You are here

function _bigmenu_overview_tree_form in Big Menu 7

Same name and namespace in other branches
  1. 6 bigmenu.admin.inc \_bigmenu_overview_tree_form()

Recursive helper function for menu_overview_form().

Copied from core, and modified to limit recursion.

See also

_menu_overview_tree_form()

2 calls to _bigmenu_overview_tree_form()
bigmenu_overview_form in ./bigmenu.admin.inc
Overview form for bigmenu.
bigmenu_slice_form in ./bigmenu.admin.inc
Form for editing the immediate children of the given menu item id.

File

./bigmenu.admin.inc, line 230
Administrative page callbacks for bigmenu module.

Code

function _bigmenu_overview_tree_form($tree, $depth = 0) {
  $form =& drupal_static(__FUNCTION__, array(
    '#tree' => TRUE,
  ));
  foreach ($tree as $data) {
    $item = $data['link'];

    // Don't show callbacks; these have $item['hidden'] < 0.
    if ($item && $item['hidden'] >= 0) {
      $mlid = 'mlid:' . $item['mlid'];
      $form[$mlid]['#item'] = $item;
      $form[$mlid]['#attributes'] = $item['hidden'] ? array(
        'class' => array(
          'menu-disabled',
        ),
      ) : array(
        'class' => array(
          'menu-enabled',
        ),
      );
      $form[$mlid]['title']['#markup'] = l($item['title'], $item['href'], $item['localized_options']) . ($item['hidden'] ? ' (' . t('disabled') . ')' : '');
      $form[$mlid]['hidden'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable @title menu link', array(
          '@title' => $item['title'],
        )),
        '#title_display' => 'invisible',
        '#default_value' => !$item['hidden'],
      );
      $form[$mlid]['weight'] = array(
        '#type' => 'weight',
        '#delta' => 50,
        '#default_value' => $item['weight'],
        '#title_display' => 'invisible',
        '#title' => t('Weight for @title', array(
          '@title' => $item['title'],
        )),
      );
      $form[$mlid]['mlid'] = array(
        '#type' => 'hidden',
        '#value' => $item['mlid'],
      );
      $form[$mlid]['plid'] = array(
        '#type' => 'hidden',
        '#default_value' => $item['plid'],
      );

      // Build a list of operations.
      $operations = array();
      $operations['edit'] = array(
        '#type' => 'link',
        '#title' => t('edit'),
        '#href' => 'admin/structure/menu/item/' . $item['mlid'] . '/edit',
      );

      // Only items created by the menu module can be deleted.
      if ($item['module'] == 'menu' || $item['updated'] == 1) {
        $operations['delete'] = array(
          '#type' => 'link',
          '#title' => t('delete'),
          '#href' => 'admin/structure/menu/item/' . $item['mlid'] . '/delete',
        );
      }
      elseif ($item['module'] == 'system' && $item['customized']) {
        $operations['reset'] = array(
          '#type' => 'link',
          '#title' => t('reset'),
          '#href' => 'admin/structure/menu/item/' . $item['mlid'] . '/reset',
        );
      }
      $form[$mlid]['operations'] = $operations;
    }
    if ($data['below']) {
      if ($depth > 0) {
        _bigmenu_overview_tree_form($data['below'], $depth - 1);
      }
      else {

        // 'below' contains both immediate children and something else.
        $strings = array(
          '!show_children' => t('Show children'),
          '%count' => count($data['below']),
          '!tooltip' => t('Click to expand and show child items'),
        );
        $text = strtr('<span class="bigmenu-toggle">+</span> <span class="count" title="!tooltip"><span class="hide-show">!show_children</span> (%count)</span>', $strings);
        $indicator = l($text, "admin/structure/menu/manage/{$item['menu_name']}/bigmenu-customize/subform/{$item['mlid']}", array(
          'html' => TRUE,
          'attributes' => array(
            'class' => array(
              'bigmenu-childindictor',
            ),
          ),
        ));
        $form[$mlid]['title']['#markup'] .= '<br/>' . $indicator;
        $form[$mlid]['#attributes']['class'][] = 'bigmenu-collapsed';
      }
    }
  }
  return $form;
}