You are here

function popup_toolbar in Popup 8

Implements hook_toolbar().

File

./popup.module, line 19
Module file for Popup module.

Code

function popup_toolbar() {

  // First, build an array of all popup modules and their routes.
  // We resort to this hard-coded way so as not to muck up each popup module.
  $popup_modules = _popup_toolbar_routes();

  // Build a list of links for the menu.
  $links = [];
  foreach ($popup_modules as $module => $route) {

    // Get the module info (title, description) from Drupal.
    $info = system_get_info('module', $module);

    // If there's no info, the popup isn't enabled, so don't display it.
    if (!empty($info)) {
      $links[$module] = [
        'title' => Html::escape($info['name']),
        'url' => Url::fromRoute($route),
        'attributes' => [
          'title' => Html::escape($info['description']),
        ],
      ];
    }
  }

  // Add a link to enable all popup modules.
  $links['enable_popup'] = [
    'title' => t('Enable Popup Modules'),
    'url' => Url::fromRoute('system.modules_list'),
    'options' => [
      'title' => t('Enable more Popup modules in on the Extend page.'),
    ],
    'fragment' => 'edit-modules-popup-modules',
  ];

  // Create the Popup toolbar render array.
  $items['popup_modules'] = [
    '#type' => 'toolbar_item',
    'tab' => [
      '#type' => 'link',
      '#title' => t('Popup'),
      '#url' => Url::fromRoute('<front>'),
      '#attributes' => [
        'title' => t('Popup Modules'),
        'class' => [
          'toolbar-icon',
          'toolbar-icon-popup',
        ],
      ],
    ],
    'tray' => [
      '#heading' => t('Popup Modules'),
      'shortcuts' => [
        '#theme' => 'links__toolbar_popup',
        '#links' => $links,
        '#attributes' => [
          'class' => [
            'toolbar-menu',
          ],
        ],
      ],
    ],
    '#weight' => 99,
    '#attached' => [
      'library' => [
        'popup/assets/images',
      ],
    ],
  ];
  return $items;
}