Commit 52ef5735 authored by adriancid's avatar adriancid

Merge branch '8.x-1.x' of git.drupal.org:project/admin_toolbar into 8.x-1.x

parents 0263a273 39c1c1b8
......@@ -2,6 +2,13 @@ Admin Toolbar 8.x-1.27, 2019-05-22
----------------------------------
Changes since 8.x-1.26:
- #3026216 by adriancid, oknate, sunlix, joachim: Add media link to content
menu in toolbar.
- #3051676 by Amsteri, rollingnet, adriancid: Menu items with no link miss of
CSS.
- #3026302 by idebr, adriancid: Admin toolbar icon width/height changes for
themes based on box-sizing: border-box.
- #2986082 by oknate, Bobík, adriancid: Add search for menu items.
- #3026337 by thalles, mpp, adriancid, Gábor Hojtsy: Config labels are not
properly translated.
- #3003678 by adriancid, romainj: New method to invalidate twig templates.
......
......@@ -8,3 +8,14 @@ toolbar.tree:
dependencies:
- core/jquery
- core/drupal
search:
css:
theme:
css/admin.toolbar_search.css: {}
js:
js/admin_toolbar_search.js: {}
dependencies:
- core/jquery
- core/drupal
- core/jquery.once
- core/jquery.ui.autocomplete
......@@ -9,6 +9,7 @@ use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Component\Utility\Html;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Implements hook_toolbar_alter().
......@@ -16,6 +17,38 @@ use Drupal\Component\Utility\Html;
function admin_toolbar_toolbar_alter(&$items) {
$items['administration']['tray']['toolbar_administration']['#pre_render'] = ['admin_toolbar_prerender_toolbar_administration_tray'];
$items['administration']['#attached']['library'][] = 'admin_toolbar/toolbar.tree';
$items['administration_search'] = [
"#type" => "toolbar_item",
'tab' => [
'#type' => 'link',
'#title' => new TranslatableMarkup('Search'),
'#url' => URL::fromRoute('system.admin'),
'#attributes' => [
'class' => [
'toolbar-icon',
],
],
],
'tray' => [
'search' => [
'#title' => 'Search',
'#type' => 'textfield',
'#size' => 60,
'#attributes' => [
'id' => 'admin-toolbar-search-input',
],
],
],
'#attached' => [
'library' => [
'admin_toolbar/search',
],
],
'#wrapper_attributes' => [
"id" => "admin-toolbar-search-tab",
],
];
}
/**
......
......@@ -636,6 +636,15 @@ function admin_toolbar_tools_menu_links_discovered_alter(&$links) {
// If module Media enabled.
if ($moduleHandler->moduleExists('media')) {
// Displays media link in toolbar.
$links['admin_toolbar_tools.media_page'] = [
'title' => t('Media'),
'provider' => 'admin_toolbar_tools',
'route_name' => 'entity.media.collection',
'menu_name' => 'admin',
'parent' => 'system.admin_content',
];
$links['admin_toolbar_tools.add_media'] = [
'title' => t('Add media'),
'provider' => 'admin_toolbar_tools',
......
......@@ -3,6 +3,7 @@
}
.toolbar-icon-admin-toolbar-tools-help:before {
box-sizing: content-box;
background-image: url(../misc/icons/ffffff/d8-item.svg);
padding-bottom: 0;
padding-left: 4px;
......
......@@ -104,6 +104,13 @@
display: block;
}
.toolbar-menu .menu-item > span {
padding: 1em 1.3333em;
display: block;
color: #434343;
cursor: pointer;
}
[dir="rtl"] .toolbar-tray-horizontal .menu-item:hover {
background: #fff;
}
......
#toolbar-item-administration-search-tray {
padding-left: 1em;
}
#admin-toolbar-search-tab .toolbar-item:before {
background-image: url('../misc/icons/bebebe/loupe.svg');
}
#admin-toolbar-search-tab .toolbar-item:active:before,
#admin-toolbar-search-tab .toolbar-item.is-active:before {
background-image: url('../misc/icons/ffffff/loupe.svg');
}
#toolbar-item-administration-search-tray label {
display: inline-block;
color: #000000;
margin-right: .5em;
font-weight: bold;
}
#toolbar-item-administration-search-tray div.form-item {
margin: 0.75em 0;
}
#toolbar-item-administration-search-tray input {
display: inline-block;
padding: 0.3em 0.4em 0.3em 0.5em;
font-size: 1em;
}
.ui-autocomplete .ui-menu-item span.admin-toolbar-search-url {
color: rgba(0, 0, 0, 0.50);
}
(function ($, Drupal) {
Drupal.behaviors.adminToolbarSearch = {
attach: function (context) {
if (context != document) {
return;
}
var getUrl = window.location;
var baseUrl = getUrl.protocol + "//" + getUrl.host + "/";
var $self = this;
this.links = [];
$('a[data-drupal-link-system-path]').each(function() {
if (this.href != baseUrl) {
var label = $self.getItemLabel(this);
$self.links.push({
'value': $(this).attr('href'),
'label': label + ' ' + $(this).attr('href'),
'labelRaw': label
});
}
});
$( "#admin-toolbar-search-input").autocomplete({
minLength: 2,
source: function(request, response) {
var data = $self.handleAutocomplete(request.term);
response(data);
},
open: function(){
var zIndex = $('#toolbar-item-administration-search-tray').css("z-index")+1;
$(this).autocomplete('widget').css('z-index', zIndex);
return false;
},
select: function( event, ui ) {
if (ui.item.value) {
location.href = ui.item.value;
return false;
}
}
}).data("ui-autocomplete")._renderItem = (function(ul, item) {
return $("<li>")
.append('<div>' + item.labelRaw + ' <span class="admin-toolbar-search-url">' + item.value + '</span></div>')
.appendTo(ul);
});
// Focus on search field when tab is clicked, or enter is pressed.
$(context).find('#toolbar-item-administration-search').once('admin_toolbar_search').each(function () {
if ($('#toolbar-item-administration-search-tray:visible').length) {
$('#admin-toolbar-search-input').focus();
}
$(this).on('click', function() {
$self.focusOnSearchElement();
});
});
},
focusOnSearchElement: function() {
var waitforVisible = function() {
if ($('#toolbar-item-administration-search-tray:visible').length) {
$('#admin-toolbar-search-input').focus();
} else {
setTimeout(function() {
waitforVisible();
}, 1);
}
};
waitforVisible();
},
getItemLabel: function(item) {
var breadcrumbs = [];
$(item).parents().each(function() {
if ($(this).hasClass('menu-item')) {
var $link = $(this).find('a:first');
if ($link.length && !$link.hasClass('admin-toolbar-search-ignore')) {
breadcrumbs.unshift($link.text());
}
}
});
label = breadcrumbs.join(' > ');
return label;
},
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;
}
};
})(jQuery, Drupal);
<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>
<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>
<?php
namespace Drupal\Tests\admin_toolbar\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Test the functionality of admin toolbar search.
*
* @group admin_toolbar
*/
class AdminToolbarSearchTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'admin_toolbar',
];
/**
* The admin user for tests.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser([
'access toolbar',
'administer menu',
'access administration pages',
'administer site configuration',
]);
}
/**
* Tests search functionality.
*/
public function testSearchFunctionality() {
$search_tab = '#toolbar-item-administration-search';
$search_tray = '#toolbar-item-administration-search-tray';
$search_input = '#admin-toolbar-search-input';
$this->drupalLogin($this->adminUser);
$this->assertSession()->responseContains('admin.toolbar_search.css');
$this->assertSession()->responseContains('admin_toolbar_search.js');
$this->assertSession()->elementExists('css', $search_tab)->click();
$this->assertSession()->waitForElementVisible('css', $search_tray);
$this->assertSession()
->elementExists('css', $search_input)
->setValue('basic');
$autocomplete_suggestions = $this->assertSession()
->waitForElementVisible('css', 'ul.ui-autocomplete');
$suggestion = 'Configuration &gt; System &gt; Basic site settings <span class="admin-toolbar-search-url">/subdirectory/admin/config/system/site-information</span>';
$this->assertSession()
->elementContains('css', 'ul.ui-autocomplete', $suggestion);
}
}
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