Skip to content
Snippets Groups Projects
Commit 3371102b authored by Brian Canini's avatar Brian Canini
Browse files

Updating drupal/admin_toolbar (2.0.0 => 2.2.0)

parent 834cc9eb
No related branches found
No related tags found
No related merge requests found
Showing
with 528 additions and 132 deletions
......@@ -88,7 +88,7 @@
"drupal-composer/drupal-scaffold": "2.5.4",
"drupal/address": "1.1",
"drupal/addtocalendar": "3.1",
"drupal/admin_toolbar": "2.0",
"drupal/admin_toolbar": "2.2",
"drupal/administerusersbyrole": "2.0-beta1",
"drupal/allowed_formats": "1.2",
"drupal/anchor_link": "1.6",
......@@ -318,4 +318,4 @@
"php": "7.0.8"
}
}
}
\ No newline at end of file
}
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f3f9a51e6c09cc6554fa012dbf1ad64d",
"content-hash": "efa9a31671a248c25e142792e159ae55",
"packages": [
{
"name": "alchemy/zippy",
......@@ -2113,20 +2113,20 @@
},
{
"name": "drupal/admin_toolbar",
"version": "2.0.0",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/admin_toolbar.git",
"reference": "8.x-2.0"
"reference": "8.x-2.2"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/admin_toolbar-8.x-2.0.zip",
"reference": "8.x-2.0",
"shasum": "568de63dbaa8046a82d327dbd0b892ab79fb87aa"
"url": "https://ftp.drupal.org/files/projects/admin_toolbar-8.x-2.2.zip",
"reference": "8.x-2.2",
"shasum": "41ea0e3321e6d1e190c486be49a99e60446d8dd7"
},
"require": {
"drupal/core": "*"
"drupal/core": "^8.8.0 || ^9.0"
},
"type": "drupal-module",
"extra": {
......@@ -2134,8 +2134,8 @@
"dev-2.x": "2.x-dev"
},
"drupal": {
"version": "8.x-2.0",
"datestamp": "1573751237",
"version": "8.x-2.2",
"datestamp": "1585017179",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -6064,8 +6064,7 @@
"homepage": "https://www.drupal.org/project/migrate_devel",
"support": {
"source": "http://cgit.drupalcode.org/migrate_devel"
},
"time": "2017-06-25T23:46:13+00:00"
}
},
{
"name": "drupal/migrate_plus",
......
......@@ -2178,21 +2178,21 @@
},
{
"name": "drupal/admin_toolbar",
"version": "2.0.0",
"version_normalized": "2.0.0.0",
"version": "2.2.0",
"version_normalized": "2.2.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/admin_toolbar.git",
"reference": "8.x-2.0"
"reference": "8.x-2.2"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/admin_toolbar-8.x-2.0.zip",
"reference": "8.x-2.0",
"shasum": "568de63dbaa8046a82d327dbd0b892ab79fb87aa"
"url": "https://ftp.drupal.org/files/projects/admin_toolbar-8.x-2.2.zip",
"reference": "8.x-2.2",
"shasum": "41ea0e3321e6d1e190c486be49a99e60446d8dd7"
},
"require": {
"drupal/core": "*"
"drupal/core": "^8.8.0 || ^9.0"
},
"type": "drupal-module",
"extra": {
......@@ -2200,8 +2200,8 @@
"dev-2.x": "2.x-dev"
},
"drupal": {
"version": "8.x-2.0",
"datestamp": "1573751237",
"version": "8.x-2.2",
"datestamp": "1585017179",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......
......@@ -3,12 +3,12 @@ description: Provides an improved drop-down menu interface to the site Toolbar.
package: Administration
type: module
core: 8.x
core_version_requirement: ^8.8.0 || ^9.0
dependencies:
- drupal:toolbar
# Information added by Drupal.org packaging script on 2019-10-29
version: '8.x-2.0'
# Information added by Drupal.org packaging script on 2020-03-24
version: '8.x-2.2'
project: 'admin_toolbar'
datestamp: 1572370993
datestamp: 1585017182
......@@ -8,14 +8,3 @@ toolbar.tree:
dependencies:
- core/jquery
- core/drupal
search:
css:
theme:
css/admin.toolbar_search.css: {}
js:
js/admin_toolbar_search.js: {}
dependencies:
- core/jquery
- core/drupal
- core/jquery.once
- core/jquery.ui.autocomplete
......@@ -5,57 +5,17 @@
* This is the module to create a drop-down menu for the core toolbar.
*/
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\admin_toolbar\Render\Element\AdminToolbar;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Component\Utility\Html;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Implements hook_toolbar_alter().
*/
function admin_toolbar_toolbar_alter(&$items) {
$items['administration']['tray']['toolbar_administration']['#pre_render'] = ['admin_toolbar_prerender_toolbar_administration_tray'];
$items['administration']['tray']['toolbar_administration']['#pre_render'] = [[AdminToolbar::class, 'preRenderTray']];
$items['administration']['#attached']['library'][] = 'admin_toolbar/toolbar.tree';
$admin_toolbar_tools = \Drupal::service('module_handler')
->moduleExists('admin_toolbar_tools');
$items['administration_search'] = [
"#type" => "toolbar_item",
'tab' => [
'#type' => 'link',
'#title' => new TranslatableMarkup('Search'),
'#url' => URL::fromRoute('system.admin'),
'#attributes' => [
'class' => [
'toolbar-icon',
],
],
],
'tray' => [
'search' => [
'#title' => 'Search',
'#type' => 'textfield',
'#size' => 60,
'#attributes' => [
'id' => 'admin-toolbar-search-input',
'aria-labelledby' => 'toolbar-item-administration-search',
],
],
],
'#attached' => [
'library' => [
'admin_toolbar/search',
],
'drupalSettings' => [
'adminToolbarSearch' => [
'loadExtraLinks' => $admin_toolbar_tools,
],
],
],
'#wrapper_attributes' => [
"id" => "admin-toolbar-search-tab",
],
];
}
/**
......@@ -77,35 +37,6 @@ function admin_toolbar_help($route_name, RouteMatchInterface $route_match) {
}
}
/**
* Renders the toolbar's administration tray.
*
* This is a clone of core's toolbar_prerender_toolbar_administration_tray()
* function, which uses setMaxDepth(4) instead of setTopLevelOnly().
*
* @param array $element
* A renderable array.
*
* @return array
* The updated renderable array.
*
* @see toolbar_prerender_toolbar_administration_tray()
*/
function admin_toolbar_prerender_toolbar_administration_tray(array $element) {
$menu_tree = \Drupal::service('toolbar.menu_tree');
$parameters = new MenuTreeParameters();
$parameters->setRoot('system.admin')->excludeRoot()->setMaxDepth(4)->onlyEnabledLinks();
$tree = $menu_tree->load(NULL, $parameters);
$manipulators = [
['callable' => 'menu.default_tree_manipulators:checkAccess'],
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
['callable' => 'toolbar_tools_menu_navigation_links'],
];
$tree = $menu_tree->transform($tree, $manipulators);
$element['administration_menu'] = $menu_tree->build($tree);
return $element;
}
/**
* Adds toolbar-specific attributes to the menu link tree.
*
......
......@@ -3,12 +3,12 @@ description: Provides a workaround for the common problem that users with 'Use t
package: Administration
type: module
core: 8.x
core_version_requirement: ^8.8.0 || ^9.0
dependencies:
- admin_toolbar:admin_toolbar
# Information added by Drupal.org packaging script on 2019-10-29
version: '8.x-2.0'
# Information added by Drupal.org packaging script on 2020-03-24
version: '8.x-2.2'
project: 'admin_toolbar'
datestamp: 1572370993
datestamp: 1585017182
......@@ -26,13 +26,14 @@
"name": "Mohamed Anis Taktak (matio89)",
"homepage": "https://www.drupal.org/u/matio89",
"role": "Maintainer"
}
}
],
"support": {
"issues": "https://www.drupal.org/project/issues/admin_toolbar",
"source": "http://cgit.drupalcode.org/admin_toolbar"
},
"require": {
"drupal/admin_toolbar": "^1"
"drupal/admin_toolbar": "^2",
"drupal/core": "^8.8.0 || ^9.0"
}
}
name: Admin Toolbar Search
description: Provides search of admin toolbar items.
package: Administration
type: module
core_version_requirement: ^8.8.0 || ^9.0
dependencies:
- admin_toolbar:admin_toolbar
# Information added by Drupal.org packaging script on 2020-03-24
version: '8.x-2.2'
project: 'admin_toolbar'
datestamp: 1585017182
search:
css:
theme:
css/admin.toolbar_search.css: {}
js:
js/admin_toolbar_search.js: {}
dependencies:
- core/jquery
- core/drupal
- core/jquery.once
- core/jquery.ui.autocomplete
<?php
/**
* @file
* Functionality for search of Admin Toolbar.
*/
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function admin_toolbar_search_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help.
case 'help.page.admin_toolbar_search':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Admin Toolbar Search module add a search option to the toolbar for site administrative tasks.') . '</p>';
return $output;
}
}
/**
* Implements hook_toolbar_alter().
*/
function admin_toolbar_search_toolbar_alter(&$items) {
$access = \Drupal::currentUser()->hasPermission('use admin toolbar search');
$admin_toolbar_tools_enabled = \Drupal::service('module_handler')
->moduleExists('admin_toolbar_tools');
$items['administration_search'] = [
"#type" => "toolbar_item",
'#access' => $access,
'tab' => [
'#type' => 'link',
'#title' => new TranslatableMarkup('Search'),
'#url' => URL::fromRoute('system.admin'),
'#attributes' => [
'class' => [
'toolbar-icon',
],
],
],
'tray' => [
'search' => [
'#title' => 'Search',
'#type' => 'textfield',
'#size' => 60,
'#attributes' => [
'id' => 'admin-toolbar-search-input',
'aria-labelledby' => 'toolbar-item-administration-search',
],
],
],
'#attached' => [
'library' => [
'admin_toolbar_search/search',
],
'drupalSettings' => [
'adminToolbarSearch' => [
'loadExtraLinks' => $admin_toolbar_tools_enabled,
],
],
],
'#wrapper_attributes' => [
'id' => 'admin-toolbar-search-tab',
],
'#cache' => [
'contexts' => [
'user.permissions',
],
],
];
}
use admin toolbar search:
title: 'Use Admin Toolbar search'
admin_toolbar.search:
path: '/admin/admin-toolbar-search'
defaults:
_controller: '\Drupal\admin_toolbar_search\Controller\AdminToolbarSearchController::search'
requirements:
_permission: 'use admin toolbar search'
services:
admin_toolbar_search.search_links:
class: Drupal\admin_toolbar_search\SearchLinks
arguments:
- '@entity_type.manager'
- '@module_handler'
- '@router.route_provider'
- '@cache_contexts_manager'
- '@cache.toolbar'
{
"name": "drupal/admin_toolbar_search",
"description": "Provides search of admin toolbar items.",
"type": "drupal-module",
"keywords": ["Drupal", "Toolbar", "Search"],
"homepage": "http://drupal.org/project/admin_toolbar",
"license": "GPL-2.0+",
"authors": [
{
"name": "Wilfrid Roze (eme)",
"homepage": "https://www.drupal.org/u/eme",
"role": "Maintainer"
},
{
"name": "Romain Jarraud (romainj)",
"homepage": "https://www.drupal.org/u/romainj",
"role": "Maintainer"
},
{
"name": "Adrian Cid Almaguer (adriancid)",
"email": "adriancid@gmail.com",
"homepage": "https://www.drupal.org/u/adriancid",
"role": "Maintainer"
},
{
"name": "Mohamed Anis Taktak (matio89)",
"homepage": "https://www.drupal.org/u/matio89",
"role": "Maintainer"
}
],
"support": {
"issues": "https://www.drupal.org/project/issues/admin_toolbar",
"source": "http://cgit.drupalcode.org/admin_toolbar"
},
"require": {
"drupal/admin_toolbar": "^2",
"drupal/core": "^8.8.0 || ^9.0"
}
}
#toolbar-item-administration-search-tray {
padding-left: 1em;
}
#admin-toolbar-search-tab .toolbar-item:before {
background-image: url('../../misc/icons/bebebe/loupe.svg');
}
#admin-toolbar-search-tab .toolbar-item:active:before,
#admin-toolbar-search-tab .toolbar-item.is-active:before {
background-image: url('../../misc/icons/ffffff/loupe.svg');
}
#toolbar-item-administration-search-tray label {
display: inline-block;
color: #000000;
margin-right: .5em;
font-weight: bold;
}
#toolbar-item-administration-search-tray div.form-item {
margin: 0.75em 0;
}
#toolbar-item-administration-search-tray input {
display: inline-block;
padding: 0.3em 0.4em 0.3em 0.5em;
font-size: 1em;
}
.ui-autocomplete .ui-menu-item span.admin-toolbar-search-url {
color: rgba(0, 0, 0, 0.50);
}
/**
* @file
* Behaviors for the search widget in the admin toolbar.
*/
(function ($, Drupal) {
'use strict';
Drupal.behaviors.adminToolbarSearch = {
// If extra links have been fetched.
extraFetched: false,
attach: function (context) {
if (context != document) {
return;
}
var getUrl = window.location;
var baseUrl = getUrl.protocol + "//" + getUrl.host + "/";
var $self = this;
this.links = [];
$('.toolbar-tray a[data-drupal-link-system-path]').each(function () {
if (this.href != baseUrl) {
var label = $self.getItemLabel(this);
$self.links.push({
'value': $(this).attr('href'),
'label': label + ' ' + $(this).attr('href'),
'labelRaw': label
});
}
});
$("#admin-toolbar-search-input").autocomplete({
minLength: 2,
source: function (request, response) {
var data = $self.handleAutocomplete(request.term);
if (!$self.extraFetched && drupalSettings.adminToolbarSearch.loadExtraLinks) {
$.getJSON( "/admin/admin-toolbar-search", function( data ) {
$(data).each(function() {
var item = this;
item.label = this.labelRaw + ' ' + this.value;
$self.links.push(item);
});
$self.extraFetched = true;
var results = $self.handleAutocomplete(request.term);
response(results);
});
}
else {
response(data);
}
},
open: function () {
var zIndex = $('#toolbar-item-administration-search-tray')
.css("z-index") + 1;
$(this).autocomplete('widget').css('z-index', zIndex);
return false;
},
select: function (event, ui) {
if (ui.item.value) {
location.href = ui.item.value;
return false;
}
}
}).data("ui-autocomplete")._renderItem = (function (ul, item) {
return $("<li>")
.append('<div>' + item.labelRaw + ' <span class="admin-toolbar-search-url">' + item.value + '</span></div>')
.appendTo(ul);
});
// Focus on search field when tab is clicked, or enter is pressed.
$(context).find('#toolbar-item-administration-search')
.once('admin_toolbar_search')
.each(function () {
if (Drupal.behaviors.adminToolbarSearch.isSearchVisible()) {
$('#admin-toolbar-search-input').focus();
}
$(this).on('click', function () {
$self.focusOnSearchElement();
});
});
// Initialize hotkey / keyboard shortcut.
this.initHotkey();
},
focusOnSearchElement: function () {
var waitforVisible = function () {
if ($('#toolbar-item-administration-search-tray:visible').length) {
$('#admin-toolbar-search-input').focus();
}
else {
setTimeout(function () {
waitforVisible();
}, 1);
}
};
waitforVisible();
},
getItemLabel: function (item) {
var breadcrumbs = [];
$(item).parents().each(function () {
if ($(this).hasClass('menu-item')) {
var $link = $(this).find('a:first');
if ($link.length && !$link.hasClass('admin-toolbar-search-ignore')) {
breadcrumbs.unshift($link.text());
}
}
});
return breadcrumbs.join(' > ');
},
handleAutocomplete: function (term) {
var $self = this;
var keywords = term.split(" "); // Split search terms into list.
var suggestions = [];
$self.links.forEach(function (element) {
var label = element.label.toLowerCase();
// Add exact matches.
if (label.indexOf(term.toLowerCase()) >= 0) {
suggestions.push(element);
}
else {
// Add suggestions where it matches all search terms.
var matchCount = 0;
keywords.forEach(function (keyword) {
if (label.indexOf(keyword.toLowerCase()) >= 0) {
matchCount++;
}
});
if (matchCount == keywords.length) {
suggestions.push(element);
}
}
});
return suggestions;
},
/**
* Whether the search is visible or not.
*
* @returns {boolean}
* True if visible, false otherwise.
*/
isSearchVisible: function () {
return $('#toolbar-item-administration-search-tray').is(':visible');
},
/**
* Toggles the toolbar search tray.
*/
toggleSearch: function () {
$('#toolbar-item-administration-search').trigger('click');
},
/**
* Binds a keyboard shortcut to toggle the search.
*/
initHotkey: function () {
$(document)
.once('admin_toolbar_search')
.keydown(function (event) {
// Show the form with alt + S.
if (!Drupal.behaviors.adminToolbarSearch.isSearchVisible()) {
// 83 = s.
if (event.altKey === true && event.keyCode === 83) {
Drupal.behaviors.adminToolbarSearch.toggleSearch();
event.preventDefault();
}
}
// Hide the search with alt + S or ESC.
else {
// 83 = s.
if (
(event.altKey === true && event.keyCode === 83) ||
event.key === 'Escape'
) {
Drupal.behaviors.adminToolbarSearch.toggleSearch();
event.preventDefault();
}
}
});
}
};
})(jQuery, Drupal);
<?php
namespace Drupal\admin_toolbar_search\Controller;
use Drupal\admin_toolbar_search\SearchLinks;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Class AdminToolbarSearchController.
*
* @package Drupal\admin_toolbar_tools\Controller
*/
class AdminToolbarSearchController extends ControllerBase {
/**
* The search links service.
*
* @var \Drupal\admin_toolbar_search\SearchLinks
*/
protected $links;
/**
* Constructs an AdminToolbarSearchController object.
*
* @param \Drupal\admin_toolbar_search\SearchLinks $links
* The search links service.
*/
public function __construct(SearchLinks $links) {
$this->links = $links;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('admin_toolbar_search.search_links')
);
}
/**
* Return additional search links.
*/
public function search() {
return new JsonResponse($this->links->getLinks());
}
}
<?php
namespace Drupal\admin_toolbar_tools;
namespace Drupal\admin_toolbar_search;
use Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks;
use Drupal\Core\Cache\Cache;
......@@ -57,7 +57,18 @@ class SearchLinks {
protected $toolbarCache;
/**
* {@inheritdoc}
* Constructs a SearchLinks object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* The route provider.
* @param \Drupal\Core\Cache\Context\CacheContextsManager $cache_context_manager
* The cache contexts manager.
* @param \Drupal\Core\Cache\CacheBackendInterface $toolbar_cache
* Cache backend instance to use.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, RouteProviderInterface $route_provider, CacheContextsManager $cache_context_manager, CacheBackendInterface $toolbar_cache) {
$this->entityTypeManager = $entity_type_manager;
......@@ -68,10 +79,10 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Mod
}
/**
* Get extra links for admin toolbar search feature.
* Gets extra links for admin toolbar search feature.
*
* @return array
* An array of link data.
* An array of link data for the JSON used for search.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
......@@ -239,7 +250,7 @@ public function getLinks() {
}
/**
* Get a list of content entities.
* Gets a list of content entities.
*
* @return array
* An array of metadata about content entities.
......@@ -258,19 +269,6 @@ protected function getBundleableEntitiesList() {
return $content_entities;
}
/**
* Get an array of entity types that should trigger a menu rebuild.
*
* @return array
* An array of entity machine names.
*/
public function getRebuildEntityTypes() {
$types = ['menu'];
$content_entities = $this->getBundleableEntitiesList();
$types = array_merge($types, array_column($content_entities, 'content_entity_bundle'));
return $types;
}
/**
* Determine if a route exists by name.
*
......
<?php
namespace Drupal\Tests\admin_toolbar_search\FunctionalJavascript;
/**
* Test the functionality of admin toolbar search.
*
* @group admin_toolbar
* @group admin_toolbar_search
*/
class AdminToolbarSearchTest extends AdminToolbarSearchTestBase {
/**
* Tests search functionality without admin_toolbar_tools enabled.
*/
public function testToolbarSearch() {
$search_tab = '#toolbar-item-administration-search';
$search_tray = '#toolbar-item-administration-search-tray';
$this->drupalLogin($this->userWithAccess);
$assert_session = $this->assertSession();
$assert_session->responseContains('admin.toolbar_search.css');
$assert_session->responseContains('admin_toolbar_search.js');
$assert_session->waitForElementVisible('css', $search_tab)->click();
$assert_session->waitForElementVisible('css', $search_tray);
$this->assertSuggestionContains('perfor', 'admin/config/development/performance');
$this->assertSuggestionContains('develop', 'admin/config/development/maintenance');
$this->assertSuggestionContains('types', 'admin/structure/types');
}
/**
* Tests a user without the search permission can't use search.
*/
public function testNoAccess() {
$search_tab = '#toolbar-item-administration-search';
$search_tray = '#toolbar-item-administration-search-tray';
$this->drupalLogin($this->noAccessUser);
$assert_session = $this->assertSession();
$assert_session->responseNotContains('admin.toolbar_search.css');
$assert_session->responseNotContains('admin_toolbar_search.js');
$assert_session->elementNotExists('css', $search_tab);
$assert_session->elementNotExists('css', $search_tray);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment