You are here

function theme_menu_overview_form in Drupal 6

Same name and namespace in other branches
  1. 7 modules/menu/menu.admin.inc \theme_menu_overview_form()

Theme the menu overview form into a table.

Related topics

File

modules/menu/menu.admin.inc, line 170
Administrative page callbacks for menu module.

Code

function theme_menu_overview_form($form) {
  drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1);
  drupal_add_tabledrag('menu-overview', 'order', 'sibling', 'menu-weight');
  $header = array(
    t('Menu item'),
    array(
      'data' => t('Enabled'),
      'class' => 'checkbox',
    ),
    array(
      'data' => t('Expanded'),
      'class' => 'checkbox',
    ),
    t('Weight'),
    array(
      'data' => t('Operations'),
      'colspan' => '3',
    ),
  );
  $rows = array();
  foreach (element_children($form) as $mlid) {
    if (isset($form[$mlid]['hidden'])) {
      $element =& $form[$mlid];

      // Build a list of operations.
      $operations = array();
      foreach (element_children($element['operations']) as $op) {
        $operations[] = drupal_render($element['operations'][$op]);
      }
      while (count($operations) < 2) {
        $operations[] = '';
      }

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

      // Change the parent field to a hidden. This allows any value but hides the field.
      $element['plid']['#type'] = 'hidden';
      $row = array();
      $row[] = theme('indentation', $element['#item']['depth'] - 1) . drupal_render($element['title']);
      $row[] = array(
        'data' => drupal_render($element['hidden']),
        'class' => 'checkbox',
      );
      $row[] = array(
        'data' => drupal_render($element['expanded']),
        'class' => 'checkbox',
      );
      $row[] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']);
      $row = array_merge($row, $operations);
      $row = array_merge(array(
        'data' => $row,
      ), $element['#attributes']);
      $row['class'] = !empty($row['class']) ? $row['class'] . ' draggable' : 'draggable';
      $rows[] = $row;
    }
  }
  $output = '';
  if ($rows) {
    $output .= theme('table', $header, $rows, array(
      'id' => 'menu-overview',
    ));
  }
  $output .= drupal_render($form);
  return $output;
}