Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -18,35 +18,35 @@ class Toolbar extends RenderElement {
*/
public function getInfo() {
$class = get_class($this);
return array(
'#pre_render' => array(
array($class, 'preRenderToolbar'),
),
return [
'#pre_render' => [
[$class, 'preRenderToolbar'],
],
'#theme' => 'toolbar',
'#attached' => array(
'library' => array(
'#attached' => [
'library' => [
'toolbar/toolbar',
),
),
],
],
// Metadata for the toolbar wrapping element.
'#attributes' => array(
'#attributes' => [
// The id cannot be simply "toolbar" or it will clash with the
// simpletest tests listing which produces a checkbox with attribute
// id="toolbar".
'id' => 'toolbar-administration',
'role' => 'group',
'aria-label' => $this->t('Site administration toolbar'),
),
],
// Metadata for the administration bar.
'#bar' => array(
'#bar' => [
'#heading' => $this->t('Toolbar items'),
'#attributes' => array(
'#attributes' => [
'id' => 'toolbar-bar',
'role' => 'navigation',
'aria-label' => $this->t('Toolbar items'),
),
),
);
],
],
];
}
/**
@ -68,7 +68,7 @@ class Toolbar extends RenderElement {
// toolbar presentation.
$breakpoints = static::breakpointManager()->getBreakpointsByGroup('toolbar');
if (!empty($breakpoints)) {
$media_queries = array();
$media_queries = [];
foreach ($breakpoints as $id => $breakpoint) {
$media_queries[$id] = $breakpoint->getMediaQuery();
}
@ -82,7 +82,7 @@ class Toolbar extends RenderElement {
// Allow for altering of hook_toolbar().
$module_handler->alter('toolbar', $items);
// Sort the children.
uasort($items, array('\Drupal\Component\Utility\SortArray', 'sortByWeightProperty'));
uasort($items, ['\Drupal\Component\Utility\SortArray', 'sortByWeightProperty']);
// Merge in the original toolbar values.
$element = array_merge($element, $items);

View file

@ -19,16 +19,16 @@ class ToolbarItem extends RenderElement {
*/
public function getInfo() {
$class = get_class($this);
return array(
'#pre_render' => array(
array($class, 'preRenderToolbarItem'),
),
'tab' => array(
return [
'#pre_render' => [
[$class, 'preRenderToolbarItem'],
],
'tab' => [
'#type' => 'link',
'#title' => NULL,
'#url' => Url::fromRoute('<front>'),
),
);
],
];
}
/**
@ -47,33 +47,33 @@ class ToolbarItem extends RenderElement {
$id = $element['#id'];
// Provide attributes for a toolbar item.
$attributes = array(
$attributes = [
'id' => $id,
);
];
// If tray content is present, markup the tray and its associated trigger.
if (!empty($element['tray'])) {
// Provide attributes necessary for trays.
$attributes += array(
$attributes += [
'data-toolbar-tray' => $id . '-tray',
'aria-owns' => $id . '-tray',
'role' => 'button',
'aria-pressed' => 'false',
);
];
// Merge in module-provided attributes.
$element['tab'] += array('#attributes' => array());
$element['tab'] += ['#attributes' => []];
$element['tab']['#attributes'] += $attributes;
$element['tab']['#attributes']['class'][] = 'trigger';
// Provide attributes for the tray theme wrapper.
$attributes = array(
$attributes = [
'id' => $id . '-tray',
'data-toolbar-tray' => $id . '-tray',
);
];
// Merge in module-provided attributes.
if (!isset($element['tray']['#wrapper_attributes'])) {
$element['tray']['#wrapper_attributes'] = array();
$element['tray']['#wrapper_attributes'] = [];
}
$element['tray']['#wrapper_attributes'] += $attributes;
$element['tray']['#wrapper_attributes']['class'][] = 'toolbar-tray';

View file

@ -15,7 +15,7 @@ class ToolbarMenuLinkTree extends MenuLinkTree {
public function build(array $tree, $level = 0) {
if ($level == 0) {
if (!$tree) {
return array();
return [];
}
$build = parent::build($tree, $level);

View file

@ -53,12 +53,12 @@ class ToolbarAdminMenuTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('node', 'block', 'menu_ui', 'user', 'taxonomy', 'toolbar', 'language', 'test_page_test', 'locale');
public static $modules = ['node', 'block', 'menu_ui', 'user', 'taxonomy', 'toolbar', 'language', 'test_page_test', 'locale'];
protected function setUp() {
parent::setUp();
$perms = array(
$perms = [
'access toolbar',
'access administration pages',
'administer site configuration',
@ -75,7 +75,7 @@ class ToolbarAdminMenuTest extends WebTestBase {
'administer taxonomy',
'administer languages',
'translate interface',
);
];
// Create an administrative user and log it in.
$this->adminUser = $this->drupalCreateUser($perms);
@ -97,13 +97,13 @@ class ToolbarAdminMenuTest extends WebTestBase {
* Tests the toolbar_modules_installed() and toolbar_modules_uninstalled() hook
* implementations.
*/
function testModuleStatusChangeSubtreesHashCacheClear() {
public function testModuleStatusChangeSubtreesHashCacheClear() {
// Uninstall a module.
$edit = array();
$edit = [];
$edit['uninstall[taxonomy]'] = TRUE;
$this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
// Confirm the uninstall form.
$this->drupalPostForm(NULL, array(), t('Uninstall'));
$this->drupalPostForm(NULL, [], t('Uninstall'));
$this->rebuildContainer();
// Assert that the subtrees hash has been altered because the subtrees
@ -111,8 +111,8 @@ class ToolbarAdminMenuTest extends WebTestBase {
$this->assertDifferentHash();
// Enable a module.
$edit = array();
$edit['modules[Core][taxonomy][enable]'] = TRUE;
$edit = [];
$edit['modules[taxonomy][enable]'] = TRUE;
$this->drupalPostForm('admin/modules', $edit, t('Install'));
$this->rebuildContainer();
@ -124,12 +124,12 @@ class ToolbarAdminMenuTest extends WebTestBase {
/**
* Tests toolbar cache tags implementation.
*/
function testMenuLinkUpdateSubtreesHashCacheClear() {
public function testMenuLinkUpdateSubtreesHashCacheClear() {
// The ID of a (any) admin menu link.
$admin_menu_link_id = 'system.admin_config_development';
// Disable the link.
$edit = array();
$edit = [];
$edit['enabled'] = FALSE;
$this->drupalPostForm("admin/structure/menu/link/" . $admin_menu_link_id . "/edit", $edit, t('Save'));
$this->assertResponse(200);
@ -144,13 +144,13 @@ class ToolbarAdminMenuTest extends WebTestBase {
* Exercises the toolbar_user_role_update() and toolbar_user_update() hook
* implementations.
*/
function testUserRoleUpdateSubtreesHashCacheClear() {
public function testUserRoleUpdateSubtreesHashCacheClear() {
// Find the new role ID.
$all_rids = $this->adminUser->getRoles();
unset($all_rids[array_search(RoleInterface::AUTHENTICATED_ID, $all_rids)]);
$rid = reset($all_rids);
$edit = array();
$edit = [];
$edit[$rid . '[administer taxonomy]'] = FALSE;
$this->drupalPostForm('admin/people/permissions', $edit, t('Save permissions'));
@ -179,10 +179,10 @@ class ToolbarAdminMenuTest extends WebTestBase {
$this->hash = $this->getSubtreesHash();
$rid = $this->drupalCreateRole(array('administer content types',));
$rid = $this->drupalCreateRole(['administer content types']);
// Assign the role to the user.
$this->drupalPostForm('user/' . $this->adminUser->id() . '/edit', array("roles[$rid]" => $rid), t('Save'));
$this->drupalPostForm('user/' . $this->adminUser->id() . '/edit', ["roles[$rid]" => $rid], t('Save'));
$this->assertText(t('The changes have been saved.'));
// Assert that the subtrees hash has been altered because the subtrees
@ -208,13 +208,13 @@ class ToolbarAdminMenuTest extends WebTestBase {
* Tests that changes to a user account by another user clears the changed
* account's toolbar cached, not the user's who took the action.
*/
function testNonCurrentUserAccountUpdates() {
public function testNonCurrentUserAccountUpdates() {
$admin_user_id = $this->adminUser->id();
$this->hash = $this->getSubtreesHash();
// adminUser2 will add a role to adminUser.
$this->drupalLogin($this->adminUser2);
$rid = $this->drupalCreateRole(array('administer content types',));
$rid = $this->drupalCreateRole(['administer content types']);
// Get the subtree hash for adminUser2 to check later that it has not
// changed. Request a new page to refresh the drupalSettings object.
@ -223,7 +223,7 @@ class ToolbarAdminMenuTest extends WebTestBase {
$admin_user_2_hash = $this->getSubtreesHash();
// Assign the role to the user.
$this->drupalPostForm('user/' . $admin_user_id . '/edit', array("roles[$rid]" => $rid), t('Save'));
$this->drupalPostForm('user/' . $admin_user_id . '/edit', ["roles[$rid]" => $rid], t('Save'));
$this->assertText(t('The changes have been saved.'));
// Log in adminUser and assert that the subtrees hash has changed.
@ -243,10 +243,10 @@ class ToolbarAdminMenuTest extends WebTestBase {
/**
* Tests that toolbar cache is cleared when string translations are made.
*/
function testLocaleTranslationSubtreesHashCacheClear() {
public function testLocaleTranslationSubtreesHashCacheClear() {
$admin_user = $this->adminUser;
// User to translate and delete string.
$translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
$translate_user = $this->drupalCreateUser(['translate interface', 'access administration pages']);
// Create a new language with the langcode 'xx'.
$langcode = 'xx';
@ -257,14 +257,14 @@ class ToolbarAdminMenuTest extends WebTestBase {
// Add custom language.
$this->drupalLogin($admin_user);
$edit = array(
$edit = [
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
);
];
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
t($name, array(), array('langcode' => $langcode));
t($name, [], ['langcode' => $langcode]);
// Reset locale cache.
$this->container->get('string_translation')->reset();
$this->assertRaw('"edit-languages-' . $langcode . '-weight"', 'Language code found.');
@ -285,11 +285,11 @@ class ToolbarAdminMenuTest extends WebTestBase {
// should create a new menu hash if the toolbar subtrees cache is correctly
// invalidated.
$this->drupalLogin($translate_user);
$search = array(
$search = [
'string' => 'Search and metadata',
'langcode' => $langcode,
'translation' => 'untranslated',
);
];
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this->assertNoText(t('No strings available'));
$this->assertText($name, 'Search found the string as untranslated.');
@ -298,9 +298,9 @@ class ToolbarAdminMenuTest extends WebTestBase {
// Translate the string to a random string.
$textarea = current($this->xpath('//textarea'));
$lid = (string) $textarea[0]['name'];
$edit = array(
$edit = [
$lid => $translation,
);
];
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
$this->assertText(t('The strings have been saved.'), 'The strings have been saved.');
$this->assertUrl(\Drupal::url('locale.translate_page', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
@ -324,7 +324,7 @@ class ToolbarAdminMenuTest extends WebTestBase {
/**
* Tests that the 'toolbar/subtrees/{hash}' is reachable and correct.
*/
function testSubtreesJsonRequest() {
public function testSubtreesJsonRequest() {
$admin_user = $this->adminUser;
$this->drupalLogin($admin_user);
// Request a new page to refresh the drupalSettings object.
@ -339,7 +339,7 @@ class ToolbarAdminMenuTest extends WebTestBase {
/**
* Test that subtrees hashes vary by the language of the page.
*/
function testLanguageSwitching() {
public function testLanguageSwitching() {
// Create a new language with the langcode 'xx'.
$langcode = 'xx';
$language = ConfigurableLanguage::createFromLangcode($langcode);
@ -350,7 +350,7 @@ class ToolbarAdminMenuTest extends WebTestBase {
$this->rebuildContainer();
// Get a page with the new language langcode in the URL.
$this->drupalGet('test-page', array('language' => $language));
$this->drupalGet('test-page', ['language' => $language]);
// Assert different hash.
$new_subtree_hash = $this->getSubtreesHash();

View file

@ -23,20 +23,20 @@ class ToolbarMenuTranslationTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('toolbar', 'toolbar_test', 'locale', 'locale_test');
public static $modules = ['toolbar', 'toolbar_test', 'locale', 'locale_test'];
protected function setUp() {
parent::setUp();
// Create an administrative user and log it in.
$this->adminUser = $this->drupalCreateUser(array('access toolbar', 'translate interface', 'administer languages', 'access administration pages'));
$this->adminUser = $this->drupalCreateUser(['access toolbar', 'translate interface', 'administer languages', 'access administration pages']);
$this->drupalLogin($this->adminUser);
}
/**
* Tests that toolbar classes don't change when adding a translation.
*/
function testToolbarClasses() {
public function testToolbarClasses() {
$langcode = 'es';
// Add Spanish.
@ -50,11 +50,11 @@ class ToolbarMenuTranslationTest extends WebTestBase {
$this->drupalGet($langcode . '/admin/structure');
// Search for the menu item.
$search = array(
$search = [
'string' => $menu_item,
'langcode' => $langcode,
'translation' => 'untranslated',
);
];
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
// Make sure will be able to translate the menu item.
$this->assertNoText('No strings available.', 'Search found the menu item as untranslated.');
@ -67,17 +67,17 @@ class ToolbarMenuTranslationTest extends WebTestBase {
$menu_item_translated = $this->randomMachineName();
$textarea = current($this->xpath('//textarea'));
$lid = (string) $textarea[0]['name'];
$edit = array(
$edit = [
$lid => $menu_item_translated,
);
];
$this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
// Search for the translated menu item.
$search = array(
$search = [
'string' => $menu_item,
'langcode' => $langcode,
'translation' => 'translated',
);
];
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
// Make sure the menu item string was translated.
$this->assertText($menu_item_translated, 'Search found the menu item as translated: ' . $menu_item_translated . '.');

View file

@ -12,38 +12,38 @@ use Drupal\Core\Url;
*/
function toolbar_test_toolbar() {
$items['testing'] = array(
$items['testing'] = [
'#type' => 'toolbar_item',
'tab' => array(
'tab' => [
'#type' => 'link',
'#title' => t('Test tab'),
'#url' => Url::fromRoute('<front>'),
'#options' => array(
'attributes' => array(
'#options' => [
'attributes' => [
'id' => 'toolbar-tab-testing',
'title' => t('Test tab'),
),
),
),
'tray' => array(
],
],
],
'tray' => [
'#heading' => t('Test tray'),
'#wrapper_attributes' => array(
'#wrapper_attributes' => [
'id' => 'toolbar-tray-testing',
),
'content' => array(
],
'content' => [
'#theme' => 'item_list',
'#items' => array(
\Drupal::l(t('link 1'), new Url('<front>', [], array('attributes' => array('title' => 'Test link 1 title')))),
\Drupal::l(t('link 2'), new Url('<front>', [], array('attributes' => array('title' => 'Test link 2 title')))),
\Drupal::l(t('link 3'), new Url('<front>', [], array('attributes' => array('title' => 'Test link 3 title')))),
),
'#attributes' => array(
'class' => array('toolbar-menu'),
),
),
),
'#items' => [
\Drupal::l(t('link 1'), new Url('<front>', [], ['attributes' => ['title' => 'Test link 1 title']])),
\Drupal::l(t('link 2'), new Url('<front>', [], ['attributes' => ['title' => 'Test link 2 title']])),
\Drupal::l(t('link 3'), new Url('<front>', [], ['attributes' => ['title' => 'Test link 3 title']])),
],
'#attributes' => [
'class' => ['toolbar-menu'],
],
],
],
'#weight' => 50,
);
];
return $items;
}

View file

@ -1,15 +1,15 @@
<?php
namespace Drupal\toolbar\Tests;
namespace Drupal\Tests\toolbar\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the implementation of hook_toolbar() by a module.
*
* @group toolbar
*/
class ToolbarHookToolbarTest extends WebTestBase {
class ToolbarHookToolbarTest extends BrowserTestBase {
/**
* A user with permission to access the administrative toolbar.
@ -23,20 +23,20 @@ class ToolbarHookToolbarTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('toolbar', 'toolbar_test', 'test_page_test');
public static $modules = ['toolbar', 'toolbar_test', 'test_page_test'];
protected function setUp() {
parent::setUp();
// Create an administrative user and log it in.
$this->adminUser = $this->drupalCreateUser(array('access toolbar'));
$this->adminUser = $this->drupalCreateUser(['access toolbar']);
$this->drupalLogin($this->adminUser);
}
/**
* Tests for a tab and tray provided by a module implementing hook_toolbar().
*/
function testHookToolbar() {
public function testHookToolbar() {
$this->drupalGet('test-page');
$this->assertResponse(200);

View file

@ -45,45 +45,45 @@ use Drupal\Core\Url;
* @ingroup toolbar_tabs
*/
function hook_toolbar() {
$items = array();
$items = [];
// Add a search field to the toolbar. The search field employs no toolbar
// module theming functions.
$items['global_search'] = array(
$items['global_search'] = [
'#type' => 'toolbar_item',
'tab' => array(
'tab' => [
'#type' => 'search',
'#attributes' => array(
'#attributes' => [
'placeholder' => t('Search the site'),
'class' => array('search-global'),
),
),
'class' => ['search-global'],
],
],
'#weight' => 200,
// Custom CSS, JS or a library can be associated with the toolbar item.
'#attached' => array(
'library' => array(
'#attached' => [
'library' => [
'search/global',
),
),
);
],
],
];
// The 'Home' tab is a simple link, which is wrapped in markup associated
// with a visual tab styling.
$items['home'] = array(
$items['home'] = [
'#type' => 'toolbar_item',
'tab' => array(
'tab' => [
'#type' => 'link',
'#title' => t('Home'),
'#url' => Url::fromRoute('<front>'),
'#options' => array(
'attributes' => array(
'#options' => [
'attributes' => [
'title' => t('Home page'),
'class' => array('toolbar-icon', 'toolbar-icon-home'),
),
),
),
'class' => ['toolbar-icon', 'toolbar-icon-home'],
],
],
],
'#weight' => -20,
);
];
// A tray may be associated with a tab.
//
@ -93,27 +93,27 @@ function hook_toolbar() {
// The tray should contain a renderable array. An optional #heading property
// can be passed. This text is written to a heading tag in the tray as a
// landmark for accessibility.
$items['commerce'] = array(
$items['commerce'] = [
'#type' => 'toolbar_item',
'tab' => array(
'tab' => [
'#type' => 'link',
'#title' => t('Shopping cart'),
'#url' => Url::fromRoute('cart'),
'#options' => array(
'attributes' => array(
'#options' => [
'attributes' => [
'title' => t('Shopping cart'),
),
),
),
'tray' => array(
],
],
],
'tray' => [
'#heading' => t('Shopping cart actions'),
'shopping_cart' => array(
'shopping_cart' => [
'#theme' => 'item_list',
'#items' => array( /* An item list renderable array */ ),
),
),
'#items' => [ /* An item list renderable array */ ],
],
],
'#weight' => 150,
);
];
// The tray can be used to render arbitrary content.
//
@ -123,28 +123,28 @@ function hook_toolbar() {
// If the default behavior and styling of a toolbar tray is not desired, one
// can render content to the toolbar element and apply custom theming and
// behaviors.
$items['user_messages'] = array(
$items['user_messages'] = [
// Include the toolbar_tab_wrapper to style the link like a toolbar tab.
// Exclude the theme wrapper if custom styling is desired.
'#type' => 'toolbar_item',
'tab' => array(
'tab' => [
'#type' => 'link',
'#theme' => 'user_message_toolbar_tab',
'#theme_wrappers' => array(),
'#theme_wrappers' => [],
'#title' => t('Messages'),
'#url' => Url::fromRoute('user.message'),
'#options' => array(
'attributes' => array(
'#options' => [
'attributes' => [
'title' => t('Messages'),
),
),
),
'tray' => array(
],
],
],
'tray' => [
'#heading' => t('User messages'),
'messages' => array(/* renderable content */),
),
'messages' => [/* renderable content */],
],
'#weight' => 125,
);
];
return $items;
}

View file

@ -20,7 +20,7 @@ function toolbar_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.toolbar':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Toolbar module provides a toolbar for site administrators, which displays tabs and trays provided by the Toolbar module itself and other modules. For more information, see the <a href=":toolbar_docs">online documentation for the Toolbar module</a>.', array(':toolbar_docs' => 'https://www.drupal.org/documentation/modules/toolbar')) . '</p>';
$output .= '<p>' . t('The Toolbar module provides a toolbar for site administrators, which displays tabs and trays provided by the Toolbar module itself and other modules. For more information, see the <a href=":toolbar_docs">online documentation for the Toolbar module</a>.', [':toolbar_docs' => 'https://www.drupal.org/documentation/modules/toolbar']) . '</p>';
$output .= '<h4>' . t('Terminology') . '</h4>';
$output .= '<dl>';
$output .= '<dt>' . t('Tabs') . '</dt>';
@ -36,13 +36,13 @@ function toolbar_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_theme().
*/
function toolbar_theme($existing, $type, $theme, $path) {
$items['toolbar'] = array(
$items['toolbar'] = [
'render element' => 'element',
);
$items['menu__toolbar'] = array(
];
$items['menu__toolbar'] = [
'base hook' => 'menu',
'variables' => array('items' => array(), 'attributes' => array()),
);
'variables' => ['items' => [], 'attributes' => []],
];
return $items;
}
@ -53,14 +53,14 @@ function toolbar_theme($existing, $type, $theme, $path) {
* Add admin toolbar to the top of the page automatically.
*/
function toolbar_page_top(array &$page_top) {
$page_top['toolbar'] = array(
$page_top['toolbar'] = [
'#type' => 'toolbar',
'#access' => \Drupal::currentUser()->hasPermission('access toolbar'),
'#cache' => [
'keys' => ['toolbar'],
'contexts' => ['user.permissions'],
],
);
];
}
/**
@ -83,9 +83,9 @@ function template_preprocess_toolbar(&$variables) {
// Prepare the trays and tabs for each toolbar item as well as the remainder
// variable that will hold any non-tray, non-tab elements.
$variables['trays'] = array();
$variables['tabs'] = array();
$variables['remainder'] = array();
$variables['trays'] = [];
$variables['tabs'] = [];
$variables['remainder'] = [];
foreach (Element::children($element) as $key) {
// Early rendering to collect the wrapper attributes from
// ToolbarItem elements.
@ -94,14 +94,14 @@ function template_preprocess_toolbar(&$variables) {
}
// Add the tray.
if (isset($element[$key]['tray'])) {
$attributes = array();
$attributes = [];
if (!empty($element[$key]['tray']['#wrapper_attributes'])) {
$attributes = $element[$key]['tray']['#wrapper_attributes'];
}
$variables['trays'][$key] = array(
$variables['trays'][$key] = [
'links' => $element[$key]['tray'],
'attributes' => new Attribute($attributes),
);
];
if (array_key_exists('#heading', $element[$key]['tray'])) {
$variables['trays'][$key]['label'] = $element[$key]['tray']['#heading'];
}
@ -109,22 +109,22 @@ function template_preprocess_toolbar(&$variables) {
// Add the tab.
if (isset($element[$key]['tab'])) {
$attributes = array();
$attributes = [];
// Pass the wrapper attributes along.
if (!empty($element[$key]['#wrapper_attributes'])) {
$attributes = $element[$key]['#wrapper_attributes'];
}
$variables['tabs'][$key] = array(
$variables['tabs'][$key] = [
'link' => $element[$key]['tab'],
'attributes' => new Attribute($attributes),
);
];
}
// Add other non-tray, non-tab child elements to the remainder variable for
// later rendering.
foreach (Element::children($element[$key]) as $child_key) {
if (!in_array($child_key, array('tray', 'tab'))) {
if (!in_array($child_key, ['tray', 'tab'])) {
$variables['remainder'][$key][$child_key] = $element[$key][$child_key];
}
}
@ -136,28 +136,28 @@ function template_preprocess_toolbar(&$variables) {
*/
function toolbar_toolbar() {
// The 'Home' tab is a simple link, with no corresponding tray.
$items['home'] = array(
$items['home'] = [
'#type' => 'toolbar_item',
'tab' => array(
'tab' => [
'#type' => 'link',
'#title' => t('Back to site'),
'#url' => Url::fromRoute('<front>'),
'#attributes' => array(
'#attributes' => [
'title' => t('Return to site content'),
'class' => array('toolbar-icon', 'toolbar-icon-escape-admin'),
'class' => ['toolbar-icon', 'toolbar-icon-escape-admin'],
'data-toolbar-escape-admin' => TRUE,
),
),
'#wrapper_attributes' => array(
'class' => array('hidden', 'home-toolbar-tab'),
),
'#attached' => array(
'library' => array(
],
],
'#wrapper_attributes' => [
'class' => ['hidden', 'home-toolbar-tab'],
],
'#attached' => [
'library' => [
'toolbar/toolbar.escapeAdmin',
),
),
],
],
'#weight' => -20,
);
];
// To conserve bandwidth, we only include the top-level links in the HTML.
// The subtrees are fetched through a JSONP script that is generated at the
@ -171,38 +171,38 @@ function toolbar_toolbar() {
// The administration element has a link that is themed to correspond to
// a toolbar tray. The tray contains the full administrative menu of the site.
$items['administration'] = array(
$items['administration'] = [
'#type' => 'toolbar_item',
'tab' => array(
'tab' => [
'#type' => 'link',
'#title' => t('Manage'),
'#url' => Url::fromRoute('system.admin'),
'#attributes' => array(
'#attributes' => [
'title' => t('Admin menu'),
'class' => array('toolbar-icon', 'toolbar-icon-menu'),
'class' => ['toolbar-icon', 'toolbar-icon-menu'],
// A data attribute that indicates to the client to defer loading of
// the admin menu subtrees until this tab is activated. Admin menu
// subtrees will not render to the DOM if this attribute is removed.
// The value of the attribute is intentionally left blank. Only the
// presence of the attribute is necessary.
'data-drupal-subtrees' => '',
),
),
'tray' => array(
],
],
'tray' => [
'#heading' => t('Administration menu'),
'#attached' => $subtrees_attached,
'toolbar_administration' => array(
'#pre_render' => array(
'toolbar_administration' => [
'#pre_render' => [
'toolbar_prerender_toolbar_administration_tray',
),
],
'#type' => 'container',
'#attributes' => array(
'class' => array('toolbar-menu-administration'),
),
),
),
'#attributes' => [
'class' => ['toolbar-menu-administration'],
],
],
],
'#weight' => -15,
);
];
$hash_cacheability->applyTo($items['administration']);
return $items;
@ -228,11 +228,11 @@ function toolbar_prerender_toolbar_administration_tray(array $element) {
$parameters->setMinDepth(2)->setMaxDepth(2)->onlyEnabledLinks();
// @todo Make the menu configurable in https://www.drupal.org/node/1869638.
$tree = $menu_tree->load('admin', $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
array('callable' => 'toolbar_menu_navigation_links'),
);
$manipulators = [
['callable' => 'menu.default_tree_manipulators:checkAccess'],
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
['callable' => 'toolbar_menu_navigation_links'],
];
$tree = $menu_tree->transform($tree, $manipulators);
$element['administration_menu'] = $menu_tree->build($tree);
return $element;
@ -262,7 +262,7 @@ function toolbar_menu_navigation_links(array $tree) {
$id = substr(Crypt::hashBase64($url->getUri()), 0, 16);
}
else {
$id = str_replace(array('.', '<', '>'), array('-', '', ''), $url->getRouteName());
$id = str_replace(['.', '<', '>'], ['-', '', ''], $url->getRouteName());
}
// Get the non-localized title to make the icon class.
@ -270,7 +270,7 @@ function toolbar_menu_navigation_links(array $tree) {
$element->options['attributes']['id'] = 'toolbar-link-' . $id;
$element->options['attributes']['class'][] = 'toolbar-icon';
$element->options['attributes']['class'][] = 'toolbar-icon-' . strtolower(str_replace(array('.', ' ', '_'), array('-', '-', '-'), $definition['id']));
$element->options['attributes']['class'][] = 'toolbar-icon-' . strtolower(str_replace(['.', ' ', '_'], ['-', '-', '-'], $definition['id']));
$element->options['attributes']['title'] = $link->getDescription();
}
return $tree;
@ -310,13 +310,13 @@ function _toolbar_do_get_rendered_subtrees(array $data) {
$parameters->setMinDepth(2)->setMaxDepth(4)->onlyEnabledLinks();
// @todo Make the menu configurable in https://www.drupal.org/node/1869638.
$tree = $menu_tree->load('admin', $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
array('callable' => 'toolbar_menu_navigation_links'),
);
$manipulators = [
['callable' => 'menu.default_tree_manipulators:checkAccess'],
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
['callable' => 'toolbar_menu_navigation_links'],
];
$tree = $menu_tree->transform($tree, $manipulators);
$subtrees = array();
$subtrees = [];
// Calculated the combined cacheability of all subtrees.
$cacheability = new CacheableMetadata();
foreach ($tree as $element) {
@ -333,7 +333,7 @@ function _toolbar_do_get_rendered_subtrees(array $data) {
// Many routes have dots as route name, while some special ones like <front>
// have <> characters in them.
$url = $link->getUrlObject();
$id = str_replace(array('.', '<', '>'), array('-', '', '' ), $url->isRouted() ? $url->getRouteName() : $url->getUri());
$id = str_replace(['.', '<', '>'], ['-', '', '' ], $url->isRouted() ? $url->getRouteName() : $url->getUri());
$subtrees[$id] = $output;
}