You are here

function theme_menu_overview_form_extended in Content Menu 8

Same name and namespace in other branches
  1. 7 content_menu.menu_admin.inc \theme_menu_overview_form_extended()

Returns HTML for the menu overview form into a table.

Code taken mainly from original theme_menu_overview_form().

Parameters

$variables: An associative array containing:

  • form: A render element representing the form.

File

./content_menu.menu_admin.inc, line 381

Code

function theme_menu_overview_form_extended($variables) {
  $form = $variables['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');

  // Count max number of operations per item.
  $operations_count_max = 1;
  foreach (element_children($form) as $mlid) {
    if (isset($form[$mlid]['#operations_count'])) {
      $operations_count_max = max($operations_count_max, $form[$mlid]['#operations_count']);
    }
  }
  $header = array(
    t('Menu link'),
    array(
      'data' => t('Enabled'),
      'class' => array(
        'checkbox',
      ),
    ),
    t('Weight'),
    t('Target'),
    array(
      'data' => t('Operations'),
      'colspan' => $operations_count_max,
    ),
  );

  // Build item tables.
  $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[] = array(
          'data' => drupal_render($element['operations'][$op]),
          'class' => array(
            'menu-operations',
          ),
        );
      }
      while (count($operations) < $operations_count_max) {
        $operations[] = '';
      }

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

      // Change the parent field to a hidden. This allows any value but hides the field.
      $element['plid']['#type'] = 'hidden';
      $depth = isset($element['#item']) ? $element['#item']['depth'] : 1;
      $row = array();
      $row[] = theme('indentation', array(
        'size' => $depth - 1,
      )) . drupal_render($element['title']);
      $row[] = array(
        'data' => drupal_render($element['hidden']),
        'class' => array(
          'checkbox',
          'menu-enabled',
        ),
      );
      $row[] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']);
      $row[] = array(
        'data' => drupal_render($element['target_content']),
        'class' => array(
          'menu-target-content',
        ),
      );
      $row = array_merge($row, $operations);
      $row = array_merge(array(
        'data' => $row,
      ), $element['#attributes']);
      $row['class'][] = 'draggable';

      // Highlight row if menu item has been created within the last minute.
      if (isset($element['#item']['mlid']) && isset($_SESSION['content_menu_inserted_links'][$element['#item']['mlid']])) {
        if (time() - $_SESSION['content_menu_inserted_links'][$element['#item']['mlid']]['created'] <= 60) {
          $row['class'][] = 'ok';
        }
        unset($_SESSION['content_menu_inserted_links'][$element['#item']['mlid']]);
      }
      $rows[] = $row;
    }
  }
  $output = '';
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => $form['#empty_text'],
        'colspan' => '7',
      ),
    );
  }

  // render selection filter widgets on top
  if (isset($form['#content_menu_filter_widget'])) {
    foreach ($form['#content_menu_filter_widget'] as $widgetname) {
      $output .= drupal_render($form[$widgetname]);
    }
  }
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'menu-overview',
    ),
  ));
  $output .= drupal_render_children($form);
  return $output;
}