first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
* For a full list of fixes in the latest release, visit:
https://www.drupal.org/project/admin_toolbar/releases

View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@@ -0,0 +1,66 @@
# Admin Toolbar
Admin Toolbar intends to improve the default Drupal Toolbar to transform it into
a drop-down menu, providing a fast and full access to all administration links.
For a full description of the module, visit the
[project page](https://www.drupal.org/project/admin_toolbar).
Submit bug reports and feature suggestions, or track changes in the
[issue queue](https://www.drupal.org/project/issues/search/admin_toolbar).
## Table of contents
- Requirements
- Recommended modules
- Installation
- Configuration
- Maintainers
## Requirements
This module requires the following modules:
- [Toolbar](https://www.drupal.org/project/toolbar)
- [Breakpoint](https://www.drupal.org/project/breakpoint)
## Recommended modules
[Admin Toolbar Extra Tools](https://www.drupal.org/project/admin_toolbar):
Provides menu links to administration pages or actions (eg. Flushing caches)
that are not generated by Drupal core.
[Admin Toolbar Links Access Filter](https://www.drupal.org/node/2474539):
Provides a workaround for the common problem that users with
'Use the administration pages and help' permission see menu links they don't
have access permission for.
## Installation
Install as you would normally install a contributed Drupal module. For further
information, see
[Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).
## Configuration
Configure the admin toolbar tools at (/admin/config/user-interface/admin-toolbar).
## Maintainers
Current maintainers:
- [Romain Jarraud (romainj)](https://www.drupal.org/u/romainj)
- [Adrian Cid Almaguer (adriancid)](https://www.drupal.org/u/adriancid)
- [Wilfrid Roze (eme)](https://www.drupal.org/u/eme)
- [bilel khalil (bolbol)](https://www.drupal.org/u/bolbol)
- [fethi.krout (fethi.krout)](https://www.drupal.org/u/fethi.krout)
- [Mohamed Anis Taktak (matio89)](https://www.drupal.org/u/matio89)
- [Thomas MUSA (Musa.thomas)](https://www.drupal.org/u/musathomas)
Supporting organizations:
- [emerya](https://www.drupal.org/emerya) Created this module for you!
- [Trained People](https://www.drupal.org/trained-people) Sponsored the module development
- [Drupiter](https://www.drupal.org/drupiter) Sponsored the module development
- [Dropteam](https://www.drupal.org/dropteam) Sponsored the module development
- [Alliance of Digital Builders (AODB)](https://www.drupal.org/alliance-of-digital-builders-aodb) Sponsored the module development

View File

@@ -0,0 +1,13 @@
name: Admin Toolbar
description: Provides an improved drop-down menu interface to the site Toolbar.
package: Administration
type: module
configure: admin_toolbar.settings
core_version_requirement: ^9.2 || ^10
dependencies:
- drupal:toolbar
# Information added by Drupal.org packaging script on 2023-09-29
version: '3.4.2'
project: 'admin_toolbar'
datestamp: 1696006156

View File

@@ -0,0 +1,30 @@
<?php
/**
* @file
* Install, update and uninstall functions for the Admin Toolbar module.
*/
/**
* Rebuild routes to mitigate issue 2938884.
*
* @see https://www.drupal.org/project/admin_toolbar/issues/2938884
*/
function admin_toolbar_update_8001() {
// Rebuilding the route cache.
\Drupal::service("router.builder")->rebuild();
}
/**
* Add menu_depth param into the config.
*
* @see https://www.drupal.org/project/admin_toolbar/issues/3200542
*/
function admin_toolbar_update_8002() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('admin_toolbar.settings');
if (empty($config->get('menu_depth'))) {
$config->set('menu_depth', 4);
$config->save(TRUE);
}
}

View File

@@ -0,0 +1,21 @@
toolbar.tree:
css:
theme:
css/admin.toolbar.css: {}
js:
js/admin_toolbar.js: {}
dependencies:
- core/jquery
- core/drupal
toolbar.tree.hoverintent:
js:
js/jquery.hoverIntent.js: {}
js/admin_toolbar.hoverintent.js: {}
dependencies:
- core/jquery
toolbar.tree.hover:
js:
js/admin_toolbar.hover.js: {}
dependencies:
- core/jquery

View File

@@ -0,0 +1,5 @@
admin_toolbar.settings:
title: 'Admin Toolbar'
description: 'Configure the Admin Toolbar module.'
route_name: admin_toolbar.settings
parent: system.admin_config_ui

View File

@@ -0,0 +1,74 @@
<?php
/**
* @file
* This is the module to create a drop-down menu for the core toolbar.
*/
use Drupal\admin_toolbar\Render\Element\AdminToolbar;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Component\Utility\Html;
/**
* Implements hook_toolbar_alter().
*/
function admin_toolbar_toolbar_alter(&$items) {
$items['administration']['tray']['toolbar_administration']['#pre_render'] = [
[AdminToolbar::class, 'preRenderTray'],
];
$items['administration']['#attached']['library'][] = 'admin_toolbar/toolbar.tree';
$hoverintent_functionality = \Drupal::config('admin_toolbar_tools.settings')->get('hoverintent_functionality');
if ($hoverintent_functionality === TRUE) {
// Use jQuery hover() effect.
$items['administration']['#attached']['library'][] = 'admin_toolbar/toolbar.tree.hoverintent';
}
else {
// User hoverIntent plugin.
$items['administration']['#attached']['library'][] = 'admin_toolbar/toolbar.tree.hover';
}
}
/**
* Implements hook_help().
*/
function admin_toolbar_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.admin_toolbar':
$variables = [
':toolbar' => Url::fromRoute('help.page', ['name' => 'toolbar'])->toString(),
':automated_cron' => (\Drupal::moduleHandler()->moduleExists('automated_cron')) ? Url::fromRoute('help.page', ['name' => 'automated_cron'])->toString() : '#',
];
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Admin Toolbar module enhances the <a href=":toolbar">Toolbar</a> module by providing fast access to all the administrative links at the top of your site. Admin Toolbar remains a very "lightweight" module by closely integrating with all Toolbar functionality. It can be used in conjunction with all the sub modules included on Admin Toolbar, for quick access to system commands such as Flush all caches, <a href=":automated_cron">Run cron</a>, Run Updates, etc.', $variables) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<p>' . t('The Admin Toolbar greatly improves the user experience for those who regularly interact with the site Toolbar by providing fast, full access to all links in the site Toolbar without having to click to get there.') . '</p>';
return $output;
}
}
/**
* Adds toolbar-specific attributes to the menu link tree.
*
* @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree
* The menu link tree to manipulate.
*
* @return \Drupal\Core\Menu\MenuLinkTreeElement[]
* The manipulated menu link tree.
*/
function toolbar_tools_menu_navigation_links(array $tree) {
foreach ($tree as $element) {
if ($element->subtree) {
toolbar_tools_menu_navigation_links($element->subtree);
}
$link = $element->link;
// Get the non-localized title to make the icon class.
$definition = $link->getPluginDefinition();
$element->options['attributes']['class'][] = 'toolbar-icon';
$string = strtolower(str_replace(['.', ' ', '_'], ['-', '-', '-'], $definition['id']));
$element->options['attributes']['class'][] = Html::cleanCssIdentifier('toolbar-icon-' . $string);
$element->options['attributes']['title'] = $link->getDescription();
}
return $tree;
}

View File

@@ -0,0 +1,7 @@
admin_toolbar.settings:
path: '/admin/config/user-interface/admin-toolbar'
defaults:
_form: '\Drupal\admin_toolbar\Form\AdminToolbarSettingsForm'
_title: 'Admin Toolbar settings'
requirements:
_permission: 'administer site configuration'

View File

@@ -0,0 +1,55 @@
# Admin Toolbar Tools
The Admin Toolbar Links Access Filter module Provides a workaround for the
common problem that users with 'Use the administration pages and help'
permission see menu links they don't have access permission for. Once the issue
[296693](https://www.drupal.org/node/296693) be solved, this module will be deprecated.
For a full description of the module, visit the
[project page](https://www.drupal.org/project/admin_toolbar).
Submit bug reports and feature suggestions, or track changes in the
[issue queue](https://www.drupal.org/project/issues/search/admin_toolbar).
## Table of contents
- Requirements
- Installation
- Configuration
- Maintainers
## Requirements
This module requires the following modules:
- [Admin Toolbar](https://www.drupal.org/project/admin_toolbar)
## Installation
Install as you would normally install a contributed Drupal module. For further
information, see
[Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).
## Configuration
No configuration is needed.
## Maintainers
Current maintainers:
- [Romain Jarraud (romainj)](https://www.drupal.org/u/romainj)
- [Adrian Cid Almaguer (adriancid)](https://www.drupal.org/u/adriancid)
- [Wilfrid Roze (eme)](https://www.drupal.org/u/eme)
- [bilel khalil (bolbol)](https://www.drupal.org/u/bolbol)
- [fethi.krout (fethi.krout)](https://www.drupal.org/u/fethi.krout)
- [Mohamed Anis Taktak (matio89)](https://www.drupal.org/u/matio89)
- [Thomas MUSA (Musa.thomas)](https://www.drupal.org/u/musathomas)
Supporting organizations:
- [emerya](https://www.drupal.org/emerya) Created this module for you!
- [Trained People](https://www.drupal.org/trained-people) Sponsored the module development
- [Drupiter](https://www.drupal.org/drupiter) Sponsored the module development
- [Dropteam](https://www.drupal.org/dropteam) Sponsored the module development
- [Alliance of Digital Builders (AODB)](https://www.drupal.org/alliance-of-digital-builders-aodb) Sponsored the module development

View File

@@ -0,0 +1,12 @@
name: Admin Toolbar Links Access Filter
description: Provides a workaround for the common problem that users with 'Use the administration pages and help' permission see menu links they don't have access permission for. Once the issue <a href='https://www.drupal.org/node/296693'>https://www.drupal.org/node/296693</a> be solved, this module will be deprecated.
package: Administration
type: module
core_version_requirement: ^9.2 || ^10
dependencies:
- admin_toolbar:admin_toolbar
# Information added by Drupal.org packaging script on 2023-09-29
version: '3.4.2'
project: 'admin_toolbar'
datestamp: 1696006156

View File

@@ -0,0 +1,193 @@
<?php
/**
* @file
* This module don't show menu links that you don't have access permission for.
*/
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function admin_toolbar_links_access_filter_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help.
case 'help.page.admin_toolbar_links_access_filter':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Admin Toolbar Links Access Filter module provides a workaround for the common problem that users with <em>Use the administration pages and help</em> permission see menu links they done not have access permission for.') . '</p>';
return $output;
}
}
/**
* Implements hook_preprocess_menu().
*
* Hides links from admin menu, if user doesn't have access rights.
*/
function admin_toolbar_links_access_filter_preprocess_menu(&$variables) {
if (empty($variables['items'])) {
// Additional empty check to prevent exotic situations, where the preprocess
// function is entered even without items.
// @see https://www.drupal.org/node/2833885
return;
}
// Ensure that menu_name exists.
if (!isset($variables['menu_name'])) {
// In rare cases (for unknown reasons) menu_name may not be set.
// As fallback, we can fetch it from the first menu item.
$first_link = reset($variables['items']);
/** @var Drupal\Core\Menu\MenuLinkDefault $original_link */
// Fetch the menu_name from the original link.
$original_link = $first_link['original_link'];
$variables['menu_name'] = $original_link->getMenuName();
}
if ($variables['menu_name'] == 'admin') {
if (!admin_toolbar_links_access_filter_user_has_admin_role($variables['user'])) {
admin_toolbar_links_access_filter_filter_non_accessible_links($variables['items']);
}
}
}
/**
* Hides links from admin menu, if user doesn't have access rights.
*/
function admin_toolbar_links_access_filter_filter_non_accessible_links(array &$items) {
if (Drupal::currentUser()->id() == 1) {
// Admin can access everything.
return;
}
$access_manager = \Drupal::accessManager();
foreach ($items as $menu_id => &$item) {
try {
$route_name = NULL;
$route_params = [];
if (!empty($item['original_link'])) {
/** @var \Drupal\Core\Menu\MenuLinkBase $original_link */
$original_link = $item['original_link'];
if ($original_link->getUrlObject()->isExternal() || !$original_link->getUrlObject()->isRouted()) {
// Do not filter external URL at all.
continue;
}
$route_name = $original_link->getRouteName() ?: $original_link->getUrlObject()->getRouteName();
$route_params = $original_link->getRouteParameters() ?: $original_link->getUrlObject()->getRouteParameters();
}
elseif (!empty($item['url'])) {
/** @var \Drupal\Core\Url $url */
$url = $item['url'];
if ($url->isExternal() || !$original_link->getUrlObject()->isRouted()) {
// Do not filter external URL at all.
continue;
}
$route_name = $url->getRouteName();
$route_params = $url->getRouteParameters();
}
// Check, if user has access rights to the route.
if (!$access_manager->checkNamedRoute($route_name, $route_params)) {
unset($items[$menu_id]);
}
else {
if (!empty($items[$menu_id]['below'])) {
// Recursively call this function for the child items.
admin_toolbar_links_access_filter_filter_non_accessible_links($items[$menu_id]['below']);
}
if (empty($items[$menu_id]['below'])) {
// Every child item has been cleared out.
// Now check, if the given route represents an overview page only,
// without having functionality on its own. In this case, we can
// safely unset this item, as there aren't any children left.
// This assumption is only valid, when the admin_toolbar module is
// installed because otherwise we won't have child items at all.
if (admin_toolbar_links_access_filter_is_overview_page($route_name)) {
unset($items[$menu_id]);
}
// If there are no sub-items and the parent does not have a link, then
// it is safe to remove it.
elseif ($route_name === '<nolink>') {
unset($items[$menu_id]);
}
else {
// Let's remove the expanded flag.
$items[$menu_id]['is_expanded'] = FALSE;
}
}
}
}
catch (\UnexpectedValueException $e) {
// Skip on errors like "base:block has no corresponding route":
\Drupal::logger('my_module')->error($e->getMessage());
continue;
}
}
}
/**
* Checks if the given route name is an overview page.
*
* Checks if the given route name matches a pure (admin) overview page that can
* be skipped, if there are no child items set. The typical example are routes
* having the SystemController::systemAdminMenuBlockPage() function as their
* controller callback set.
*
* @param string $route_name
* The route name to check.
*
* @return bool
* TRUE, if the given route name matches a pure admin overview page route,
* FALSE otherwise.
*/
function admin_toolbar_links_access_filter_is_overview_page($route_name) {
/** @var \Drupal\Core\Routing\RouteProviderInterface $route_provider. */
$route_provider = \Drupal::service('router.route_provider');
$overview_page_controllers = [
'\Drupal\system\Controller\AdminController::index',
'\Drupal\system\Controller\SystemController::overview',
'\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage',
];
try {
$route = $route_provider->getRouteByName($route_name);
$controller = $route->getDefault('_controller');
return !empty($controller) && in_array($controller, $overview_page_controllers);
}
catch (RouteNotFoundException $ex) {
}
return FALSE;
}
/**
* Checks, if the given user has admin rights.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The account to check.
*
* @return bool
* TRUE, if the given user account has at least one role with admin rights
* assigned, FALSE otherwise.
*/
function admin_toolbar_links_access_filter_user_has_admin_role(AccountInterface $account) {
static $user_has_admin_role = [];
$uid = $account->id();
if (!isset($user_has_admin_role[$uid])) {
$user_has_admin_role[$uid] = FALSE;
$roles = Role::loadMultiple($account->getRoles());
// It is possible for a user account to have no roles assigned.
if (!empty($roles)) {
foreach ($roles as $role) {
if ($role->isAdmin()) {
$user_has_admin_role[$uid] = TRUE;
break;
}
}
}
}
return $user_has_admin_role[$uid];
}

View File

@@ -0,0 +1,13 @@
name: Admin Toolbar Search
description: Provides search of Admin Toolbar items.
package: Administration
type: module
core_version_requirement: ^9.2 || ^10
configure: admin_toolbar_search.settings
dependencies:
- admin_toolbar:admin_toolbar_tools
# Information added by Drupal.org packaging script on 2023-09-29
version: '3.4.2'
project: 'admin_toolbar'
datestamp: 1696006156

View File

@@ -0,0 +1,11 @@
search:
css:
theme:
css/admin.toolbar_search.css: {}
js:
js/admin_toolbar_search.js: {}
dependencies:
- core/jquery
- core/drupal
- core/once
- core/drupal.autocomplete

View File

@@ -0,0 +1,5 @@
admin_toolbar_search.settings:
title: 'Admin Toolbar Search'
description: 'Configure the Admin Toolbar Search module.'
route_name: admin_toolbar_search.settings
parent: system.admin_config_ui

View File

@@ -0,0 +1,142 @@
<?php
/**
* @file
* Functionality for search of Admin Toolbar.
*/
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/**
* 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) {
if (!\Drupal::currentUser()->hasPermission('use admin toolbar search')) {
return;
}
$admin_toolbar_tools_enabled = \Drupal::service('module_handler')
->moduleExists('admin_toolbar_tools');
$config = \Drupal::config('admin_toolbar_search.settings');
$display_menu_item = $config->get('display_menu_item');
if (!$display_menu_item) {
$items['administration_mobile_search'] = [
'#type' => 'toolbar_item',
'#weight' => 100,
'tab' => [
'#type' => 'link',
'#title' => new TranslatableMarkup('Search'),
'#url' => Url::fromRoute('system.admin'),
'#attributes' => [
'class' => [
'toolbar-icon',
],
],
],
'#wrapper_attributes' => [
'id' => 'admin-toolbar-mobile-search-tab',
],
];
$items['administration_search'] = [
"#type" => "toolbar_item",
'#weight' => 101,
'tab' => [
'search' => [
'#title' => t('Search'),
'#title_display' => 'invisible',
'#type' => 'search',
'#size' => 30,
'#attributes' => [
'placeholder' => new TranslatableMarkup('Admin Toolbar quick search'),
],
'#id' => 'admin-toolbar-search-input',
],
],
'#attached' => [
'library' => [
'admin_toolbar_search/search',
],
'drupalSettings' => [
'adminToolbarSearch' => [
'loadExtraLinks' => $admin_toolbar_tools_enabled,
],
],
],
'#wrapper_attributes' => [
'id' => 'admin-toolbar-search-tab',
],
'#cache' => [
'contexts' => [
'user.permissions',
],
'tags' => [
'config:admin_toolbar_search.settings',
],
],
];
}
else {
$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' => t('Search'),
'#type' => 'search',
'#size' => 60,
'#id' => 'admin-toolbar-search-input',
],
],
'#attached' => [
'library' => [
'admin_toolbar_search/search',
],
'drupalSettings' => [
'adminToolbarSearch' => [
'loadExtraLinks' => $admin_toolbar_tools_enabled,
],
],
],
'#wrapper_attributes' => [
"id" => "admin-toolbar-search-tab",
],
'#cache' => [
'contexts' => [
'user.permissions',
],
'tags' => [
'config:admin_toolbar_search.settings',
],
],
];
}
}

View File

@@ -0,0 +1,2 @@
use admin toolbar search:
title: 'Use Admin Toolbar search'

View File

@@ -0,0 +1,14 @@
admin_toolbar.search:
path: '/admin/admin-toolbar-search'
defaults:
_controller: '\Drupal\admin_toolbar_search\Controller\AdminToolbarSearchController::search'
requirements:
_permission: 'use admin toolbar search'
admin_toolbar_search.settings:
path: '/admin/config/user-interface/admin-toolbar-search-settings'
defaults:
_title: 'Admin toolbar search settings'
_form: 'Drupal\admin_toolbar_search\Form\AdminToolbarSearchSettingsForm'
requirements:
_permission: 'administer site configuration'

View File

@@ -0,0 +1,10 @@
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'
- '@config.factory'

View File

@@ -0,0 +1,110 @@
#admin-toolbar-mobile-search-tab ~ #admin-toolbar-search-tab {
display: none;
}
#admin-toolbar-mobile-search-tab ~ #admin-toolbar-search-tab.visible {
display: block;
width: 100%;
}
#admin-toolbar-mobile-search-tab ~ #admin-toolbar-search-tab .js-form-item.form-item {
margin: 0.75rem 0;
padding-left: 1rem;
padding-right: 1rem;
}
#admin-toolbar-mobile-search-tab .toolbar-item::before {
background-image: url('../../misc/icons/bebebe/loupe.svg');
}
#admin-toolbar-mobile-search-tab ~ #admin-toolbar-search-tab #admin-toolbar-search-input {
width: 100%;
}
@media only screen and (min-width: 769px) {
#admin-toolbar-mobile-search-tab {
display: none;
}
#admin-toolbar-mobile-search-tab ~ #admin-toolbar-search-tab {
display: block;
}
#admin-toolbar-mobile-search-tab ~ #admin-toolbar-search-tab.visible {
width: auto;
}
#admin-toolbar-mobile-search-tab ~ #admin-toolbar-search-tab .js-form-item.form-item {
margin-top: 0.3rem;
margin-bottom: 0;
}
}
#admin-toolbar-search-input {
min-height: 30px;
height: 100%;
padding: 0 0.4rem;
line-height: 1.75rem;
margin: 0;
color: #3b3b3b;
background: #fcfcfa;
border: 1px solid #ccc;
border-radius: unset;
font-size: 1em;
}
.ui-autocomplete .ui-menu-item span.admin-toolbar-search-url {
display: none;
}
.admin-toolbar-search-autocomplete-list {
max-height: 300px;
overflow-y: scroll;
}
.admin-toolbar-search-autocomplete-list .ui-menu-item .ui-state-active {
margin: 0;
}
.admin-toolbar-search-autocomplete-list .ui-menu-item .ui-menu-item-wrapper {
border: 1px solid transparent;
padding: 3px 1em 3px 0.4em;
}
.admin-toolbar-search-autocomplete-list .ui-menu-item a {
text-decoration: none;
}
.admin-toolbar-search-autocomplete-list .ui-menu-item .ui-state-active:hover a,
.admin-toolbar-search-autocomplete-list .ui-menu-item .ui-state-active a {
color: white;
}
#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;
}
#toolbar-item-administration-search-tray input {
display: inline-block;
padding: 0.3em 0.4em 0.3em 0.5em;
font-size: 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 div.form-item.js-form-type-textfield {
margin: 0.75em 0;
}

View File

@@ -0,0 +1,151 @@
/**
* @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 $self = this;
const elements = once('admin-toolbar-search', '#toolbar-bar', context);
$(elements).each(function () {
$self.links = [];
var $searchTab = $(this).find('#admin-toolbar-search-tab')
var $searchInput = $searchTab.find('#admin-toolbar-search-input');
if ($searchInput.length === 0) {
return;
}
$searchInput.autocomplete({
minLength: 2,
position: { collision : 'fit' },
source: function (request, response) {
var data = $self.handleAutocomplete(request.term);
if (!$self.extraFetched && drupalSettings.adminToolbarSearch.loadExtraLinks) {
$.getJSON( Drupal.url('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-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) {
ul.addClass('admin-toolbar-search-autocomplete-list');
return $('<li>')
.append('<div ><a href="' + item.value + '" onclick="window.open(this.href); return false;" >' + item.labelRaw + ' <span class="admin-toolbar-search-url">' + item.value + '</span></a></div>')
.appendTo(ul);
});
// Populate the links for search results when the input is pressed.
$searchInput.focus(function () {
Drupal.behaviors.adminToolbarSearch.populateLinks($self);
});
// Show/hide search input field when mobile tab item is pressed.
$('#admin-toolbar-mobile-search-tab .toolbar-item', context).click(function (e) {
e.preventDefault();
$(this).toggleClass('is-active');
$searchTab.toggleClass('visible');
$searchInput.focus();
});
});
},
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;
},
/**
* Populates the links in admin toolbar search.
*/
populateLinks: function ($self) {
// Populate only when links array is empty (only the first time).
if ($self.links.length === 0) {
var getUrl = window.location;
var baseUrl = getUrl.protocol + "//" + getUrl.host + "/";
$('.toolbar-tray a[data-drupal-link-system-path]').each(function () {
if (this.href !== baseUrl) {
var label = $self.getItemLabel(this);
$self.links.push({
'value': this.href,
'label': label + ' ' + this.href,
'labelRaw': Drupal.checkPlain(label)
});
}
});
}
},
};
})(jQuery, Drupal);

View File

@@ -0,0 +1,50 @@
<?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 to the search functionality.
*
* @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());
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Drupal\admin_toolbar_search\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Configure Admin Toolbar Search settings for this site.
*/
class AdminToolbarSearchSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'admin_toolbar_search_admin_toolbar_search_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['admin_toolbar_search.settings'];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['display_menu_item'] = [
'#type' => 'checkbox',
'#title' => $this->t('Display the search input as a menu item.'),
'#description' => $this->t("If set, instead of displaying a text input field, it displays a menu item in the toolbar so the user has to click on it to toggle the search input."),
'#default_value' => $this->config('admin_toolbar_search.settings')->get('display_menu_item'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('admin_toolbar_search.settings')
->set('display_menu_item', $form_state->getValue('display_menu_item'))
->save();
parent::submitForm($form, $form_state);
}
}

View File

@@ -0,0 +1,317 @@
<?php
namespace Drupal\admin_toolbar_search;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\Context\CacheContextsManager;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use Drupal\system\Entity\Menu;
/**
* Extra search links.
*/
class SearchLinks {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected $routeProvider;
/**
* The cache context manager service.
*
* @var \Drupal\Core\Cache\Context\CacheContextsManager
*/
protected $cacheContextManager;
/**
* The toolbar cache bin.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $toolbarCache;
/**
* The admin toolbar tools configuration.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* 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.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Config factory mservice.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, RouteProviderInterface $route_provider, CacheContextsManager $cache_context_manager, CacheBackendInterface $toolbar_cache, ConfigFactoryInterface $config_factory) {
$this->entityTypeManager = $entity_type_manager;
$this->moduleHandler = $module_handler;
$this->routeProvider = $route_provider;
$this->cacheContextManager = $cache_context_manager;
$this->toolbarCache = $toolbar_cache;
$this->config = $config_factory->get('admin_toolbar_tools.settings');
}
/**
* Gets extra links for admin toolbar search feature.
*
* @return array
* An array of link data for the JSON used for search.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function getLinks() {
$max_bundle_number = $this->config->get('max_bundle_number');
$additional_keys = $this->cacheContextManager->convertTokensToKeys([
'languages:' . LanguageInterface::TYPE_INTERFACE,
'user.permissions',
])->getKeys();
$cid_parts = array_merge(['admin_toolbar_search:links'], $additional_keys);
$cid = implode(':', $cid_parts);
if ($cache = $this->toolbarCache->get($cid)) {
return $cache->data;
}
$links = [];
$cache_tags = [];
$content_entities = $this->getBundleableEntitiesList();
// Adds common links to entities.
foreach ($content_entities as $entities) {
$content_entity_bundle = $entities['content_entity_bundle'];
$content_entity = $entities['content_entity'];
// Load the remaining items that were not loaded by the toolbar.
$content_entity_bundle_storage = $this->entityTypeManager->getStorage($content_entity_bundle);
$bundles_ids = $content_entity_bundle_storage->getQuery()->sort('weight')->range($max_bundle_number)->execute();
if (!empty($bundles_ids)) {
$bundles = $this->entityTypeManager
->getStorage($content_entity_bundle)
->loadMultiple($bundles_ids);
foreach ($bundles as $machine_name => $bundle) {
$cache_tags = Cache::mergeTags($cache_tags, $bundle->getEntityType()->getListCacheTags());
$tparams = [
'@entity_type' => $bundle->getEntityType()->getLabel(),
'@bundle' => $bundle->label(),
];
$label_base = $this->t('@entity_type > @bundle', $tparams);
$params = [$content_entity_bundle => $machine_name];
if ($this->routeExists('entity.' . $content_entity_bundle . '.overview_form')) {
// Some bundles have an overview/list form that make a better root
// link.
$url = Url::fromRoute('entity.' . $content_entity_bundle . '.overview_form', $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $label_base,
'value' => $url_string,
];
}
}
if ($this->routeExists('entity.' . $content_entity_bundle . '.edit_form')) {
$url = Url::fromRoute('entity.' . $content_entity_bundle . '.edit_form', $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $label_base . ' > ' . $this->t('Edit'),
'value' => $url_string,
];
}
}
if ($this->moduleHandler->moduleExists('field_ui')) {
if ($this->routeExists('entity.' . $content_entity . '.field_ui_fields')) {
$url = Url::fromRoute('entity.' . $content_entity . '.field_ui_fields', $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $label_base . ' > ' . $this->t('Manage fields'),
'value' => $url_string,
];
}
}
if ($this->routeExists('entity.entity_form_display.' . $content_entity . '.default')) {
$url = Url::fromRoute('entity.entity_form_display.' . $content_entity . '.default', $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $label_base . ' > ' . $this->t('Manage form display'),
'value' => $url_string,
];
}
}
if ($this->routeExists('entity.entity_view_display.' . $content_entity . '.default')) {
$url = Url::fromRoute('entity.entity_view_display.' . $content_entity . '.default', $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $label_base . ' > ' . $this->t('Manage display'),
'value' => $url_string,
];
}
}
if ($this->moduleHandler->moduleExists('devel') && $this->routeExists('entity.' . $content_entity_bundle . '.devel_load')) {
$url = Url::fromRoute($route_name = 'entity.' . $content_entity_bundle . '.devel_load', $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $label_base . ' > ' . $this->t('Devel'),
'value' => $url_string,
];
}
}
if ($this->routeExists('entity.' . $content_entity_bundle . '.delete_form')) {
$url = Url::fromRoute('entity.' . $content_entity_bundle . '.delete_form', $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $label_base . ' > ' . $this->t('Delete'),
'value' => $url_string,
];
}
}
}
}
}
}
// Add menu links.
if ($this->moduleHandler->moduleExists('menu_ui')) {
$menus = $this->entityTypeManager->getStorage('menu')->loadMultiple();
uasort($menus, [Menu::class, 'sort']);
$menus = array_slice($menus, $max_bundle_number);
$cache_tags = Cache::mergeTags($cache_tags, ['config:menu_list']);
foreach ($menus as $menu_id => $menu) {
$route_name = 'entity.menu.edit_form';
$params = ['menu' => $menu_id];
$url = Url::fromRoute($route_name, $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $this->t('Menus > @menu_label', ['@menu_label' => $menu->label()]),
'value' => $url_string,
];
}
$route_name = 'entity.menu.add_link_form';
$params = ['menu' => $menu_id];
$url = Url::fromRoute($route_name, $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $this->t('Menus > @menu_label > Add link', ['@menu_label' => $menu->label()]),
'value' => $url_string,
];
}
$menus = ['admin', 'devel', 'footer', 'main', 'tools', 'account'];
if (!in_array($menu_id, $menus)) {
$route_name = 'entity.menu.delete_form';
$params = ['menu' => $menu_id];
$url = Url::fromRoute($route_name, $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $this->t('Menus > @menu_label > Delete', ['@menu_label' => $menu->label()]),
'value' => $url_string,
];
}
}
if ($this->moduleHandler->moduleExists('devel') && $this->routeExists('entity.menu.devel_load')) {
$route_name = 'entity.menu.devel_load';
$params = ['menu' => $menu_id];
$url = Url::fromRoute($route_name, $params);
if ($url->access()) {
$url_string = $url->toString();
$links[] = [
'labelRaw' => $this->t('Menus > @menu_label > Devel', ['@menu_label' => $menu->label()]),
'value' => $url_string,
];
}
}
}
}
$this->toolbarCache->set($cid, $links, Cache::PERMANENT, $cache_tags);
return $links;
}
/**
* Gets a list of content entities.
*
* @return array
* An array of metadata about content entities.
*/
protected function getBundleableEntitiesList() {
$entity_types = $this->entityTypeManager->getDefinitions();
$content_entities = [];
foreach ($entity_types as $key => $entity_type) {
if ($entity_type->getBundleEntityType() && ($entity_type->get('field_ui_base_route') != '')) {
$content_entities[$key] = [
'content_entity' => $key,
'content_entity_bundle' => $entity_type->getBundleEntityType(),
];
}
}
return $content_entities;
}
/**
* Determine if a route exists by name.
*
* @param string $route_name
* The name of the route to check.
*
* @return bool
* Whether a route with that route name exists.
*/
public function routeExists($route_name) {
return (count($this->routeProvider->getRoutesByNames([$route_name])) === 1);
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace Drupal\Tests\admin_toolbar_search\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
/**
* Test the functionality of admin toolbar search.
*
* @group admin_toolbar
* @group admin_toolbar_search
*/
class AdminToolbarSearchSettingTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'admin_toolbar_search',
'node',
'media',
'field_ui',
'menu_ui',
'block',
];
/**
* A user with the 'Use Admin Toolbar search' permission.
*
* @var \Drupal\user\UserInterface
*/
protected $userWithAccess;
/**
* A test user without the 'Use Admin Toolbar search' permission..
*
* @var \Drupal\user\UserInterface
*/
protected $noAccessUser;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$permissions = [
'access toolbar',
'administer menu',
'access administration pages',
'administer site configuration',
'administer content types',
];
$this->noAccessUser = $this->drupalCreateUser($permissions);
$permissions[] = 'use admin toolbar search';
$this->userWithAccess = $this->drupalCreateUser($permissions);
}
/**
* Tests search functionality without admin_toolbar_tools enabled.
*/
public function testToolbarSearch() {
$this->drupalLogin($this->userWithAccess);
$this->drupalGet(Url::fromRoute('system.admin'));
$this->assertSession()->responseNotContains('id="toolbar-item-administration-search');
$this->config('admin_toolbar_search.settings')->set('display_menu_item', 1);
$this->config('admin_toolbar_search.settings')->save();
$this->drupalGet(Url::fromRoute('system.admin'));
$this->assertSession()->responseContains('id="toolbar-item-administration-search');
$this->config('admin_toolbar_search.settings')->set('display_menu_item', 0);
$this->config('admin_toolbar_search.settings')->save();
$this->drupalGet(Url::fromRoute('system.admin'));
$this->assertSession()->responseNotContains('id="toolbar-item-administration-search');
}
}

View File

@@ -0,0 +1,51 @@
<?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 = '#admin-toolbar-search-tab';
$search_toolbar_item = '#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);
$assert_session->waitForElementVisible('css', $search_toolbar_item);
$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 = '#admin-toolbar-search-tab';
$search_toolbar_item = '#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_toolbar_item);
$assert_session->elementNotExists('css', $search_tray);
}
}

View File

@@ -0,0 +1,192 @@
<?php
namespace Drupal\Tests\admin_toolbar_search\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\system\Entity\Menu;
/**
* Base class for testing the functionality of admin toolbar search.
*
* @group admin_toolbar
* @group admin_toolbar_search
*/
abstract class AdminToolbarSearchTestBase extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'admin_toolbar_search',
'node',
'media',
'field_ui',
'menu_ui',
'block',
];
/**
* A user with the 'Use Admin Toolbar search' permission.
*
* @var \Drupal\user\UserInterface
*/
protected $userWithAccess;
/**
* A test user without the 'Use Admin Toolbar search' permission..
*
* @var \Drupal\user\UserInterface
*/
protected $noAccessUser;
/**
* {@inheritdoc}
*/
public function setUp(): void {
parent::setUp();
$baby_names = [
'ada' => 'Ada',
'amara' => 'Amara',
'amelia' => 'Amelia',
'arabella' => 'Arabella',
'asher' => 'Asher',
'astrid' => 'Astrid',
'atticus' => 'Atticus',
'aurora' => 'Aurora',
'ava' => 'Ava',
'cora' => 'Cora',
'eleanor' => 'Eleanor',
'eloise' => 'Eloise',
'felix' => 'Felix',
'freya' => 'Freya',
'genevieve' => 'Genevieve',
'isla' => 'Isla',
'jasper' => 'Jasper',
'luna' => 'Luna',
'maeve' => 'Maeve',
'milo' => 'Milo',
'nora' => 'Nora',
'olivia' => 'Olivia',
'ophelia' => 'Ophelia',
'posie' => 'Posie',
'rose' => 'Rose',
'silas' => 'Silas',
'soren' => 'Soren',
];
foreach ($baby_names as $id => $label) {
$menu = Menu::create([
'id' => $id,
'label' => $label,
]);
$menu->save();
}
$this->drupalPlaceBlock('local_tasks_block');
$permissions = [
'access toolbar',
'administer menu',
'access administration pages',
'administer site configuration',
'administer content types',
];
$this->noAccessUser = $this->drupalCreateUser($permissions);
$permissions[] = 'use admin toolbar search';
$this->userWithAccess = $this->drupalCreateUser($permissions);
}
/**
* Assert that the search suggestions contain a given string with given input.
*
* @param string $search
* The string to search for.
* @param string $contains
* Some HTML that is expected to be within the suggestions element.
*/
protected function assertSuggestionContains($search, $contains) {
$this->resetSearch();
$page = $this->getSession()->getPage();
$page->fillField('admin-toolbar-search-input', $search);
$this->getSession()->getDriver()->keyDown('//input[@id="admin-toolbar-search-input"]', ' ');
$page->waitFor(3, function () use ($page) {
return ($page->find('css', 'ul.ui-autocomplete')->isVisible() === TRUE);
});
$suggestions_markup = $page->find('css', 'ul.ui-autocomplete')->getHtml();
$this->assertStringContainsString($contains, $suggestions_markup);
}
/**
* Assert that the search suggestions does not contain a given string.
*
* Assert that the search suggestions does not contain a given string with a
* given input.
*
* @param string $search
* The string to search for.
* @param string $contains
* Some HTML that is not expected to be within the suggestions element.
*/
protected function assertSuggestionNotContains($search, $contains) {
$this->resetSearch();
$page = $this->getSession()->getPage();
$page->fillField('admin-toolbar-search-input', $search);
$this->getSession()->getDriver()->keyDown('//input[@id="admin-toolbar-search-input"]', ' ');
$page->waitFor(3, function () use ($page) {
return ($page->find('css', 'ul.ui-autocomplete')->isVisible() === TRUE);
});
if ($page->find('css', 'ul.ui-autocomplete')->isVisible() === FALSE) {
return;
}
else {
$suggestions_markup = $page->find('css', 'ul.ui-autocomplete')->getHtml();
$this->assertStringNotContainsString($contains, $suggestions_markup);
}
}
/**
* Search for an empty string to clear out the autocomplete suggestions.
*/
protected function resetSearch() {
$page = $this->getSession()->getPage();
// Empty out the suggestions.
$page->fillField('admin-toolbar-search-input', '');
$this->getSession()->getDriver()->keyDown('//input[@id="admin-toolbar-search-input"]', ' ');
$page->waitFor(3, function () use ($page) {
return ($page->find('css', 'ul.ui-autocomplete')->isVisible() === FALSE);
});
}
/**
* Checks that there is a link with the specified url in the admin toolbar.
*
* @param string $url
* The url to assert exists in the admin menu.
*
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
protected function assertMenuHasHref($url) {
$this->assertSession()
->elementExists('xpath', '//div[@id="toolbar-item-administration-tray"]//a[contains(@href, "' . $url . '")]');
}
/**
* Checks that there is no link with the specified url in the admin toolbar.
*
* @param string $url
* The url to assert exists in the admin menu.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
protected function assertMenuDoesNotHaveHref($url) {
$this->assertSession()
->elementNotExists('xpath', '//div[@id="toolbar-item-administration-tray"]//a[contains(@href, "' . $url . '")]');
}
}

View File

@@ -0,0 +1,216 @@
<?php
namespace Drupal\Tests\admin_toolbar_search\FunctionalJavascript;
use Drupal\media\Entity\MediaType;
use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
/**
* Test the functionality of admin toolbar search.
*
* @group admin_toolbar
* @group admin_toolbar_search
*/
class AdminToolbarToolsSearchTest extends AdminToolbarSearchTestBase {
use MediaTypeCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'admin_toolbar_tools',
'admin_toolbar_search',
'node',
'media',
'field_ui',
'menu_ui',
'block',
];
/**
* The admin user for tests.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
public function setUp(): void {
parent::setUp();
$this->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$dog_names = [
'archie' => 'Archie',
'bailey' => 'Bailey',
'bella' => 'Bella',
'buddy' => 'Buddy',
'charlie' => 'Charlie',
'coco' => 'Coco',
'daisy' => 'Daisy',
'frankie' => 'Frankie',
'jack' => 'Jack',
'lola' => 'Lola',
'lucy' => 'Lucy',
'max' => 'Max',
'milo' => 'Milo',
'molly' => 'Molly',
'ollie' => 'Ollie',
'oscar' => 'Oscar',
'rosie' => 'Rosie',
'ruby' => 'Ruby',
'teddy' => 'Teddy',
'toby' => 'Toby',
'tonga' => 'Tonga',
'tracey' => 'Tracey',
'tuna' => 'Tuna',
'uno' => 'Uno',
'venus' => 'Venus',
'vicky' => 'Vicky',
'wimpy' => 'Wimpy',
'yellow' => 'Yellow',
'zac' => 'zac',
'zora' => 'zora',
];
foreach ($dog_names as $machine_name => $label) {
$this->createMediaType('image', [
'id' => $machine_name,
'label' => $label,
]);
}
$this->adminUser = $this->drupalCreateUser([
'access toolbar',
'administer menu',
'access administration pages',
'administer site configuration',
'administer content types',
'administer node fields',
'access media overview',
'administer media',
'administer media fields',
'administer media form display',
'administer media display',
'administer media types',
'use admin toolbar search',
]);
}
/**
* Tests search functionality with admin_toolbar_tools enabled.
*/
public function testToolbarSearch() {
$search_tab = '#admin-toolbar-search-tab';
$search_toolbar_item = '#toolbar-item-administration-search';
$search_tray = '#toolbar-item-administration-search-tray';
$this->drupalLogin($this->adminUser);
$assert_session = $this->assertSession();
$assert_session->responseContains('admin.toolbar_search.css');
$assert_session->responseContains('admin_toolbar_search.js');
$assert_session->waitForElementVisible('css', $search_tab);
$assert_session->waitForElementVisible('css', $search_toolbar_item);
$assert_session->waitForElementVisible('css', $search_tray);
$this->assertSuggestionContains('basic', 'admin/config/system/site-information');
// Rebuild menu items.
drupal_flush_all_caches();
// Test that the route admin_toolbar.search returns expected json.
$this->drupalGet('/admin/admin-toolbar-search');
$search_menus = [
'maeve',
'milo',
'nora',
'olivia',
'ophelia',
'posie',
'rose',
'silas',
'soren',
];
$toolbar_menus = [
'ada',
'amara',
'amelia',
'arabella',
'asher',
'astrid',
'atticus',
'aurora',
'ava',
];
foreach ($search_menus as $menu_id) {
$assert_session->responseContains('\/admin\/structure\/menu\/manage\/' . $menu_id);
}
foreach ($toolbar_menus as $menu_id) {
$assert_session->responseNotContains('\/admin\/structure\/menu\/manage\/' . $menu_id);
}
$this->drupalGet('/admin');
foreach ($search_menus as $menu_id) {
$this->assertMenuDoesNotHaveHref('/admin/structure/menu/manage/' . $menu_id);
}
foreach ($toolbar_menus as $menu_id) {
$this->assertMenuHasHref('/admin/structure/menu/manage/' . $menu_id);
}
$this->drupalGet('admin/structure/types/manage/article/fields');
$assert_session->waitForElementVisible('css', $search_tray);
$this->assertSuggestionContains('article manage fields', '/admin/structure/types/manage/article/fields');
$suggestions = $assert_session
->waitForElementVisible('css', 'ul.ui-autocomplete');
// Assert there is only one suggestion with a link to
// /admin/structure/types/manage/article/fields.
$count = count($suggestions->findAll('xpath', '//span[contains(text(), "/admin/structure/types/manage/article/fields")]'));
$this->assertEquals(1, $count);
// Test that bundle within admin toolbar appears in search.
$this->assertSuggestionContains('lola', 'admin/structure/media/manage/lola/fields');
// Assert that a link after the limit doesn't appear in admin toolbar.
$zora_url = '/admin/structure/media/manage/zora/fields';
$assert_session->elementNotContains('css', '#toolbar-administration', $zora_url);
// Assert that a link excluded from admin toolbar appears in search.
$this->assertSuggestionContains('zora', $zora_url);
// Test that adding a new bundle updates the extra links loaded from
// admin_toolbar.search route.
$this->createMediaType('image', [
'id' => 'zuzu',
'label' => 'Zuzu',
]);
$this->drupalGet('admin');
$assert_session->waitForElementVisible('css', $search_tray);
$this->assertSuggestionContains('zuzu', '/admin/structure/media/manage/zuzu/fields');
// Test that deleting a bundle updates the extra links loaded from
// admin_toolbar.search route.
$zora = MediaType::load('zora');
$zora->delete();
$this->getSession()->reload();
$assert_session->waitForElementVisible('css', $search_tray);
$this->assertSuggestionNotContains('zora', $zora);
}
}

View File

@@ -0,0 +1,56 @@
# Admin Toolbar Tools
Admin Toolbar Extra Tools provides menu links to administration pages or actions
(eg. Flushing caches) that are not generated by Drupal core. It adds menu items
that are not generated by Drupal core. For example there are no menu items for
each content type by default or menu links to Manage fields on each entity
types. That's the purpose of Admin Toolbar Extra Tools to add them.
For a full description of the module, visit the
[project page](https://www.drupal.org/project/admin_toolbar).
Submit bug reports and feature suggestions, or track changes in the
[issue queue](https://www.drupal.org/project/issues/search/admin_toolbar).
## Table of contents
- Requirements
- Installation
- Configuration
- Maintainers
## Requirements
This module requires the following modules:
- [Admin Toolbar](https://www.drupal.org/project/admin_toolbar)
## Installation
Install as you would normally install a contributed Drupal module. For further
information, see
[Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).
## Configuration
No configuration is needed.
## Maintainers
Current maintainers:
- [Romain Jarraud (romainj)](https://www.drupal.org/u/romainj)
- [Adrian Cid Almaguer (adriancid)](https://www.drupal.org/u/adriancid)
- [Wilfrid Roze (eme)](https://www.drupal.org/u/eme)
- [bilel khalil (bolbol)](https://www.drupal.org/u/bolbol)
- [fethi.krout (fethi.krout)](https://www.drupal.org/u/fethi.krout)
- [Mohamed Anis Taktak (matio89)](https://www.drupal.org/u/matio89)
- [Thomas MUSA (Musa.thomas)](https://www.drupal.org/u/musathomas)
Supporting organizations:
- [emerya](https://www.drupal.org/emerya) Created this module for you!
- [Trained People](https://www.drupal.org/trained-people) Sponsored the module development
- [Drupiter](https://www.drupal.org/drupiter) Sponsored the module development
- [Dropteam](https://www.drupal.org/dropteam) Sponsored the module development
- [Alliance of Digital Builders (AODB)](https://www.drupal.org/alliance-of-digital-builders-aodb) Sponsored the module development

View File

@@ -0,0 +1,13 @@
name: Admin Toolbar Extra Tools
description: Adds menu links like Flush cache, Run cron, Run updates, and Logout under Drupal icon.
package: Administration
configure: admin_toolbar_tools.settings
type: module
core_version_requirement: ^9.2 || ^10
dependencies:
- admin_toolbar:admin_toolbar
# Information added by Drupal.org packaging script on 2023-09-29
version: '3.4.2'
project: 'admin_toolbar'
datestamp: 1696006156

View File

@@ -0,0 +1,34 @@
<?php
/**
* @file
* Install, update and uninstall functions for the Admin Toolbar Tools module.
*/
/**
* Install the Admin Toolbar Search module.
*/
function admin_toolbar_tools_update_8001() {
// Installing the Admin Toolbar Search module.
\Drupal::service('module_installer')->install(['admin_toolbar_search']);
}
/**
* Default setting for maximum number of bundles per entity type to display.
*/
function admin_toolbar_tools_update_8201() {
\Drupal::service('config.factory')
->getEditable('admin_toolbar_tools.settings')
->set('max_bundle_number', 20)
->save(TRUE);
}
/**
* Default setting for enable hoverintent.
*/
function admin_toolbar_tools_update_8202() {
\Drupal::service('config.factory')
->getEditable('admin_toolbar_tools.settings')
->set('hoverintent_functionality', TRUE)
->save(TRUE);
}

View File

@@ -0,0 +1,4 @@
toolbar.icon:
css:
theme:
css/tools.css: {}

View File

@@ -0,0 +1,92 @@
admin_toolbar_tools.help:
title: 'Tools'
route_name: <front>
menu_name: admin
parent: system.admin
weight: -100
system.admin_index:
title: 'Index'
route_name: system.admin_index
menu_name: admin
parent: admin_toolbar_tools.help
weight: -100
system.run_cron:
title: 'Run cron'
route_name: admin_toolbar.run.cron
menu_name: admin
parent: admin_toolbar_tools.help
weight: -8
system.db_update:
title: 'Run updates'
route_name: system.db_update
menu_name: admin
parent: admin_toolbar_tools.help
weight: -6
system.modules_uninstall:
title: 'Uninstall module'
route_name: system.modules_uninstall
menu_name: admin
parent: system.modules_list
admin_toolbar_tools.flush:
title: 'Flush all caches'
route_name: admin_toolbar_tools.flush
weight: -9
parent: admin_toolbar_tools.help
menu_name: admin
admin_toolbar_tools.cssjs:
title: 'Flush CSS and JavaScript'
route_name: admin_toolbar_tools.cssjs
parent: admin_toolbar_tools.flush
menu_name: admin
admin_toolbar_tools.plugin:
title: 'Flush plugins cache'
route_name: admin_toolbar_tools.plugin
parent: admin_toolbar_tools.flush
menu_name: admin
admin_toolbar_tools.flush_static:
title: 'Flush static cache'
route_name: admin_toolbar_tools.flush_static
parent: admin_toolbar_tools.flush
menu_name: admin
admin_toolbar_tools.flush_menu:
title: 'Flush routing and links cache'
route_name: admin_toolbar_tools.flush_menu
parent: admin_toolbar_tools.flush
menu_name: admin
admin_toolbar_tools.flush_twig:
title: 'Flush twig cache'
route_name: admin_toolbar_tools.flush_twig
parent: admin_toolbar_tools.flush
menu_name: admin
admin_toolbar_tools.flush_rendercache:
title: 'Flush render cache'
route_name: admin_toolbar_tools.flush_rendercache
parent: admin_toolbar_tools.flush
menu_name: admin
admin_toolbar_tools.theme_rebuild:
title: 'Rebuild theme registry'
route_name: admin_toolbar_tools.theme_rebuild
parent: admin_toolbar_tools.flush
menu_name: admin
admin_toolbar_tools.extra_links:
deriver: \Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks
menu_name: admin
admin_toolbar_tools.settings:
title: 'Admin Toolbar Tools'
description: 'Configure the Admin Toolbar Tools module.'
route_name: admin_toolbar_tools.settings
parent: system.admin_config_ui

View File

@@ -0,0 +1,99 @@
<?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_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) {
// 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();
}
}
}

View File

@@ -0,0 +1,13 @@
<?php
/**
* @file
* Post-update functions for the Admin Toolbar Tools module.
*/
/**
* Update container for admin_toolbar_tools.helper arguments.
*/
function admin_toolbar_tools_post_update_helper_added_config_factory() {
// Intentionally empty to trigger a service container rebuild.
}

View File

@@ -0,0 +1,97 @@
admin_toolbar_tools.flush:
path: '/admin/flush'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushAll'
_title: 'Flush all caches'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar_tools.cssjs:
path: '/admin/flush/cssjs'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushJsCss'
_title: 'Flush CSS and JavaScript'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar_tools.plugin:
path: '/admin/flush/plugin'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushPlugins'
_title: 'Plugin'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar_tools.flush_static:
path: '/admin/flush/static-caches'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushStatic'
_title: 'Static caches'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar_tools.flush_menu:
path: '/admin/flush/menu'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushMenu'
_title: 'Menu'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar_tools.flush_rendercache:
path: '/admin/flush/rendercache'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::cacheRender'
_title: 'Render cache'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar_tools.flush_views:
path: '/admin/flush/views'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushViews'
_title: 'Views'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar_tools.flush_twig:
path: '/admin/flush/twig'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::flushTwig'
_title: 'Twig'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar_tools.theme_rebuild:
path: '/admin/flush/theme_rebuild'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::themeRebuild'
_title: 'Theme Rebuild'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar.run.cron:
path: '/run-cron'
defaults:
_controller: '\Drupal\admin_toolbar_tools\Controller\ToolbarController::runCron'
_title: 'Run cron'
requirements:
_permission: 'administer site configuration'
_csrf_token: 'TRUE'
admin_toolbar_tools.settings:
path: '/admin/config/user-interface/admin-toolbar-tools'
defaults:
_form: '\Drupal\admin_toolbar_tools\Form\AdminToolbarToolsSettingsForm'
_title: 'Admin Toolbar Tools settings'
requirements:
_permission: 'administer site configuration'

View File

@@ -0,0 +1,8 @@
services:
admin_toolbar_tools.helper:
class: Drupal\admin_toolbar_tools\AdminToolbarToolsHelper
arguments:
- '@entity_type.manager'
- '@plugin.manager.menu.local_task'
- '@current_route_match'
- '@config.factory'

View File

@@ -0,0 +1,47 @@
.toolbar-icon-admin-toolbar-tools-help {
text-indent: -9999px;
}
.toolbar-icon-9 .toolbar-icon-admin-toolbar-tools-help:before,
.toolbar-icon-10 .toolbar-icon-admin-toolbar-tools-help:before {
box-sizing: content-box;
background-image: url(../misc/icons/ffffff/drupal-9-logo.svg);
padding-bottom: 0;
padding-left: 2px;
padding-right: 2px;
padding-top: 2px;
margin-left: 4px;
}
.toolbar-icon-9 .toolbar-icon-admin-toolbar-tools-help:active:before,
.toolbar-icon-9 .toolbar-icon-admin-toolbar-tools-help.active:before,
.toolbar-icon-10 .toolbar-icon-admin-toolbar-tools-help:active:before,
.toolbar-icon-10 .toolbar-icon-admin-toolbar-tools-help.active:before {
background-image: url(../misc/icons/ffffff/drupal-9-logo.svg);
}
.toolbar-icon-8 .toolbar-icon-admin-toolbar-tools-help:before {
box-sizing: content-box;
background-image: url(../misc/icons/ffffff/drupal-8-logo.svg);
padding-bottom: 0;
padding-left: 4px;
padding-right: 8px;
padding-top: 2px;
}
.toolbar-icon-8 .toolbar-icon-admin-toolbar-tools-help:active:before,
.toolbar-icon-8 .toolbar-icon-admin-toolbar-tools-help.active:before {
background-image: url(../misc/icons/ffffff/drupal-8-logo.svg);
}
.toolbar-oriented .toolbar-bar .local-tasks-toolbar-tab {
float: right;
}
.toolbar-horizontal .local-tasks-toolbar-tab .toolbar-menu {
float: right;
}
.toolbar-bar .toolbar-icon-local-tasks:before {
background-image: url(../misc/icons/bebebe/tasks.svg);
}

View File

@@ -0,0 +1,4 @@
<svg fill="#bebebe" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z"/>
<path d="M0 0h24v24H0V0z" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 434 B

View File

@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" preserveAspectRatio="xMinYMin" viewBox="0 0 611 646"><path fill="#2ba9e0" d="M 161.14248,607.07981 C 135.931,577.51327 120.7662,539.33875 120.7662,497.60876 c 0,-87.01545 66.15644,-158.68624 151.648,-168.60413 -14.59612,-20.95856 -23.31588,-46.40824 -23.31588,-73.72922 0,-71.85792 58.95316,-129.86822 131.7442,-129.86822 6.06592,0 11.94228,0.37426 17.62908,1.12278 C 355.44148,89.85249 312.41136,52.61362 278.48012,12.00641 295.73008,190.15417 114.1316,125.40719 46.8378,289.70733 1.91208,399.73977 42.47792,535.78328 161.14248,607.07981 Z m 143.1178,-351.8044 c 0,41.72999 34.31036,75.41339 76.39268,75.41339 42.08232,0 76.58224,-33.87053 76.58224,-75.41339 0,-41.72999 -34.31036,-75.41339 -76.39268,-75.41339 -42.08232,0 -76.58224,33.6834 -76.58224,75.41339 z m 112.97776,124.81571 c 29.57136,30.50219 47.76912,71.85792 47.76912,117.51764 0,57.82317 -29.19224,108.72253 -73.73884,139.41185 82.4586,-25.07542 150.7002,-86.26693 181.21936,-160.37041 42.27188,-102.54724 2.8434,-179.6448 -63.12348,-249.63142 2.08516,8.98224 3.22252,18.52587 3.22252,28.0695 -0.18956,59.50734 -40.37628,109.47105 -95.34868,125.00284 z m -124.35136,18.90013 c -55.16196,0 -99.89812,44.16268 -99.89812,98.61751 0,54.45483 44.73616,98.61751 99.89812,98.61751 55.16196,0 99.89812,-44.16268 99.89812,-98.61751 0,-54.45483 -44.73616,-98.61751 -99.89812,-98.61751 z" /></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42.15 55.08"><defs><style>.cls-1{fill:#009cde;}</style></defs><title>Risorsa 23</title><g id="Livello_2" data-name="Livello 2"><g id="Livello_1-2" data-name="Livello 1"><path class="cls-1" d="M29.75,11.73C25.87,7.86,22.18,4.16,21.08,0,20,4.16,16.28,7.86,12.4,11.73,6.59,17.54,0,24.12,0,34a21.08,21.08,0,1,0,42.15,0C42.15,24.12,35.56,17.54,29.75,11.73ZM10.84,35.92a14.13,14.13,0,0,0-1.65,2.62.54.54,0,0,1-.36.3H8.65c-.47,0-1-.92-1-.92h0c-.14-.22-.27-.45-.4-.69l-.09-.19C5.94,34.25,7,30.28,7,30.28h0a17.42,17.42,0,0,1,2.52-5.41,31.53,31.53,0,0,1,2.28-3l1,1,4.72,4.82a.54.54,0,0,1,0,.72l-4.93,5.47h0ZM21.32,49.73a7.29,7.29,0,0,1-5.4-12.14c1.54-1.83,3.42-3.63,5.46-6,2.42,2.58,4,4.35,5.55,6.29a3.08,3.08,0,0,1,.32.48,7.15,7.15,0,0,1,1.3,4.12A7.23,7.23,0,0,1,21.32,49.73ZM35,38.14v0a.84.84,0,0,1-.67.58h-.14a1.22,1.22,0,0,1-.68-.55h0a37.77,37.77,0,0,0-4.28-5.31l-1.93-2-6.41-6.65a54,54,0,0,1-3.84-3.94,1.3,1.3,0,0,0-.1-.15,3.84,3.84,0,0,1-.51-1c0-.06,0-.13,0-.19a3.4,3.4,0,0,1,1-3c1.24-1.24,2.49-2.49,3.67-3.79,1.3,1.44,2.69,2.82,4.06,4.19v0a57.6,57.6,0,0,1,7.55,8.58A16,16,0,0,1,35.65,34,14.55,14.55,0,0,1,35,38.14Z"/></g></g></svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1,174 @@
<?php
namespace Drupal\admin_toolbar_tools;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Menu\LocalTaskManagerInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
/**
* Admin Toolbar Tools helper service.
*/
class AdminToolbarToolsHelper {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The local task manger.
*
* @var \Drupal\Core\Menu\LocalTaskManagerInterface
* The local task manager menu.
*/
protected $localTaskManager;
/**
* The route match interface.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
* The route match.
*/
protected $routeMatch;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Create an AdminToolbarToolsHelper object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Menu\LocalTaskManagerInterface $local_task_manager
* The local task manager.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, LocalTaskManagerInterface $local_task_manager, RouteMatchInterface $route_match, ConfigFactoryInterface $config_factory) {
$this->entityTypeManager = $entity_type_manager;
$this->localTaskManager = $local_task_manager;
$this->routeMatch = $route_match;
$this->configFactory = $config_factory;
}
/**
* Generate the toolbar tab and item for primary local tasks.
*
* @return array
* The toolbar render array.
*/
public function buildLocalTasksToolbar() {
$build = [];
$config = $this->configFactory->get('admin_toolbar_tools.settings');
$cacheability = CacheableMetadata::createFromObject($config);
if ($config->get('show_local_tasks')) {
$local_tasks = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName());
$cacheability = $cacheability->merge($local_tasks['cacheability']);
$cacheability = $cacheability->merge(CacheableMetadata::createFromObject($this->localTaskManager));
if (!empty($local_tasks['tabs'])) {
$local_task_links = [
'#theme' => 'links',
'#links' => [],
'#attributes' => [
'class' => ['toolbar-menu'],
],
];
// Sort the links by weight.
Element::children($local_tasks['tabs'], TRUE);
// Only show the accessible local tasks.
foreach (Element::getVisibleChildren($local_tasks['tabs']) as $task) {
$local_task_links['#links'][$task] = $local_tasks['tabs'][$task]['#link'];
if ($local_tasks['tabs'][$task]['#active']) {
$local_task_links['#links'][$task]['attributes']['class'][] = 'is-active';
}
}
$build = [
'#type' => 'toolbar_item',
'#wrapper_attributes' => [
'class' => ['local-tasks-toolbar-tab'],
],
// Put it after contextual toolbar item so when float right is applied
// local tasks item will be first.
'#weight' => 10,
'tab' => [
// We can't use #lazy_builder here because
// ToolbarItem::preRenderToolbarItem will insert #attributes before
// lazy_builder callback and this will produce Exception.
// This means that for now we always render Local Tasks item even
// when the tray is empty.
'#type' => 'link',
'#title' => $this->t('Local Tasks'),
'#url' => Url::fromRoute('<none>'),
'#attributes' => [
'class' => [
'toolbar-icon',
'toolbar-icon-local-tasks',
],
],
],
'tray' => [
'local_tasks' => $local_task_links,
],
'#attached' => ['library' => ['admin_toolbar_tools/toolbar.icon']],
];
}
}
$cacheability->applyTo($build);
return $build;
}
/**
* Gets a list of content entities.
*
* @return array
* An array of metadata about content entities.
*/
public function getBundleableEntitiesList() {
$entity_types = $this->entityTypeManager->getDefinitions();
$content_entities = [];
foreach ($entity_types as $key => $entity_type) {
if ($entity_type->getBundleEntityType() && ($entity_type->get('field_ui_base_route') != '')) {
$content_entities[$key] = [
'content_entity' => $key,
'content_entity_bundle' => $entity_type->getBundleEntityType(),
];
}
}
return $content_entities;
}
/**
* Gets 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;
}
}

View File

@@ -0,0 +1,295 @@
<?php
namespace Drupal\admin_toolbar_tools\Controller;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\CronInterface;
use Drupal\Core\Menu\ContextualLinkManager;
use Drupal\Core\Menu\LocalActionManager;
use Drupal\Core\Menu\LocalTaskManager;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Core\Plugin\CachedDiscoveryClearerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\Template\TwigEnvironment;
use Drupal\Core\Theme\Registry;
/**
* Controller for AdminToolbar Tools.
*
* @package Drupal\admin_toolbar_tools\Controller
*/
class ToolbarController extends ControllerBase {
/**
* A cron instance.
*
* @var \Drupal\Core\CronInterface
*/
protected $cron;
/**
* A menu link manager instance.
*
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* A context link manager instance.
*
* @var \Drupal\Core\Menu\ContextualLinkManager
*/
protected $contextualLinkManager;
/**
* A local task manager instance.
*
* @var \Drupal\Core\Menu\LocalTaskManager
*/
protected $localTaskLinkManager;
/**
* A local action manager instance.
*
* @var \Drupal\Core\Menu\LocalActionManager
*/
protected $localActionLinkManager;
/**
* A cache backend interface instance.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheRender;
/**
* A date time instance.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* A request stack symfony instance.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* A plugin cache clear instance.
*
* @var \Drupal\Core\Plugin\CachedDiscoveryClearerInterface
*/
protected $pluginCacheClearer;
/**
* The cache menu instance.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheMenu;
/**
* A TwigEnvironment instance.
*
* @var \Drupal\Core\Template\TwigEnvironment
*/
protected $twig;
/**
* The search theme.registry service.
*
* @var \Drupal\Core\Theme\Registry
*/
protected $themeRegistry;
/**
* Constructs a ToolbarController object.
*
* @param \Drupal\Core\CronInterface $cron
* A cron instance.
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menuLinkManager
* A menu link manager instance.
* @param \Drupal\Core\Menu\ContextualLinkManager $contextualLinkManager
* A context link manager instance.
* @param \Drupal\Core\Menu\LocalTaskManager $localTaskLinkManager
* A local task manager instance.
* @param \Drupal\Core\Menu\LocalActionManager $localActionLinkManager
* A local action manager instance.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheRender
* A cache backend interface instance.
* @param \Drupal\Component\Datetime\TimeInterface $time
* A date time instance.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* A request stack symfony instance.
* @param \Drupal\Core\Plugin\CachedDiscoveryClearerInterface $plugin_cache_clearer
* A plugin cache clear instance.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_menu
* A cache menu instance.
* @param \Drupal\Core\Template\TwigEnvironment $twig
* A TwigEnvironment instance.
* @param \Drupal\Core\Theme\Registry $theme_registry
* The theme.registry service.
*/
public function __construct(
CronInterface $cron,
MenuLinkManagerInterface $menuLinkManager,
ContextualLinkManager $contextualLinkManager,
LocalTaskManager $localTaskLinkManager,
LocalActionManager $localActionLinkManager,
CacheBackendInterface $cacheRender,
TimeInterface $time,
RequestStack $request_stack,
CachedDiscoveryClearerInterface $plugin_cache_clearer,
CacheBackendInterface $cache_menu,
TwigEnvironment $twig,
Registry $theme_registry
) {
$this->cron = $cron;
$this->menuLinkManager = $menuLinkManager;
$this->contextualLinkManager = $contextualLinkManager;
$this->localTaskLinkManager = $localTaskLinkManager;
$this->localActionLinkManager = $localActionLinkManager;
$this->cacheRender = $cacheRender;
$this->time = $time;
$this->requestStack = $request_stack;
$this->pluginCacheClearer = $plugin_cache_clearer;
$this->cacheMenu = $cache_menu;
$this->twig = $twig;
$this->themeRegistry = $theme_registry;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('cron'),
$container->get('plugin.manager.menu.link'),
$container->get('plugin.manager.menu.contextual_link'),
$container->get('plugin.manager.menu.local_task'),
$container->get('plugin.manager.menu.local_action'),
$container->get('cache.render'),
$container->get('datetime.time'),
$container->get('request_stack'),
$container->get('plugin.cache_clearer'),
$container->get('cache.menu'),
$container->get('twig'),
$container->get('theme.registry')
);
}
/**
* Reload the previous page.
*/
public function reloadPage() {
$request = $this->requestStack->getCurrentRequest();
if ($request->server->get('HTTP_REFERER')) {
return $request->server->get('HTTP_REFERER');
}
else {
return base_path();
}
}
/**
* Flushes all caches.
*/
public function flushAll() {
$this->messenger()->addMessage($this->t('All caches cleared.'));
drupal_flush_all_caches();
return new RedirectResponse($this->reloadPage());
}
/**
* Flushes css and javascript caches.
*/
public function flushJsCss() {
$this->state()
->set('system.css_js_query_string', base_convert($this->time->getCurrentTime(), 10, 36));
$this->messenger()->addMessage($this->t('CSS and JavaScript cache cleared.'));
return new RedirectResponse($this->reloadPage());
}
/**
* Flushes plugins caches.
*/
public function flushPlugins() {
$this->pluginCacheClearer->clearCachedDefinitions();
$this->messenger()->addMessage($this->t('Plugins cache cleared.'));
return new RedirectResponse($this->reloadPage());
}
/**
* Resets all static caches.
*/
public function flushStatic() {
drupal_static_reset();
$this->messenger()->addMessage($this->t('Static cache cleared.'));
return new RedirectResponse($this->reloadPage());
}
/**
* Clears all cached menu data.
*/
public function flushMenu() {
$this->cacheMenu->invalidateAll();
$this->menuLinkManager->rebuild();
$this->contextualLinkManager->clearCachedDefinitions();
$this->localTaskLinkManager->clearCachedDefinitions();
$this->localActionLinkManager->clearCachedDefinitions();
$this->messenger()->addMessage($this->t('Routing and links cache cleared.'));
return new RedirectResponse($this->reloadPage());
}
/**
* Clears all cached views data.
*/
public function flushViews() {
views_invalidate_cache();
$this->messenger()->addMessage($this->t('Views cache cleared.'));
return new RedirectResponse($this->reloadPage());
}
/**
* Clears the twig cache.
*/
public function flushTwig() {
$this->twig->invalidate();
$this->messenger()->addMessage($this->t('Twig cache cleared.'));
return new RedirectResponse($this->reloadPage());
}
/**
* Run the cron.
*/
public function runCron() {
$this->cron->run();
$this->messenger()->addMessage($this->t('Cron ran successfully.'));
return new RedirectResponse($this->reloadPage());
}
/**
* Clear the rendered cache.
*/
public function cacheRender() {
$this->cacheRender->invalidateAll();
$this->messenger()->addMessage($this->t('Render cache cleared.'));
return new RedirectResponse($this->reloadPage());
}
/**
* Rebuild the theme registry.
*/
public function themeRebuild() {
$this->themeRegistry->reset();
$this->messenger()->addMessage($this->t('Theme registry rebuilt.'));
return new RedirectResponse($this->reloadPage());
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace Drupal\admin_toolbar_tools\Form;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Settings form for AdminToolbar Tools.
*
* @package Drupal\admin_toolbar_tools\Form
*/
class AdminToolbarToolsSettingsForm extends ConfigFormBase {
/**
* The cache menu instance.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheMenu;
/**
* The menu link manager instance.
*
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* AdminToolbarToolsSettingsForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The factory for configuration objects.
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menuLinkManager
* A menu link manager instance.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheMenu
* A cache menu instance.
*/
public function __construct(ConfigFactoryInterface $configFactory, MenuLinkManagerInterface $menuLinkManager, CacheBackendInterface $cacheMenu) {
parent::__construct($configFactory);
$this->cacheMenu = $cacheMenu;
$this->menuLinkManager = $menuLinkManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('plugin.manager.menu.link'),
$container->get('cache.menu')
);
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'admin_toolbar_tools.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'admin_toolbar_tools_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('admin_toolbar_tools.settings');
$form['max_bundle_number'] = [
'#type' => 'number',
'#title' => $this->t('Maximum number of bundle sub-menus to display'),
'#description' => $this->t('Loading a large number of items can cause performance issues.'),
'#default_value' => $config->get('max_bundle_number'),
];
$form['hoverintent_functionality'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable/Disable the hoverintent functionality'),
'#description' => $this->t('Check it if you want to enable the hoverintent feature.'),
'#default_value' => $config->get('hoverintent_functionality'),
];
$form['show_local_tasks'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable/Disable local tasks display'),
'#description' => $this->t('Local tasks such as node edit and delete.'),
'#default_value' => $config->get('show_local_tasks'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('admin_toolbar_tools.settings')
->set('max_bundle_number', $form_state->getValue('max_bundle_number'))
->set('hoverintent_functionality', $form_state->getValue('hoverintent_functionality'))
->set('show_local_tasks', $form_state->getValue('show_local_tasks'))
->save();
parent::submitForm($form, $form_state);
$this->cacheMenu->invalidateAll();
$this->menuLinkManager->rebuild();
}
}

View File

@@ -0,0 +1,723 @@
<?php
namespace Drupal\admin_toolbar_tools\Plugin\Derivative;
use Drupal\system\Entity\Menu;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a default implementation for menu link plugins.
*/
class ExtraLinks extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected $routeProvider;
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* The admin toolbar tools configuration.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* {@inheritdoc}
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, RouteProviderInterface $route_provider, ThemeHandlerInterface $theme_handler, ConfigFactoryInterface $config_factory, AccountInterface $current_user) {
$this->entityTypeManager = $entity_type_manager;
$this->moduleHandler = $module_handler;
$this->routeProvider = $route_provider;
$this->themeHandler = $theme_handler;
$this->config = $config_factory->get('admin_toolbar_tools.settings');
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$container->get('entity_type.manager'),
$container->get('module_handler'),
$container->get('router.route_provider'),
$container->get('theme_handler'),
$container->get('config.factory'),
$container->get('current_user')
);
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$links = [];
$max_bundle_number = $this->config->get('max_bundle_number');
$entity_types = $this->entityTypeManager->getDefinitions();
$content_entities = [];
foreach ($entity_types as $key => $entity_type) {
if ($entity_type->getBundleEntityType() && ($entity_type->get('field_ui_base_route') != '')) {
$content_entities[$key] = [
'content_entity' => $key,
'content_entity_bundle' => $entity_type->getBundleEntityType(),
];
}
}
// Adds common links to entities.
foreach ($content_entities as $entities) {
$content_entity_bundle = $entities['content_entity_bundle'];
$content_entity = $entities['content_entity'];
$content_entity_bundle_storage = $this->entityTypeManager->getStorage($content_entity_bundle);
$bundles_ids = $content_entity_bundle_storage->getQuery()->sort('weight')->pager($max_bundle_number)->execute();
$bundles = $this->entityTypeManager->getStorage($content_entity_bundle)->loadMultiple($bundles_ids);
if (count($bundles) == $max_bundle_number && $this->routeExists('entity.' . $content_entity_bundle . '.collection')) {
$links[$content_entity_bundle . '.collection'] = [
'title' => $this->t('All types'),
'route_name' => 'entity.' . $content_entity_bundle . '.collection',
'parent' => 'entity.' . $content_entity_bundle . '.collection',
'weight' => -999,
] + $base_plugin_definition;
}
foreach ($bundles as $machine_name => $bundle) {
// Normally, the edit form for the bundle would be its root link.
$content_entity_bundle_root = NULL;
if ($this->routeExists('entity.' . $content_entity_bundle . '.overview_form')) {
// Some bundles have an overview/list form that make a better root
// link.
$content_entity_bundle_root = 'entity.' . $content_entity_bundle . '.overview_form.' . $machine_name;
$links[$content_entity_bundle_root] = [
'route_name' => 'entity.' . $content_entity_bundle . '.overview_form',
'parent' => 'entity.' . $content_entity_bundle . '.collection',
'route_parameters' => [$content_entity_bundle => $machine_name],
'class' => 'Drupal\admin_toolbar_tools\Plugin\Menu\MenuLinkEntity',
'metadata' => [
'entity_type' => $bundle->getEntityTypeId(),
'entity_id' => $bundle->id(),
],
] + $base_plugin_definition;
$weight = $bundles[$machine_name]->get('weight');
if (isset($weight) && is_numeric($weight)) {
$links[$content_entity_bundle_root]['weight'] = $weight;
}
}
if ($this->routeExists('entity.' . $content_entity_bundle . '.edit_form')) {
$key = 'entity.' . $content_entity_bundle . '.edit_form.' . $machine_name;
$links[$key] = [
'route_name' => 'entity.' . $content_entity_bundle . '.edit_form',
'parent' => 'entity.' . $content_entity_bundle . '.collection',
'route_parameters' => [$content_entity_bundle => $machine_name],
] + $base_plugin_definition;
if (empty($content_entity_bundle_root)) {
$content_entity_bundle_root = $key;
$links[$key]['parent'] = 'entity.' . $content_entity_bundle . '.collection';
// When not grouped by bundle, use bundle name as title.
$links[$key]['class'] = 'Drupal\admin_toolbar_tools\Plugin\Menu\MenuLinkEntity';
$links[$key]['metadata'] = [
'entity_type' => $bundle->getEntityTypeId(),
'entity_id' => $bundle->id(),
];
}
else {
$links[$key]['parent'] = $base_plugin_definition['id'] . ':' . $content_entity_bundle_root;
$links[$key]['title'] = $this->t('Edit');
}
}
if ($this->moduleHandler->moduleExists('field_ui')) {
if ($this->routeExists('entity.' . $content_entity . '.field_ui_fields')) {
$links['entity.' . $content_entity . '.field_ui_fields' . $machine_name] = [
'title' => $this->t('Manage fields'),
'route_name' => 'entity.' . $content_entity . '.field_ui_fields',
'parent' => $base_plugin_definition['id'] . ':' . $content_entity_bundle_root,
'route_parameters' => [$content_entity_bundle => $machine_name],
'weight' => 1,
] + $base_plugin_definition;
}
if ($this->routeExists('entity.entity_form_display.' . $content_entity . '.default')) {
$links['entity.entity_form_display.' . $content_entity . '.default' . $machine_name] = [
'title' => $this->t('Manage form display'),
'route_name' => 'entity.entity_form_display.' . $content_entity . '.default',
'parent' => $base_plugin_definition['id'] . ':' . $content_entity_bundle_root,
'route_parameters' => [$content_entity_bundle => $machine_name],
'weight' => 2,
] + $base_plugin_definition;
}
if ($this->routeExists('entity.entity_view_display.' . $content_entity . '.default')) {
$links['entity.entity_view_display.' . $content_entity . '.default.' . $machine_name] = [
'title' => $this->t('Manage display'),
'route_name' => 'entity.entity_view_display.' . $content_entity . '.default',
'parent' => $base_plugin_definition['id'] . ':' . $content_entity_bundle_root,
'route_parameters' => [$content_entity_bundle => $machine_name],
'weight' => 3,
] + $base_plugin_definition;
}
if ($this->routeExists('entity.' . $bundle->getEntityTypeId() . '.entity_permissions_form')) {
$links['entity.entity_permissions_form.' . $content_entity . '.default.' . $machine_name] = [
'title' => $this->t('Manage permissions'),
'route_name' => 'entity.' . $bundle->getEntityTypeId() . '.entity_permissions_form',
'parent' => $base_plugin_definition['id'] . ':' . $content_entity_bundle_root,
'route_parameters' => [
$bundle->getEntityTypeId() => $machine_name,
],
'weight' => 3,
] + $base_plugin_definition;
}
}
if ($this->moduleHandler->moduleExists('devel') && $this->routeExists('entity.' . $content_entity_bundle . '.devel_load')) {
$links['entity.' . $content_entity_bundle . '.devel_load.' . $machine_name] = [
'title' => $this->t('Devel'),
'route_name' => 'entity.' . $content_entity_bundle . '.devel_load',
'parent' => $base_plugin_definition['id'] . ':' . $content_entity_bundle_root,
'route_parameters' => [$content_entity_bundle => $machine_name],
'weight' => 4,
] + $base_plugin_definition;
}
if ($this->routeExists('entity.' . $content_entity_bundle . '.delete_form')) {
$links['entity.' . $content_entity_bundle . '.delete_form.' . $machine_name] = [
'title' => $this->t('Delete'),
'route_name' => 'entity.' . $content_entity_bundle . '.delete_form',
'parent' => $base_plugin_definition['id'] . ':' . $content_entity_bundle_root,
'route_parameters' => [$content_entity_bundle => $machine_name],
'weight' => 5,
] + $base_plugin_definition;
}
}
}
// Adds user links.
$links['user.admin_create'] = [
'title' => $this->t('Add user'),
'route_name' => 'user.admin_create',
'parent' => 'entity.user.collection',
] + $base_plugin_definition;
$links['user.admin_permissions'] = [
'title' => $this->t('Permissions'),
'route_name' => 'user.admin_permissions',
'parent' => 'entity.user.collection',
] + $base_plugin_definition;
$links['entity.user_role.collection'] = [
'title' => $this->t('Roles'),
'route_name' => 'entity.user_role.collection',
'parent' => 'entity.user.collection',
] + $base_plugin_definition;
$links['user.logout'] = [
'title' => $this->t('Logout'),
'route_name' => 'user.logout',
'parent' => 'admin_toolbar_tools.help',
'weight' => 10,
] + $base_plugin_definition;
$links['user.role_add'] = [
'title' => $this->t('Add role'),
'route_name' => 'user.role_add',
'parent' => $base_plugin_definition['id'] . ':entity.user_role.collection',
'weight' => -50,
] + $base_plugin_definition;
// Adds sub-links to Account settings link.
if ($this->moduleHandler->moduleExists('field_ui')) {
$links['entity.user.field_ui_fields_'] = [
'title' => $this->t('Manage fields'),
'route_name' => 'entity.user.field_ui_fields',
'parent' => 'entity.user.admin_form',
'weight' => 1,
] + $base_plugin_definition;
$links['entity.entity_form_display.user.default_'] = [
'title' => $this->t('Manage form display'),
'route_name' => 'entity.entity_form_display.user.default',
'parent' => 'entity.user.admin_form',
'weight' => 2,
] + $base_plugin_definition;
$links['entity.entity_view_display.user.default_'] = [
'title' => $this->t('Manage display'),
'route_name' => 'entity.entity_view_display.user.default',
'parent' => 'entity.user.admin_form',
'weight' => 3,
] + $base_plugin_definition;
}
foreach ($this->entityTypeManager->getStorage('user_role')->loadMultiple() as $role) {
$links['entity.user_role.edit_form.' . $role->id()] = [
'route_name' => 'entity.user_role.edit_form',
'parent' => $base_plugin_definition['id'] . ':entity.user_role.collection',
'weight' => $role->getWeight(),
'route_parameters' => ['user_role' => $role->id()],
'class' => 'Drupal\admin_toolbar_tools\Plugin\Menu\MenuLinkEntity',
'metadata' => [
'entity_type' => $role->getEntityTypeId(),
'entity_id' => $role->id(),
],
] + $base_plugin_definition;
$links['entity.user_role.edit_permissions_form.' . $role->id()] = [
'title' => $this->t('Edit permissions'),
'route_name' => 'entity.user_role.edit_permissions_form',
'parent' => $base_plugin_definition['id'] . ':entity.user_role.edit_form.' . $role->id(),
'route_parameters' => ['user_role' => $role->id()],
] + $base_plugin_definition;
if ($role->id() != 'anonymous' && $role->id() != 'authenticated') {
$links['entity.user_role.delete_form.' . $role->id()] = [
'title' => $this->t('Delete'),
'route_name' => 'entity.user_role.delete_form',
'parent' => $base_plugin_definition['id'] . ':entity.user_role.edit_form.' . $role->id(),
'route_parameters' => ['user_role' => $role->id()],
] + $base_plugin_definition;
}
if ($this->moduleHandler->moduleExists('devel')) {
$links['entity.user_role.devel_load.' . $role->id()] = [
'title' => $this->t('Devel'),
'route_name' => 'entity.user_role.devel_load',
'parent' => $base_plugin_definition['id'] . ':entity.user_role.edit_form.' . $role->id(),
'route_parameters' => ['user_role' => $role->id()],
] + $base_plugin_definition;
}
}
if ($this->moduleHandler->moduleExists('node')) {
$links['node.type_add'] = [
'title' => $this->t('Add content type'),
'route_name' => 'node.type_add',
'parent' => 'entity.node_type.collection',
'weight' => -2,
] + $base_plugin_definition;
$links['node.add'] = [
'title' => $this->t('Add content'),
'route_name' => 'node.add_page',
'parent' => 'system.admin_content',
] + $base_plugin_definition;
// Adds node links for each content type.
foreach ($this->entityTypeManager->getStorage('node_type')->loadMultiple() as $type) {
$links['node.add.' . $type->id()] = [
'route_name' => 'node.add',
'parent' => $base_plugin_definition['id'] . ':node.add',
'route_parameters' => ['node_type' => $type->id()],
'class' => 'Drupal\admin_toolbar_tools\Plugin\Menu\MenuLinkEntity',
'metadata' => [
'entity_type' => $type->getEntityTypeId(),
'entity_id' => $type->id(),
],
] + $base_plugin_definition;
}
}
if ($this->moduleHandler->moduleExists('field_ui')) {
$links['field_ui.entity_form_mode_add'] = [
'title' => $this->t('Add form mode'),
'route_name' => 'field_ui.entity_form_mode_add',
'parent' => 'entity.entity_form_mode.collection',
] + $base_plugin_definition;
$links['field_ui.entity_view_mode_add'] = [
'title' => $this->t('Add view mode'),
'route_name' => 'field_ui.entity_view_mode_add',
'parent' => 'entity.entity_view_mode.collection',
] + $base_plugin_definition;
}
if ($this->moduleHandler->moduleExists('taxonomy')) {
$links['entity.taxonomy_vocabulary.add_form'] = [
'title' => $this->t('Add vocabulary'),
'route_name' => 'entity.taxonomy_vocabulary.add_form',
'parent' => 'entity.taxonomy_vocabulary.collection',
'weight' => -998,
] + $base_plugin_definition;
}
if ($this->moduleHandler->moduleExists('menu_ui')) {
$links['entity.menu.add_form'] = [
'title' => $this->t('Add menu'),
'route_name' => 'entity.menu.add_form',
'parent' => 'entity.menu.collection',
'weight' => -2,
] + $base_plugin_definition;
// Adds links to /admin/structure/menu.
$menus = $this->entityTypeManager->getStorage('menu')->loadMultiple();
uasort($menus, [Menu::class, 'sort']);
$menus = array_slice($menus, 0, $max_bundle_number);
if (count($menus) == $max_bundle_number) {
$links['entity.menu.collection'] = [
'title' => $this->t('All menus'),
'route_name' => 'entity.menu.collection',
'parent' => 'entity.menu.collection',
'weight' => -1,
] + $base_plugin_definition;
}
$weight = 0;
foreach ($menus as $menu_id => $menu) {
$links['entity.menu.edit_form.' . $menu_id] = [
'route_name' => 'entity.menu.edit_form',
'parent' => 'entity.menu.collection',
'route_parameters' => ['menu' => $menu_id],
'weight' => $weight,
'class' => 'Drupal\admin_toolbar_tools\Plugin\Menu\MenuLinkEntity',
'metadata' => [
'entity_type' => $menu->getEntityTypeId(),
'entity_id' => $menu->id(),
],
] + $base_plugin_definition;
$links['entity.menu.add_link_form.' . $menu_id] = [
'title' => $this->t('Add link'),
'route_name' => 'entity.menu.add_link_form',
'parent' => $base_plugin_definition['id'] . ':entity.menu.edit_form.' . $menu_id,
'route_parameters' => ['menu' => $menu_id],
] + $base_plugin_definition;
// Un-deletable menus.
$un_deletable_menus = [
'admin',
'devel',
'footer',
'main',
'tools',
'account',
];
if (!in_array($menu_id, $un_deletable_menus)) {
$links['entity.menu.delete_form.' . $menu_id] = [
'title' => $this->t('Delete'),
'route_name' => 'entity.menu.delete_form',
'parent' => $base_plugin_definition['id'] . ':entity.menu.edit_form.' . $menu_id,
'route_parameters' => ['menu' => $menu_id],
] + $base_plugin_definition;
}
if ($this->moduleHandler->moduleExists('devel') && $this->routeExists('entity.menu.devel_load')) {
$links['entity.menu.devel_load.' . $menu_id] = [
'title' => $this->t('Devel'),
'route_name' => 'entity.menu.devel_load',
'parent' => $base_plugin_definition['id'] . ':entity.menu.edit_form.' . $menu_id,
'route_parameters' => ['menu' => $menu_id],
] + $base_plugin_definition;
}
$weight++;
}
}
// If module block_content is enabled.
if ($this->moduleHandler->moduleExists('block_content')) {
$links['block_content.add_page'] = [
'title' => $this->t('Add custom block'),
'route_name' => 'block_content.add_page',
'parent' => 'block.admin_display',
] + $base_plugin_definition;
$links['entity.block_content.collection'] = [
'title' => $this->t('Custom block library'),
'route_name' => 'entity.block_content.collection',
'parent' => 'block.admin_display',
] + $base_plugin_definition;
$links['entity.block_content_type.collection'] = [
'title' => $this->t('Block types'),
'route_name' => 'entity.block_content_type.collection',
'parent' => 'block.admin_display',
] + $base_plugin_definition;
}
// If module Contact is enabled.
if ($this->moduleHandler->moduleExists('contact')) {
$links['contact.form_add'] = [
'title' => $this->t('Add contact form'),
'route_name' => 'contact.form_add',
'parent' => 'entity.contact_form.collection',
'weight' => -5,
] + $base_plugin_definition;
}
// If module Update Manager is enabled.
if ($this->moduleHandler->moduleExists('update')) {
$links['update.module_install'] = [
'title' => $this->t('Install new module'),
'route_name' => 'update.module_install',
'parent' => 'system.modules_list',
] + $base_plugin_definition;
$links['update.module_update'] = [
'title' => $this->t('Update'),
'route_name' => 'update.module_update',
'parent' => 'system.modules_list',
] + $base_plugin_definition;
$links['update.theme_install'] = [
'title' => $this->t('Install new theme'),
'route_name' => 'update.theme_install',
'parent' => 'system.themes_page',
] + $base_plugin_definition;
$links['update.theme_update'] = [
'title' => $this->t('Update'),
'route_name' => 'update.theme_update',
'parent' => 'system.themes_page',
] + $base_plugin_definition;
}
// If module Devel is enabled.
if ($this->moduleHandler->moduleExists('devel')) {
$links['devel'] = [
'title' => $this->t('Development'),
'route_name' => 'system.admin_config_development',
'parent' => 'admin_toolbar_tools.help',
'weight' => '-8',
] + $base_plugin_definition;
$links['devel.admin_settings'] = [
'title' => $this->t('Devel settings'),
'route_name' => 'devel.admin_settings',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
$links['devel.configs_list'] = [
'title' => $this->t('Config editor'),
'route_name' => 'devel.configs_list',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
$links['devel.reinstall'] = [
'title' => $this->t('Reinstall modules'),
'route_name' => 'devel.reinstall',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
$links['devel.menu_rebuild'] = [
'title' => $this->t('Rebuild menu'),
'route_name' => 'devel.menu_rebuild',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
$links['devel.state_system_page'] = [
'title' => $this->t('State editor'),
'route_name' => 'devel.state_system_page',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
$links['devel.theme_registry'] = [
'title' => $this->t('Theme registry'),
'route_name' => 'devel.theme_registry',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
$links['devel.entity_info_page'] = [
'title' => $this->t('Entity info'),
'route_name' => 'devel.entity_info_page',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
$links['devel.session'] = [
'title' => $this->t('Session viewer'),
'route_name' => 'devel.session',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
$links['devel.element_info'] = [
'title' => $this->t('Element Info'),
'route_name' => 'devel.elements_page',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
// Menu link for the Toolbar module.
$links['devel.toolbar.settings'] = [
'title' => $this->t('Devel Toolbar Settings'),
'route_name' => 'devel.toolbar.settings_form',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
if ($this->moduleHandler->moduleExists('webprofiler')) {
$links['devel.webprofiler'] = [
'title' => $this->t('Webprofiler settings'),
'route_name' => 'webprofiler.settings',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
}
// If module Devel PHP is enabled.
if ($this->moduleHandler->moduleExists('devel_php') && $this->routeExists('devel_php.execute_php')) {
$links['devel.devel_php.execute_php'] = [
'title' => $this->t('Execute PHP Code'),
'route_name' => 'devel_php.execute_php',
'parent' => $base_plugin_definition['id'] . ':devel',
] + $base_plugin_definition;
}
}
// If module Views Ui enabled.
if ($this->moduleHandler->moduleExists('views_ui')) {
$links['views_ui.add'] = [
'title' => $this->t('Add view'),
'route_name' => 'views_ui.add',
'parent' => 'entity.view.collection',
'weight' => -5,
] + $base_plugin_definition;
$views = $this->entityTypeManager->getStorage('view')->loadMultiple();
foreach ($views as $view) {
$links['views_ui.' . $view->id()] = [
'title' => $view->label(),
'route_name' => 'entity.view.edit_form',
'route_parameters' => ['view' => $view->id()],
'parent' => 'entity.view.collection',
] + $base_plugin_definition;
}
$links['views_ui.field_list'] = [
'title' => $this->t('Used in views'),
'route_name' => 'views_ui.reports_fields',
'parent' => 'entity.field_storage_config.collection',
] + $base_plugin_definition;
}
// Adds theme management links.
$links['system.theme_settings'] = [
'title' => $this->t('Settings'),
'route_name' => 'system.theme_settings',
'parent' => 'system.themes_page',
] + $base_plugin_definition;
$installed_themes = $this->installedThemes();
foreach ($installed_themes as $key_theme => $label_theme) {
$links['system.theme_settings_theme.' . $key_theme] = [
'title' => $label_theme,
'route_name' => 'system.theme_settings_theme',
'parent' => $base_plugin_definition['id'] . ':system.theme_settings',
'route_parameters' => ['theme' => $key_theme],
] + $base_plugin_definition;
}
// If module Language enabled.
if ($this->moduleHandler->moduleExists('language')) {
$links['language.negotiation'] = [
'title' => $this->t('Detection and selection'),
'route_name' => 'language.negotiation',
'parent' => 'entity.configurable_language.collection',
] + $base_plugin_definition;
$links['language.add'] = [
'title' => $this->t('Add language'),
'route_name' => 'language.add',
'parent' => 'entity.configurable_language.collection',
] + $base_plugin_definition;
}
// If module Media enabled.
if ($this->moduleHandler->moduleExists('media')) {
$links['media.type_add'] = [
'title' => $this->t('Add media type'),
'route_name' => 'entity.media_type.add_form',
'parent' => 'entity.media_type.collection',
'weight' => -2,
] + $base_plugin_definition;
// Displays media link in toolbar.
$links['media_page'] = [
'title' => $this->t('Media'),
'route_name' => 'entity.media.collection',
'parent' => 'system.admin_content',
] + $base_plugin_definition;
if ($this->moduleHandler->moduleExists('media_library') && $this->routeExists('view.media_library.page')) {
$links['media_library'] = [
'title' => $this->t('Media library'),
'route_name' => 'view.media_library.page',
'parent' => $base_plugin_definition['id'] . ':media_page',
] + $base_plugin_definition;
}
$links['add_media'] = [
'title' => $this->t('Add media'),
'route_name' => 'entity.media.add_page',
'parent' => $base_plugin_definition['id'] . ':media_page',
] + $base_plugin_definition;
// Adds links for each media type.
foreach ($this->entityTypeManager->getStorage('media_type')->loadMultiple() as $type) {
$links['media.add.' . $type->id()] = [
'route_name' => 'entity.media.add_form',
'parent' => $base_plugin_definition['id'] . ':add_media',
'route_parameters' => ['media_type' => $type->id()],
'class' => 'Drupal\admin_toolbar_tools\Plugin\Menu\MenuLinkEntity',
'metadata' => [
'entity_type' => $type->getEntityTypeId(),
'entity_id' => $type->id(),
],
] + $base_plugin_definition;
}
}
// If module Config enabled.
if ($this->moduleHandler->moduleExists('config')) {
$links['config.import'] = [
'title' => $this->t('Import'),
'route_name' => 'config.import_full',
'parent' => 'config.sync',
'weight' => 1,
] + $base_plugin_definition;
$links['config.export'] = [
'title' => $this->t('Export'),
'route_name' => 'config.export_full',
'parent' => 'config.sync',
'weight' => 2,
] + $base_plugin_definition;
}
// Adds a menu link to clear Views cache.
if ($this->moduleHandler->moduleExists('views')) {
$links['flush_views'] = [
'title' => $this->t('Flush views cache'),
'route_name' => 'admin_toolbar_tools.flush_views',
'parent' => 'admin_toolbar_tools.flush',
] + $base_plugin_definition;
// Adding a menu link to Files.
if ($this->moduleHandler->moduleExists('file') && $this->routeExists('view.files.page_1')) {
$links['view.files'] = [
'title' => $this->t('Files'),
'route_name' => 'view.files.page_1',
'parent' => 'system.admin_content',
] + $base_plugin_definition;
}
}
return $links;
}
/**
* Determine if a route exists by name.
*
* @param string $route_name
* The name of the route to check.
*
* @return bool
* Whether a route with that route name exists.
*/
public function routeExists($route_name) {
return (count($this->routeProvider->getRoutesByNames([$route_name])) === 1);
}
/**
* Lists all installed themes.
*
* @return array
* The list of installed themes.
*/
public function installedThemes() {
$themeHandler = $this->themeHandler;
$all_themes = $themeHandler->listInfo();
$themes_installed = [];
foreach ($all_themes as $key_theme => $theme) {
if ($themeHandler->hasUi($key_theme)) {
$themes_installed[$key_theme] = $themeHandler->getName($key_theme);
}
}
return $themes_installed;
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace Drupal\admin_toolbar_tools\Plugin\Menu;
use Drupal\Core\Entity\EntityDescriptionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Menu\MenuLinkDefault;
use Drupal\Core\Menu\StaticMenuLinkOverridesInterface;
use Drupal\node\NodeTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a menu link plugins for configuration entities.
*/
class MenuLinkEntity extends MenuLinkDefault {
/**
* The entity represented in the menu link.
*
* @var \Drupal\Core\Entity\EntityInterface
*/
protected $entity;
/**
* Constructs a new MenuLinkEntity.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Menu\StaticMenuLinkOverridesInterface $static_override
* The static override storage.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, StaticMenuLinkOverridesInterface $static_override, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $static_override);
$this->entity = $entity_type_manager->getStorage($this->pluginDefinition['metadata']['entity_type'])->load($this->pluginDefinition['metadata']['entity_id']);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('menu_link.static.overrides'),
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
public function getTitle() {
if ($this->entity) {
return (string) $this->entity->label();
}
return $this->pluginDefinition['title'] ?: $this->t('Missing');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
// @todo Remove node_type special handling.
if ($this->entity instanceof EntityDescriptionInterface || $this->entity instanceof NodeTypeInterface) {
return $this->entity->getDescription();
}
return parent::getDescription();
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
if ($this->entity) {
return $this->entity->getCacheContexts();
}
return parent::getCacheContexts();
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
if ($this->entity) {
return $this->entity->getCacheTags();
}
return parent::getCacheTags();
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
if ($this->entity) {
return $this->entity->getCacheMaxAge();
}
return parent::getCacheMaxAge();
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Drupal\Tests\admin_toolbar_tools\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests for the existence of Admin Toolbar tools new links.
*
* @group admin_toolbar
*/
class AdminToolbarToolsAlterTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'toolbar',
'admin_toolbar',
'admin_toolbar_tools',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* A test user with permission to access the administrative toolbar.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Create and log in an administrative user.
$this->adminUser = $this->drupalCreateUser([
'access toolbar',
'access administration pages',
'administer site configuration',
]);
$this->drupalLogin($this->adminUser);
}
/**
* Tests for the hover of sub menus.
*/
public function testAdminToolbarTools() {
// Assert that special menu items are present in the HTML.
$this->assertSession()->responseContains('class="toolbar-icon toolbar-icon-admin-toolbar-tools-flush"');
}
}

View File

@@ -0,0 +1,38 @@
{
"name": "drupal/admin_toolbar",
"description": "Provides a drop-down menu interface to the core Drupal Toolbar.",
"type": "drupal-module",
"keywords": [
"Drupal",
"Toolbar"
],
"homepage": "http://drupal.org/project/admin_toolbar",
"license": "GPL-2.0-or-later",
"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": "https://git.drupalcode.org/project/admin_toolbar"
}
}

View File

@@ -0,0 +1,129 @@
.toolbar-tray-horizontal .menu-item:hover {
background: #fff;
}
.toolbar-tray-horizontal .menu-item a:focus {
background: #abeae4;
}
.toolbar-tray-horizontal .toolbar-menu:not(:first-child) li.menu-item--expanded > a:focus {
background-position: center right;
background-image: url(../misc/icons/0074bd/chevron-right.svg);
background-repeat: no-repeat;
}
.toolbar-tray-horizontal .menu-item--expanded .menu {
background: #fff;
width: auto;
height: auto;
}
.toolbar-tray-horizontal .menu-item--expanded {
background-color: #f5f5f2;
}
.toolbar-tray-horizontal ul li li.menu-item {
border-top: none transparent;
border-right: 1px solid #ddd;
border-bottom: 1px solid #ddd;
border-left: 1px solid #ddd;
}
.toolbar .toolbar-tray-horizontal .menu-item:last-child {
border-left: 1px solid #ddd;
border-right: 1px solid #ddd;
}
.toolbar .toolbar-tray-horizontal ul ul li.menu-item:first-child {
border-top: 1px solid #ddd;
}
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul,
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul ul,
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul ul ul,
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul ul ul ul ul {
display: none;
left: -999em; /* LTR */
}
/* Lists nested under hovered list items */
.toolbar-tray-horizontal li.menu-item--expanded.hover-intent ul,
.toolbar-tray-horizontal li li.menu-item--expanded.hover-intent ul,
.toolbar-tray-horizontal li li li.menu-item--expanded.hover-intent ul,
.toolbar-tray-horizontal li li li li.menu-item--expanded.hover-intent ul,
.toolbar-tray-horizontal li li li li li.menu-item--expanded.hover-intent ul {
display: block;
left: auto; /* LTR */
}
.toolbar-tray-horizontal .menu ul li a,
.toolbar-tray-horizontal .menu ul .toolbar-icon {
padding: 12px 15px 12px 12px;
}
.toolbar-tray-horizontal ul li.menu-item--expanded.hover-intent ul {
display: block;
position: absolute;
width: 200px;
box-shadow: 2px 2px 3px hsla(0, 0%, 0%, 0.4);
z-index: 1;
}
.toolbar-tray-horizontal ul li.menu-item--expanded .menu-item > ul {
display: none;
}
.toolbar-tray-horizontal ul li.menu-item--expanded ul li.menu-item--expanded {
background-position: center right;
background-image: url(../misc/icons/0074bd/chevron-right.svg);
background-repeat: no-repeat;
}
.toolbar-tray-horizontal ul li.menu-item--expanded .menu-item.hover-intent ul {
display: block;
margin: -40px 0 0 197px;
}
.toolbar-tray-horizontal li:hover ul li {
float: none;
}
.toolbar-tray-horizontal li.hover-intent ul li {
float: none;
}
.toolbar-tray-horizontal .toolbar .level-2 > ul {
position: absolute;
padding-top: 0;
top: 0;
left: 200px;
width: 200px;
}
.toolbar .toolbar-tray-vertical li.open > ul.toolbar-menu.clearfix {
display: block;
}
.toolbar-menu .menu-item > span {
padding: 1em 1.3333em;
display: block;
color: #434343;
cursor: pointer;
}
[dir="rtl"] .toolbar-tray-horizontal ul li.menu-item--expanded ul li.menu-item--expanded {
background-position: center left;
background-image: url(../misc/icons/0074bd/chevron-left.svg);
}
[dir="rtl"] .toolbar-tray-horizontal ul li.menu-item--expanded .menu-item.hover-intent ul {
margin: -40px 197px 0 0;
}
[dir="rtl"] .toolbar-tray-horizontal li:hover ul li {
float: none;
}
[dir="rtl"] .toolbar-tray-horizontal li.hover-intent ul li {
float: none;
}

View File

@@ -0,0 +1,33 @@
#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: #000;
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 {
display: none;
}

View File

@@ -0,0 +1,13 @@
(function ($) {
$(document).ready(function () {
$('.toolbar-tray.toolbar-tray-horizontal .menu-item.menu-item--expanded').hover(function () {
// At the current depth, we should delete all "hover-intent" classes.
// Other wise we get unwanted behaviour where menu items are expanded while already in hovering other ones.
$(this).parent().find('li').removeClass('hover-intent');
$(this).addClass('hover-intent');
},
function () {
$(this).removeClass('hover-intent');
});
});
})(jQuery);

View File

@@ -0,0 +1,16 @@
(function ($) {
$(document).ready(function () {
$('.toolbar-tray-horizontal li.menu-item--expanded, .toolbar-tray-horizontal ul li.menu-item--expanded .menu-item').hoverIntent({
over: function () {
// At the current depth, we should delete all "hover-intent" classes.
// Other wise we get unwanted behaviour where menu items are expanded while already in hovering other ones.
$(this).parent().find('li').removeClass('hover-intent');
$(this).addClass('hover-intent');
},
out: function () {
$(this).removeClass('hover-intent');
},
timeout: 250
});
});
})(jQuery);

View File

@@ -0,0 +1,47 @@
(function ($, Drupal) {
Drupal.behaviors.adminToolbar = {
attach: function (context, settings) {
$('a.toolbar-icon', context).removeAttr('title');
// Make the toolbar menu navigable with keyboard.
$('ul.toolbar-menu li.menu-item--expanded a', context).on('focusin', function () {
$('li.menu-item--expanded', context).removeClass('hover-intent');
$(this).parents('li.menu-item--expanded').addClass('hover-intent');
});
$('ul.toolbar-menu li.menu-item a', context).keydown(function (e) {
if ((e.shiftKey && (e.keyCode || e.which) == 9)) {
if ($(this).parent('.menu-item').prev().hasClass('menu-item--expanded')) {
$(this).parent('.menu-item').prev().addClass('hover-intent');
}
}
});
$('.toolbar-menu:first-child > .menu-item:not(.menu-item--expanded) a, .toolbar-tab > a', context).on('focusin', function () {
$('.menu-item--expanded').removeClass('hover-intent');
});
$('.toolbar-menu:first-child > .menu-item', context).on('hover', function () {
$(this, 'a').css("background: #fff;");
});
$('ul:not(.toolbar-menu)', context).on({
mousemove: function () {
$('li.menu-item--expanded').removeClass('hover-intent');
},
hover: function () {
$('li.menu-item--expanded').removeClass('hover-intent');
}
});
// Always hide the dropdown menu on mobile.
if (window.matchMedia("(max-width: 767px)").matches && $('body').hasClass('toolbar-tray-open')) {
$('body').removeClass('toolbar-tray-open');
$('#toolbar-item-administration').removeClass('is-active');
$('#toolbar-item-administration-tray').removeClass('is-active');
};
}
};
})(jQuery, Drupal);

View File

@@ -0,0 +1,156 @@
;/*!
* hoverIntent v1.8.1 // 2014.08.11 // jQuery v1.9.1+
* http://briancherne.github.io/jquery-hoverIntent/
*
* You may use hoverIntent under the terms of the MIT license. Basically that
* means you are free to use hoverIntent as long as this header is left intact.
* Copyright 2007, 2014 Brian Cherne
*/
/* hoverIntent is similar to jQuery's built-in "hover" method except that
* instead of firing the handlerIn function immediately, hoverIntent checks
* to see if the user's mouse has slowed down (beneath the sensitivity
* threshold) before firing the event. The handlerOut function is only
* called after a matching handlerIn.
*
* // basic usage ... just like .hover()
* .hoverIntent( handlerIn, handlerOut )
* .hoverIntent( handlerInOut )
*
* // basic usage ... with event delegation!
* .hoverIntent( handlerIn, handlerOut, selector )
* .hoverIntent( handlerInOut, selector )
*
* // using a basic configuration object
* .hoverIntent( config )
*
* @param handlerIn function OR configuration object
* @param handlerOut function OR selector for delegation OR undefined
* @param selector selector OR undefined
* @author Brian Cherne <brian(at)cherne(dot)net>
*/(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (jQuery && !jQuery.fn.hoverIntent) {
factory(jQuery);
}
})(function ($) {
'use strict';
// default configuration values
var _cfg = {
interval: 100,
sensitivity: 6,
timeout: 0
};
// counter used to generate an ID for each instance
var INSTANCE_COUNT = 0;
// current X and Y position of mouse, updated during mousemove tracking (shared across instances)
var cX, cY;
// saves the current pointer position coordinates based on the given mousemove event
var track = function (ev) {
cX = ev.pageX;
cY = ev.pageY;
};
// compares current and previous mouse positions
var compare = function (ev,$el,s,cfg) {
// compare mouse positions to see if pointer has slowed enough to trigger `over` function
if ( Math.sqrt( (s.pX - cX) * (s.pX - cX) + (s.pY - cY) * (s.pY - cY) ) < cfg.sensitivity ) {
$el.off(s.event,track);
delete s.timeoutId;
// set hoverIntent state as active for this element (permits `out` handler to trigger)
s.isActive = true;
// overwrite old mouseenter event coordinates with most recent pointer position
ev.pageX = cX; ev.pageY = cY;
// clear coordinate data from state object
delete s.pX; delete s.pY;
return cfg.over.apply($el[0],[ev]);
} else {
// set previous coordinates for next comparison
s.pX = cX; s.pY = cY;
// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
s.timeoutId = setTimeout( function () {compare(ev, $el, s, cfg);} , cfg.interval );
}
};
// triggers given `out` function at configured `timeout` after a mouseleave and clears state
var delay = function (ev,$el,s,out) {
delete $el.data('hoverIntent')[s.id];
return out.apply($el[0],[ev]);
};
$.fn.hoverIntent = function (handlerIn,handlerOut,selector) {
// instance ID, used as a key to store and retrieve state information on an element
var instanceId = INSTANCE_COUNT++;
// extend the default configuration and parse parameters
var cfg = $.extend({}, _cfg);
if ( $.isPlainObject(handlerIn) ) {
cfg = $.extend(cfg, handlerIn);
if ( !$.isFunction(cfg.out) ) {
cfg.out = cfg.over;
}
} else if ( $.isFunction(handlerOut) ) {
cfg = $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector } );
} else {
cfg = $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut } );
}
// A private function for handling mouse 'hovering'
var handleHover = function (e) {
// cloned event to pass to handlers (copy required for event object to be passed in IE)
var ev = $.extend({},e);
// the current target of the mouse event, wrapped in a jQuery object
var $el = $(this);
// read hoverIntent data from element (or initialize if not present)
var hoverIntentData = $el.data('hoverIntent');
if (!hoverIntentData) { $el.data('hoverIntent', (hoverIntentData = {})); }
// read per-instance state from element (or initialize if not present)
var state = hoverIntentData[instanceId];
if (!state) { hoverIntentData[instanceId] = state = { id: instanceId }; }
// state properties:
// id = instance ID, used to clean up data
// timeoutId = timeout ID, reused for tracking mouse position and delaying "out" handler
// isActive = plugin state, true after `over` is called just until `out` is called
// pX, pY = previously-measured pointer coordinates, updated at each polling interval
// event = string representing the namespaced event used for mouse tracking
// clear any existing timeout
if (state.timeoutId) { state.timeoutId = clearTimeout(state.timeoutId); }
// namespaced event used to register and unregister mousemove tracking
var mousemove = state.event = 'mousemove.hoverIntent.hoverIntent' + instanceId;
// handle the event, based on its type
if (e.type === 'mouseenter') {
// do nothing if already active
if (state.isActive) { return; }
// set "previous" X and Y position based on initial entry point
state.pX = ev.pageX; state.pY = ev.pageY;
// update "current" X and Y position based on mousemove
$el.off(mousemove,track).on(mousemove,track);
// start polling interval (self-calling timeout) to compare mouse coordinates over time
state.timeoutId = setTimeout( function () {compare(ev,$el,state,cfg);} , cfg.interval );
} else { // "mouseleave"
// do nothing if not already active
if (!state.isActive) { return; }
// unbind expensive mousemove event
$el.off(mousemove,track);
// if hoverIntent state is true, then call the mouseOut function after the specified delay
state.timeoutId = setTimeout( function () {delay(ev,$el,state,cfg.out);} , cfg.timeout );
}
};
// listen for mouseenter and mouseleave
return this.on({'mouseenter.hoverIntent':handleHover,'mouseleave.hoverIntent':handleHover}, cfg.selector);
};
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#0074bd" d="M7.951 7.645c-.193.196-.193.516 0 .71l3.258 3.29c.193.193.191.519-.002.709l-1.371 1.371c-.193.192-.512.191-.707 0l-5.335-5.371c-.194-.194-.194-.514 0-.708l5.335-5.369c.195-.195.514-.195.707-.001l1.371 1.371c.193.194.195.513.002.709l-3.258 3.289z"/></svg>

After

Width:  |  Height:  |  Size: 342 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#0074bd" d="M8.053 8.355c.193-.195.193-.517 0-.711l-3.26-3.289c-.193-.195-.192-.514.002-.709l1.371-1.371c.194-.194.512-.193.706.001l5.335 5.369c.195.195.195.515 0 .708l-5.335 5.37c-.194.192-.512.193-.706.002l-1.371-1.371c-.194-.195-.195-.514-.002-.709l3.26-3.29z"/></svg>

After

Width:  |  Height:  |  Size: 347 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#BEBEBE" d="M14.648 12.788l-4.23-4.228c.525-.855.834-1.858.834-2.938 0-3.105-2.52-5.624-5.627-5.624-3.106.002-5.625 2.521-5.625 5.627 0 3.105 2.519 5.625 5.625 5.625 1.076 0 2.08-.309 2.936-.832l4.229 4.229c.194.195.515.195.707 0l1.151-1.146c.194-.2.194-.519 0-.713zm-13.35-7.163c0-2.39 1.938-4.327 4.327-4.327 2.391 0 4.328 1.937 4.328 4.327 0 2.391-1.936 4.327-4.328 4.327-2.39 0-4.327-1.936-4.327-4.327z"/></svg>

After

Width:  |  Height:  |  Size: 491 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#0074bd" d="M8.053 8.355c.193-.195.193-.517 0-.711l-3.26-3.289c-.193-.195-.192-.514.002-.709l1.371-1.371c.194-.194.512-.193.706.001l5.335 5.369c.195.195.195.515 0 .708l-5.335 5.37c-.194.192-.512.193-.706.002l-1.371-1.371c-.194-.195-.195-.514-.002-.709l3.26-3.29z"/></svg>

After

Width:  |  Height:  |  Size: 347 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path fill="#FFFFFF" d="M14.648 12.788l-4.23-4.228c.525-.855.834-1.858.834-2.938 0-3.105-2.52-5.624-5.627-5.624-3.106.002-5.625 2.521-5.625 5.627 0 3.105 2.519 5.625 5.625 5.625 1.076 0 2.08-.309 2.936-.832l4.229 4.229c.194.195.515.195.707 0l1.151-1.146c.194-.2.194-.519 0-.713zm-13.35-7.163c0-2.39 1.938-4.327 4.327-4.327 2.391 0 4.328 1.937 4.328 4.327 0 2.391-1.936 4.327-4.328 4.327-2.39 0-4.327-1.936-4.327-4.327z"/></svg>

After

Width:  |  Height:  |  Size: 491 B

View File

@@ -0,0 +1,105 @@
<?php
namespace Drupal\admin_toolbar\Form;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class AdminToolbarSettingsForm. The config form for the admin_toolbar module.
*
* @package Drupal\admin_toolbar\Form
*/
class AdminToolbarSettingsForm extends ConfigFormBase {
/**
* The cache menu instance.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheMenu;
/**
* The menu link manager instance.
*
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* AdminToolbarSettingsForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory for the form.
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menuLinkManager
* A menu link manager instance.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheMenu
* A cache menu instance.
*/
public function __construct(ConfigFactoryInterface $config_factory, MenuLinkManagerInterface $menuLinkManager, CacheBackendInterface $cacheMenu) {
parent::__construct($config_factory);
$this->cacheMenu = $cacheMenu;
$this->menuLinkManager = $menuLinkManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('plugin.manager.menu.link'),
$container->get('cache.menu')
);
}
/**
* {@inheritDoc}
*/
protected function getEditableConfigNames() {
return [
'admin_toolbar.settings',
];
}
/**
* {@inheritDoc}
*/
public function getFormId() {
return 'admin_toolbar_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('admin_toolbar.settings');
$depth_values = range(1, 9);
$form['menu_depth'] = [
'#type' => 'select',
'#title' => $this->t('Menu depth'),
'#description' => $this->t('Maximal depth of displayed menu.'),
'#default_value' => $config->get('menu_depth'),
'#options' => array_combine($depth_values, $depth_values),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('admin_toolbar.settings')
->set('menu_depth', $form_state->getValue('menu_depth'))
->save();
parent::submitForm($form, $form_state);
$this->cacheMenu->invalidateAll();
$this->menuLinkManager->rebuild();
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace Drupal\admin_toolbar\Render\Element;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Security\TrustedCallbackInterface;
/**
* Render element element for AdminToolbar.
*
* @package Drupal\admin_toolbar\Render\Element
*/
class AdminToolbar implements TrustedCallbackInterface {
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return ['preRenderTray'];
}
/**
* 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 $build
* A renderable array.
*
* @return array
* The updated renderable array.
*
* @see toolbar_prerender_toolbar_administration_tray()
*/
public static function preRenderTray(array $build) {
$menu_tree = \Drupal::service('toolbar.menu_tree');
$parameters = new MenuTreeParameters();
$max_depth = \Drupal::config('admin_toolbar.settings')->get('menu_depth');
$parameters->setRoot('system.admin')->excludeRoot()->setMaxDepth($max_depth)->onlyEnabledLinks();
$tree = $menu_tree->load('admin', $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);
$build['administration_menu'] = $menu_tree->build($tree);
return $build;
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Drupal\Tests\admin_toolbar\Functional;
use Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest;
/**
* Tests the caching of the admin menu subtree items.
*
* @group admin_toolbar
*/
class AdminToolbarAdminMenuTest extends ToolbarAdminMenuTest {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'admin_toolbar',
];
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Drupal\Tests\admin_toolbar\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Test the existence of Admin Toolbar module.
*
* @group admin_toolbar
*/
class AdminToolbarAlterTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'toolbar',
'breakpoint',
'admin_toolbar',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* A test user with permission to access the administrative toolbar.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Create and log in an administrative user.
$this->adminUser = $this->drupalCreateUser([
'access toolbar',
'access administration pages',
]);
$this->drupalLogin($this->adminUser);
}
/**
* Tests for a the hover of sub menus.
*/
public function testAdminToolbar() {
// Assert that expanded links are present in the HTML.
$this->assertSession()->responseContains('class="toolbar-icon toolbar-icon-user-admin-index"');
}
}

View File

@@ -0,0 +1,254 @@
<?php
namespace Drupal\Tests\admin_toolbar\Functional;
use Drupal\media\Entity\MediaType;
use Drupal\system\Entity\Menu;
use Drupal\Tests\BrowserTestBase;
/**
* Tests Admin Toolbar tools functionality.
*
* @group admin_toolbar
*/
class AdminToolbarToolsSortTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'toolbar',
'breakpoint',
'admin_toolbar',
'admin_toolbar_tools',
'menu_ui',
'media',
'field_ui',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* A test user with permission to access the administrative toolbar.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Tests that menu updates on entity add/update/delete.
*/
public function testMenuUpdate() {
// Create and log in an administrative user.
$this->adminUser = $this->drupalCreateUser([
'access toolbar',
'access administration pages',
'administer site configuration',
'administer menu',
'access media overview',
'administer media',
'administer media fields',
'administer media form display',
'administer media display',
'administer media types',
]);
$this->drupalLogin($this->adminUser);
$menu = Menu::create([
'id' => 'armadillo',
'label' => 'Armadillo',
]);
$menu->save();
$this->container->get('plugin.manager.menu.link')->rebuild();
$this->drupalGet('/admin');
// Assert that special menu items are present in the HTML.
$this->assertSession()->responseContains('class="toolbar-icon toolbar-icon-admin-toolbar-tools-flush"');
// Assert that adding a media type adds it to the admin toolbar.
$chinchilla_media_type = MediaType::create([
'id' => 'chinchilla',
'label' => 'Chinchilla',
'source' => 'image',
]);
$chinchilla_media_type->save();
$this->drupalGet('/admin');
$this->assertMenuHasHref('/admin/structure/media/manage/chinchilla');
// Assert that adding a menu adds it to the admin toolbar.
$menu = Menu::create([
'id' => 'chupacabra',
'label' => 'Chupacabra',
]);
$menu->save();
$this->drupalGet('/admin');
$this->assertMenuHasHref('/admin/structure/menu/manage/chupacabra');
// Assert that deleting a menu removes it from the admin toolbar.
$this->assertMenuHasHref('/admin/structure/menu/manage/armadillo');
$menu = Menu::load('armadillo');
$menu->delete();
$this->drupalGet('/admin');
$this->assertMenuDoesNotHaveHref('/admin/structure/menu/manage/armadillo');
// Assert that deleting a content entity bundle removes it from admin menu.
$this->assertMenuHasHref('/admin/structure/media/manage/chinchilla');
$chinchilla_media_type = MediaType::load('chinchilla');
$chinchilla_media_type->delete();
$this->drupalGet('/admin');
$this->assertMenuDoesNotHaveHref('/admin/structure/media/manage/chinchilla');
}
/**
* Tests sorting of menus by label rather than machine name.
*/
public function testMenuSorting() {
// Create and log in an administrative user.
$this->adminUser = $this->drupalCreateUser([
'access toolbar',
'access administration pages',
'administer site configuration',
'administer menu',
]);
$menus = [
'aaa' => 'qqq',
'bbb' => 'ppp',
'ccc' => 'ooo',
'ddd' => 'nnn',
'eee' => 'mmm',
'fff' => 'lll',
'ggg' => 'kkk',
'hhh' => 'jjj',
'iii' => 'iii',
'jjj' => 'hhh',
'kkk' => 'ggg',
'lll' => 'fff',
'mmm' => 'eee',
'nnn' => 'ddd',
'ooo' => 'ccc',
'ppp' => 'bbb',
'qqq' => 'aaa',
];
foreach ($menus as $machine_name => $label) {
$menu = Menu::create([
'id' => $machine_name,
'label' => $label,
]);
$menu->save();
}
$this->drupalLogin($this->adminUser);
$this->container->get('plugin.manager.menu.link')->rebuild();
$this->drupalGet('/admin');
$results = $this->getSession()->getPage()->findAll('xpath', '//a[contains(@href, "/admin/structure/menu/manage")]');
$links = [];
foreach ($results as $result) {
$links[] = $result->getAttribute('href');
}
$expected = [
0 => '/admin/structure/menu/manage/qqq',
1 => '/admin/structure/menu/manage/qqq/add',
2 => '/admin/structure/menu/manage/qqq/delete',
3 => '/admin/structure/menu/manage/admin',
4 => '/admin/structure/menu/manage/admin/add',
5 => '/admin/structure/menu/manage/ppp',
6 => '/admin/structure/menu/manage/ppp/add',
7 => '/admin/structure/menu/manage/ppp/delete',
8 => '/admin/structure/menu/manage/ooo',
9 => '/admin/structure/menu/manage/ooo/add',
10 => '/admin/structure/menu/manage/ooo/delete',
11 => '/admin/structure/menu/manage/nnn',
12 => '/admin/structure/menu/manage/nnn/add',
13 => '/admin/structure/menu/manage/nnn/delete',
14 => '/admin/structure/menu/manage/mmm',
15 => '/admin/structure/menu/manage/mmm/add',
16 => '/admin/structure/menu/manage/mmm/delete',
17 => '/admin/structure/menu/manage/lll',
18 => '/admin/structure/menu/manage/lll/add',
19 => '/admin/structure/menu/manage/lll/delete',
20 => '/admin/structure/menu/manage/footer',
21 => '/admin/structure/menu/manage/footer/add',
22 => '/admin/structure/menu/manage/kkk',
23 => '/admin/structure/menu/manage/kkk/add',
24 => '/admin/structure/menu/manage/kkk/delete',
25 => '/admin/structure/menu/manage/jjj',
26 => '/admin/structure/menu/manage/jjj/add',
27 => '/admin/structure/menu/manage/jjj/delete',
28 => '/admin/structure/menu/manage/iii',
29 => '/admin/structure/menu/manage/iii/add',
30 => '/admin/structure/menu/manage/iii/delete',
31 => '/admin/structure/menu/manage/hhh',
32 => '/admin/structure/menu/manage/hhh/add',
33 => '/admin/structure/menu/manage/hhh/delete',
34 => '/admin/structure/menu/manage/ggg',
35 => '/admin/structure/menu/manage/ggg/add',
36 => '/admin/structure/menu/manage/ggg/delete',
37 => '/admin/structure/menu/manage/fff',
38 => '/admin/structure/menu/manage/fff/add',
39 => '/admin/structure/menu/manage/fff/delete',
40 => '/admin/structure/menu/manage/main',
41 => '/admin/structure/menu/manage/main/add',
42 => '/admin/structure/menu/manage/eee',
43 => '/admin/structure/menu/manage/eee/add',
44 => '/admin/structure/menu/manage/eee/delete',
45 => '/admin/structure/menu/manage/ddd',
46 => '/admin/structure/menu/manage/ddd/add',
47 => '/admin/structure/menu/manage/ddd/delete',
48 => '/admin/structure/menu/manage/ccc',
49 => '/admin/structure/menu/manage/ccc/add',
50 => '/admin/structure/menu/manage/ccc/delete',
51 => '/admin/structure/menu/manage/bbb',
52 => '/admin/structure/menu/manage/bbb/add',
53 => '/admin/structure/menu/manage/bbb/delete',
54 => '/admin/structure/menu/manage/aaa',
55 => '/admin/structure/menu/manage/aaa/add',
56 => '/admin/structure/menu/manage/aaa/delete',
];
foreach ($links as $key => $link) {
// Using assert contains because prefaces the urls with "/subdirectory".
$this->assertStringContainsString($expected[$key], $link);
}
}
/**
* Checks that there is a link with the specified url in the admin toolbar.
*
* @param string $url
* The url to assert exists in the admin menu.
*
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
protected function assertMenuHasHref($url) {
$this->assertSession()
->elementExists('xpath', '//div[@id="toolbar-item-administration-tray"]//a[contains(@href, "' . $url . '")]');
}
/**
* Checks that there is no link with the specified url in the admin toolbar.
*
* @param string $url
* The url to assert exists in the admin menu.
*
* @throws \Behat\Mink\Exception\ExpectationException
*/
protected function assertMenuDoesNotHaveHref($url) {
$this->assertSession()
->elementNotExists('xpath', '//div[@id="toolbar-item-administration-tray"]//a[contains(@href, "' . $url . '")]');
}
}