admin_toolbar-8.x-2.x-dev/admin_toolbar_tools/admin_toolbar_tools.module

admin_toolbar_tools/admin_toolbar_tools.module
<?php

/**
 * @file
 * Provides extra menu links for the core drupal toolbar.
 */

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;

/**
 * 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']],
  ];

  // Toolbar item for primary local tasks.
  $items['admin_toolbar_local_tasks'] = \Drupal::service('admin_toolbar_tools.helper')->buildLocalTasksToolbar();

  return $items;
}

/**
 * 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) {
  // Skip rebuild during config sync because rebuild should
  // always be a post-sync step.
  if (!\Drupal::isConfigSyncing()) {
    $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) {
  // Skip rebuild during config sync because rebuild should
  // always be a post-sync step.
  if (!\Drupal::isConfigSyncing()) {
    $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) {
  // Skip rebuild during config sync because rebuild should
  // always be a post-sync step.
  if (!\Drupal::isConfigSyncing()) {
    $entities = \Drupal::service('admin_toolbar_tools.helper')->getRebuildEntityTypes();
    if (in_array($entity->getEntityTypeId(), $entities)) {
      \Drupal::service('plugin.manager.menu.link')->rebuild();
    }
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function admin_toolbar_tools_form_project_browser_settings_alter(&$form) {
  // Project browser settings form: Add a submit handler to rebuild menu items.
  $form['#submit'][] = 'admin_toolbar_tools_project_browser_settings_submit';
}

/**
 * Project browser integration: Helper function callback to rebuild menu items.
 */
function admin_toolbar_tools_project_browser_settings_submit(&$form) {
  \Drupal::service('plugin.manager.menu.link')->rebuild();
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc