You are here

admin_toolbar_tools.module in Admin Toolbar 8.2

Provides extra menu links for the core drupal toolbar.

File

admin_toolbar_tools/admin_toolbar_tools.module
View source
<?php

/**
 * @file
 * Provides extra menu links for the core drupal toolbar.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;

/**
 * Implements hook_toolbar().
 */
function admin_toolbar_tools_toolbar() {
  $items = [];
  $items['admin_toolbar_tools'] = [
    '#type' => 'toolbar_item',
    'tab' => [
      '#type' => 'link',
      '#attributes' => [
        'class' => [
          'toolbar-icon',
          'toolbar-icon-admin-toolbar-tools-help',
        ],
      ],
    ],
    '#attached' => [
      'library' => [
        'admin_toolbar_tools/toolbar.icon',
      ],
    ],
  ];
  return $items;
}

/**
 * Implements hook_preprocess_html().
 */
function admin_toolbar_tools_preprocess_html(&$variables) {
  if (\Drupal::currentUser()
    ->hasPermission('access toolbar')) {
    $variables['attributes']['class'][] = 'toolbar-icon-' . intval(\Drupal::VERSION);
  }
}

/**
 * Implements hook_help().
 */
function admin_toolbar_tools_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.admin_toolbar_tools':
      $output = '';
      $output .= '<p>';
      $output .= t('The Admin Toolbar Extra Tools module comes packaged with the <a href=":admin-toolbar">Admin Toolbar</a> module and adds functionality to it. The additional functionality is accessed through extra links on the main administration Toolbar. Some links to Admin Toolbar Extra Tools administration pages are located at the bottom of this page.</a>', [
        ':admin-toolbar' => Url::fromRoute('help.page', [
          'name' => 'admin_toolbar',
        ])
          ->toString(),
      ]);
      $output .= '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<p>' . t('To use Admin Toolbar Extra Tools just install it like any other module. There is no other configuration required.') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_entity_insert().
 */
function admin_toolbar_tools_entity_insert(EntityInterface $entity) {
  $entities = \Drupal::service('admin_toolbar_tools.helper')
    ->getRebuildEntityTypes();
  if (in_array($entity
    ->getEntityTypeId(), $entities)) {
    \Drupal::service('plugin.manager.menu.link')
      ->rebuild();
  }
}

/**
 * Implements hook_entity_update().
 */
function admin_toolbar_tools_entity_update(EntityInterface $entity) {
  $entities = \Drupal::service('admin_toolbar_tools.helper')
    ->getRebuildEntityTypes();
  if (in_array($entity
    ->getEntityTypeId(), $entities)) {
    \Drupal::service('plugin.manager.menu.link')
      ->rebuild();
  }
}

/**
 * Implements hook_entity_delete().
 */
function admin_toolbar_tools_entity_delete(EntityInterface $entity) {
  $entities = \Drupal::service('admin_toolbar_tools.helper')
    ->getRebuildEntityTypes();
  if (in_array($entity
    ->getEntityTypeId(), $entities)) {
    \Drupal::service('plugin.manager.menu.link')
      ->rebuild();
  }
}