Commit a80432f7 authored by mimran's avatar mimran Committed by matio89

Issue #2598136 by mimran, felribeiro: Menu items duplicated

parent 14349023
......@@ -27,10 +27,48 @@ function admin_toolbar_prerender_toolbar_administration_tray(array $element) {
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
array('callable' => 'toolbar_menu_navigation_links'),
array('callable' => 'toolbar_tools_menu_navigation_links'),
);
$tree = $menu_tree->transform($tree, $manipulators);
$element['administration_menu'] = $menu_tree->build($tree);
return $element;
}
/**
* Adds toolbar-specific attributes to the menu link tree.
*
* @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);
}
// Make sure we have a path specific ID in place, so we can attach icons
// and behaviors to the menu links.
$link = $element->link;
$url = $link->getUrlObject();
if (!$url->isRouted()) {
// This is an unusual case, so just get a distinct, safe string.
$id = substr(Crypt::hashBase64($url->getUri()), 0, 16);
}
else {
$id = str_replace(array('.', '<', '>'), array('-', '', ''), $url->getRouteName());
}
// Get the non-localized title to make the icon class.
$definition = $link->getPluginDefinition();
$element->options['attributes']['class'][] = 'toolbar-icon';
$element->options['attributes']['class'][] = 'toolbar-icon-' . strtolower(str_replace(array('.', ' ', '_'), array('-', '-', '-'), $definition['id']));
$element->options['attributes']['title'] = $link->getDescription();
}
return $tree;
}
\ No newline at end of file
......@@ -5,16 +5,16 @@
* Contains \Drupal\admin_toolbar\Tests\AdminToolbarAlterTest.
*/
namespace Drupal\admin_toolbar_tools\Tests;
namespace Drupal\admin_toolbar\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Test the existence of Admin Toolbar tools new links.
* Test the existence of Admin Toolbar module.
*
* @group admin_toolbar_tools
* @group admin_toolbar
*/
class AdminToolbarToolsAlterTest extends WebTestBase {
class AdminToolbarAlterTest extends WebTestBase {
/**
* A user with permission to access the administrative toolbar.
......@@ -28,7 +28,7 @@ class AdminToolbarToolsAlterTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('toolbar', 'admin_toolbar', 'admin_toolbar_tools');
public static $modules = array('toolbar', 'admin_toolbar');
protected function setUp() {
parent::setUp();
......@@ -41,11 +41,11 @@ class AdminToolbarToolsAlterTest extends WebTestBase {
/**
* Tests for a the hover of sub menus.
*/
function testAdminToolbarTools() {
function testAdminToolbar() {
// Test for admin_toolbar_tools if special menu items are added.
$this->assertRaw('id="toolbar-link-admin_toolbar_tools-flush"');
// Assert that expanded links are present in HTML.
// Test with the site configuration link that must be there whatever modules exists.
$this->assertRaw('data-drupal-link-system-path="admin/config/system"');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment