Created on 6 August 2020, almost 4 years ago
Updated 5 April 2024, 3 months ago

Problem/Motivation

Need to refactor deprecated and very legacy code.

/**
 * Implements hook_theme().
 */
function front_page_theme() {
  return [
    'front_page_admin_arrange_form' => [
      'render element' => 'form',
      'function' => 'theme_front_page_admin_arrange_form',
    ],
  ];
}

function theme_front_page_admin_arrange_form($variables) {
  $form = $variables['form'];

  // Enable the drag handles.
  drupal_attach_tabledrag($form['roles'], [
    'table_id' => 'front-page-arrange',
    'action' => 'order',
    'relationship' => 'sibling',
    'group' => 'front-page-weight',
  ]);

  $header = [
    t('Role'),
    t('Mode'),
    t('Preview'),
    t('Enabled'),
    t('Weight'),
  ];

  $rows = [];
  $renderer = \Drupal::service('renderer');
  foreach (Element::children($form['roles']) as $rid) {
    $element = &$form['roles'][$rid];

    // Add special classes to be used for tabledrag.js.
    $element['weight']['#attributes']['class'] = ['front-page-weight'];

    $row = [];
    $row[] = $renderer->render($element['title'], FALSE);
    $row[] = $renderer->render($element['mode'], FALSE);
    $row[] = $renderer->render($element['preview'], FALSE);
    $row[] = $renderer->render($element['enabled'], FALSE);
    $row[] = $renderer->render($element['weight'], FALSE);

    $row = array_merge(['data' => $row], $element['#attributes']);
    $row['class'][] = 'draggable';
    $rows[] = $row;
  }
  $output = '';
  if (empty($rows)) {
    $rows[] = [['data' => 'no roles', 'colspan' => '5']];
  }

  $front_page_arrange = [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    'attributes' => ['id' => 'front-page-arrange'],
  ];
  $output .= $renderer->render($front_page_arrange);
  foreach (Element::children($form) as $key) {
    if (!empty($form[$key])) {
      $output .= \Drupal::service('renderer')->render($form[$key]);
    }
  }
  return $output;
}

Just a little bit more context.
There was a form with ID front_page_admin_arrange_form, but it was removed in this commit. That's why the theme_front_page_admin_arrange_form function is not needed any more.

🌱 Plan
Status

Closed: outdated

Version

10.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine Oleksandr Senenko

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024