menu_overview_tree_rows

Versions
4.6 – 5
menu_overview_tree_rows($pid = 0, $depth = 0)

Code

modules/menu.module, line 399

<?php
function menu_overview_tree_rows($pid = 0, $depth = 0) {
  $menu = menu_get_menu();

  $rows = array();

  if (isset($menu['items'][$pid]) && $menu['items'][$pid]['children']) {

    usort($menu['items'][$pid]['children'], '_menu_sort');
    foreach ($menu['items'][$pid]['children'] as $mid) {
      // Populate the title field.
      $title = '';
      if ($pid == 0) {
        // Top-level items are menu names, and don't have an associated path.
        $title .= $menu['items'][$mid]['title'];
      }
      else {
        $title .= l($menu['items'][$mid]['title'], $menu['items'][$mid]['path']);
      }
      if ($depth > 0) {
        $title = '-&nbsp;'. $title;
      }
      for ($i = 1; $i < $depth; $i++) {
        $title = '&nbsp;&nbsp;'. $title;
      }

      // Populate the operations field.
      $operations = array();
      if (!($menu['items'][$mid]['type'] & MENU_MODIFIABLE_BY_ADMIN)) {
        $operations[] = array('data' => t('locked'), 'colspan' => '3', 'align' => 'center');
      }
      else {
        if ($menu['items'][$mid]['type'] & MENU_VISIBLE_IN_TREE) {
          $operations[] = array('data' => l(t('edit'), 'admin/menu/item/edit/'. $mid));
          if ($menu['items'][$mid]['type'] & MENU_IS_ROOT) {
            // Disabling entire menus is done from block admin page.
            $operations[] = array('data' => '');
          }
          else {
            $operations[] = array('data' => l(t('disable'), 'admin/menu/item/disable/'. $mid));
          }
        }
        else {
          $operations[] = array('data' => '');
          $operations[] = array('data' => l(t('enable'), 'admin/menu/item/edit/'. $mid));
        }

        if ($menu['items'][$mid]['type'] & MENU_CREATED_BY_ADMIN) {
          $operations[] = array('data' => l(t('delete'), 'admin/menu/item/delete/'. $mid));
        }
        else if ($menu['items'][$mid]['type'] & MENU_MODIFIED_BY_ADMIN) {
          $operations[] = array('data' => l(t('reset'), 'admin/menu/item/reset/'. $mid));
        }
        else {
          $operations[] = array('data' => '');
        }
      }

      // Call out disabled items.
      if ($menu['items'][$mid]['type'] & MENU_VISIBLE_IN_TREE) {
        $class = 'menu-enabled';
      }
      else {
        $title .= ' ('. t('disabled') .')';
        $class = 'menu-disabled';
      }

      if ($menu['items'][$mid]['type'] & (MENU_MODIFIABLE_BY_ADMIN | MENU_VISIBLE_IN_TREE)) {
        $row = array(array('data' => $title, 'class' => $class), array('data' => ($menu['items'][$mid]['children'] ? (($menu['items'][$mid]['type'] & MENU_EXPANDED) ? t('Yes') : t('No')) : ''), 'class' => $class));
        foreach ($operations as $operation) {
          $operation['class'] = $class;
          $row[] = $operation;
        }
        $rows[] = $row;
        $rows = array_merge($rows, menu_overview_tree_rows($mid, $depth + 1));
      }
      else {
        // Skip items that are hidden and locked; admins will never care about them.
        $rows = array_merge($rows, menu_overview_tree_rows($mid, $depth));
      }
    }

  }

  return $rows;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.