1 block.menus.inc DashboardMenuBlock::getContent()

Return the content of a block.

Return value

mixed:

Overrides Block::getContent

File

core/modules/dashboard/includes/block.menus.inc, line 53
Dashboard block displaying menus on the site.

Class

DashboardMenuBlock
@file Dashboard block displaying menus on the site.

Code

function getContent() {
  if (!module_exists('menu')) {
    return;
  }

  $menus = menu_get_menus();
  $current_path = current_path();
  $options = array('destination' => $current_path);
  $header = array(
    array('data' => t('Menu')),
    array('data' => t('Operations')),
  );
  $rows = array();

  if (user_access('administer menu')) {
    foreach ($menus as $machine => $menu_label) {
      if (in_array($machine, $this->settings['menus'])) {
        $links['manage'] = array(
          'title' => t('Edit links'),
          'href' => 'admin/structure/menu/manage/' . $machine,
          'query' => $options,
        );
        $links['add'] = array(
          'title' => t('Add new link'),
          'href' => 'admin/structure/menu/manage/' . $machine . '/add',
          'query' => $options,
        );
        $links['configure'] = array(
          'title' => t('Configure'),
          'href' => 'admin/structure/menu/manage/' . $machine . '/edit',
          'query' => $options,
        );
        $operations = array(
          '#type' => 'dropbutton',
          '#links' => $links,
        );
        $rows[] = array(
          'data' => array(
            check_plain(t($menu_label)),
            backdrop_render($operations),
          ),
        );
      }
    }
  }

  if (empty($rows)) {
    // If there are existing menuse, but user has no access to manage any
    // of them, hide the block completely.
    if (!empty($menus)) {
      return array();
    }
    $rows[] = array(
      array(
        'data' => t('There are no menus to display.'),
        'colspan' => 4,
      ),
    );
  }

  $panel = array(
    '#theme' => 'dashboard_panel__menus',
  );
  $panel['table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
  );

  if (user_access('administer menu')) {
    $panel['link'] = array(
      '#theme' => 'link',
      '#path' => 'admin/structure/menu',
      '#text' => t('Manage menus'),
    );
  }

  return $panel;
}