toolbar_toolbar

toolbar_toolbar()

Implements hook_toolbar().

File

core/modules/toolbar/toolbar.module, line 137
Administration toolbar for quick access to top level administration items.

Code

function toolbar_toolbar() {
  // The 'Home' tab is a simple link, with no corresponding tray.
  $items['home'] = array(
    '#type' => 'toolbar_item',
    'tab' => array(
      '#type' => 'link',
      '#title' => t('Back to site'),
      '#url' => Url::fromRoute('<front>'),
      '#attributes' => array(
        'title' => t('Return to site content'),
        'class' => array('toolbar-icon', 'toolbar-icon-escape-admin'),
        'data-toolbar-escape-admin' => TRUE,
      ),
    ),
    '#wrapper_attributes' => array(
      'class' => array('hidden', 'home-toolbar-tab'),
    ),
    '#attached' => array(
      'library' => array(
        'toolbar/toolbar.escapeAdmin',
      ),
    ),
    '#weight' => -20,
  );

  // To conserve bandwidth, we only include the top-level links in the HTML.
  // The subtrees are fetched through a JSONP script that is generated at the
  // toolbar_subtrees route. We provide the JavaScript requesting that JSONP
  // script here with the hash parameter that is needed for that route.
  // @see toolbar_subtrees_jsonp()
  list($hash, $hash_cacheability) = _toolbar_get_subtrees_hash();
  $subtrees_attached['drupalSettings']['toolbar'] = [
    'subtreesHash' => $hash,
  ];

  // The administration element has a link that is themed to correspond to
  // a toolbar tray. The tray contains the full administrative menu of the site.
  $items['administration'] = array(
    '#type' => 'toolbar_item',
    'tab' => array(
      '#type' => 'link',
      '#title' => t('Manage'),
      '#url' => Url::fromRoute('system.admin'),
      '#attributes' => array(
        'title' => t('Admin menu'),
        'class' => array('toolbar-icon', 'toolbar-icon-menu'),
        // A data attribute that indicates to the client to defer loading of
        // the admin menu subtrees until this tab is activated. Admin menu
        // subtrees will not render to the DOM if this attribute is removed.
        // The value of the attribute is intentionally left blank. Only the
        // presence of the attribute is necessary.
        'data-drupal-subtrees' => '',
      ),
    ),
    'tray' => array(
      '#heading' => t('Administration menu'),
      '#attached' => $subtrees_attached,
      'toolbar_administration' => array(
        '#pre_render' => array(
          'toolbar_prerender_toolbar_administration_tray',
        ),
        '#type' => 'container',
        '#attributes' => array(
          'class' => array('toolbar-menu-administration'),
        ),
      ),
    ),
    '#weight' => -15,
  );
  $hash_cacheability->applyTo($items['administration']);

  return $items;
}
doc_Drupal
2016-10-29 09:48:42
Comments
Leave a Comment

Please login to continue.