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

@ -21,7 +21,7 @@ class ShortcutController extends ControllerBase {
* The shortcut add form.
*/
public function addForm(ShortcutSetInterface $shortcut_set) {
$shortcut = $this->entityManager()->getStorage('shortcut')->create(array('shortcut_set' => $shortcut_set->id()));
$shortcut = $this->entityManager()->getStorage('shortcut')->create(['shortcut_set' => $shortcut_set->id()]);
return $this->entityFormBuilder()->getForm($shortcut, 'add');
}
@ -40,10 +40,10 @@ class ShortcutController extends ControllerBase {
try {
$shortcut->delete();
drupal_set_message($this->t('The shortcut %title has been deleted.', array('%title' => $label)));
drupal_set_message($this->t('The shortcut %title has been deleted.', ['%title' => $label]));
}
catch (\Exception $e) {
drupal_set_message($this->t('Unable to delete the shortcut for %title.', array('%title' => $label)), 'error');
drupal_set_message($this->t('Unable to delete the shortcut for %title.', ['%title' => $label]), 'error');
}
return $this->redirect('<front>');

View file

@ -55,20 +55,20 @@ class ShortcutSetController extends ControllerBase {
$link = $request->query->get('link');
$name = $request->query->get('name');
if (parse_url($link, PHP_URL_SCHEME) === NULL && $this->pathValidator->isValid($link)) {
$shortcut = $this->entityManager()->getStorage('shortcut')->create(array(
$shortcut = $this->entityManager()->getStorage('shortcut')->create([
'title' => $name,
'shortcut_set' => $shortcut_set->id(),
'link' => array(
'link' => [
'uri' => 'internal:/' . $link,
),
));
],
]);
try {
$shortcut->save();
drupal_set_message($this->t('Added a shortcut for %title.', array('%title' => $shortcut->label())));
drupal_set_message($this->t('Added a shortcut for %title.', ['%title' => $shortcut->label()]));
}
catch (\Exception $e) {
drupal_set_message($this->t('Unable to add a shortcut for %title.', array('%title' => $shortcut->label())), 'error');
drupal_set_message($this->t('Unable to add a shortcut for %title.', ['%title' => $shortcut->label()]), 'error');
}
return $this->redirect('<front>');

View file

@ -123,13 +123,13 @@ class Shortcut extends ContentEntityBase implements ShortcutInterface {
->setRequired(TRUE)
->setTranslatable(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('form', array(
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -10,
'settings' => array(
'settings' => [
'size' => 40,
),
));
],
]);
$fields['weight'] = BaseFieldDefinition::create('integer')
->setLabel(t('Weight'))
@ -139,14 +139,14 @@ class Shortcut extends ContentEntityBase implements ShortcutInterface {
->setLabel(t('Path'))
->setDescription(t('The location this shortcut points to.'))
->setRequired(TRUE)
->setSettings(array(
->setSettings([
'link_type' => LinkItemInterface::LINK_INTERNAL,
'title' => DRUPAL_DISABLED,
))
->setDisplayOptions('form', array(
])
->setDisplayOptions('form', [
'type' => 'link_default',
'weight' => 0,
))
])
->setDisplayConfigurable('form', TRUE);
return $fields;

View file

@ -116,8 +116,8 @@ class ShortcutSet extends ConfigEntityBundleBase implements ShortcutSetInterface
* {@inheritdoc}
*/
public function getShortcuts() {
$shortcuts = \Drupal::entityManager()->getStorage('shortcut')->loadByProperties(array('shortcut_set' => $this->id()));
uasort($shortcuts, array('\Drupal\shortcut\Entity\Shortcut', 'sort'));
$shortcuts = \Drupal::entityManager()->getStorage('shortcut')->loadByProperties(['shortcut_set' => $this->id()]);
uasort($shortcuts, ['\Drupal\shortcut\Entity\Shortcut', 'sort']);
return $shortcuts;
}

View file

@ -23,24 +23,24 @@ class SetCustomize extends EntityForm {
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['shortcuts'] = array(
$form['shortcuts'] = [
'#tree' => TRUE,
'#weight' => -20,
);
];
$form['shortcuts']['links'] = array(
$form['shortcuts']['links'] = [
'#type' => 'table',
'#header' => array(t('Name'), t('Weight'), t('Operations')),
'#empty' => $this->t('No shortcuts available. <a href=":link">Add a shortcut</a>', array(':link' => $this->url('shortcut.link_add', array('shortcut_set' => $this->entity->id())))),
'#attributes' => array('id' => 'shortcuts'),
'#tabledrag' => array(
array(
'#header' => [t('Name'), t('Weight'), t('Operations')],
'#empty' => $this->t('No shortcuts available. <a href=":link">Add a shortcut</a>', [':link' => $this->url('shortcut.link_add', ['shortcut_set' => $this->entity->id()])]),
'#attributes' => ['id' => 'shortcuts'],
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'shortcut-weight',
),
),
);
],
],
];
foreach ($this->entity->getShortcuts() as $shortcut) {
$id = $shortcut->id();
@ -49,33 +49,33 @@ class SetCustomize extends EntityForm {
continue;
}
$form['shortcuts']['links'][$id]['#attributes']['class'][] = 'draggable';
$form['shortcuts']['links'][$id]['name'] = array(
$form['shortcuts']['links'][$id]['name'] = [
'#type' => 'link',
'#title' => $shortcut->getTitle(),
) + $url->toRenderArray();
] + $url->toRenderArray();
unset($form['shortcuts']['links'][$id]['name']['#access_callback']);
$form['shortcuts']['links'][$id]['#weight'] = $shortcut->getWeight();
$form['shortcuts']['links'][$id]['weight'] = array(
$form['shortcuts']['links'][$id]['weight'] = [
'#type' => 'weight',
'#title' => t('Weight for @title', array('@title' => $shortcut->getTitle())),
'#title' => t('Weight for @title', ['@title' => $shortcut->getTitle()]),
'#title_display' => 'invisible',
'#default_value' => $shortcut->getWeight(),
'#attributes' => array('class' => array('shortcut-weight')),
);
'#attributes' => ['class' => ['shortcut-weight']],
];
$links['edit'] = array(
$links['edit'] = [
'title' => t('Edit'),
'url' => $shortcut->urlInfo(),
);
$links['delete'] = array(
];
$links['delete'] = [
'title' => t('Delete'),
'url' => $shortcut->urlInfo('delete-form'),
);
$form['shortcuts']['links'][$id]['operations'] = array(
];
$form['shortcuts']['links'][$id]['operations'] = [
'#type' => 'operations',
'#links' => $links,
'#access' => $url->access(),
);
];
}
return $form;
}
@ -85,14 +85,14 @@ class SetCustomize extends EntityForm {
*/
protected function actions(array $form, FormStateInterface $form_state) {
// Only includes a Save action for the entity, no direct Delete button.
return array(
'submit' => array(
return [
'submit' => [
'#type' => 'submit',
'#value' => t('Save'),
'#access' => (bool) Element::getVisibleChildren($form['shortcuts']['links']),
'#submit' => array('::submitForm', '::save'),
),
);
'#submit' => ['::submitForm', '::save'],
],
];
}
/**
@ -100,7 +100,7 @@ class SetCustomize extends EntityForm {
*/
public function save(array $form, FormStateInterface $form_state) {
foreach ($this->entity->getShortcuts() as $shortcut) {
$weight = $form_state->getValue(array('shortcuts', 'links', $shortcut->id(), 'weight'));
$weight = $form_state->getValue(['shortcuts', 'links', $shortcut->id(), 'weight']);
$shortcut->setWeight($weight);
$shortcut->save();
}

View file

@ -21,9 +21,9 @@ class ShortcutDeleteForm extends ContentEntityDeleteForm {
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.shortcut_set.customize_form', array(
return new Url('entity.shortcut_set.customize_form', [
'shortcut_set' => $this->entity->bundle(),
));
]);
}
/**

View file

@ -65,9 +65,9 @@ class ShortcutSetDeleteForm extends EntityDeleteForm {
$info .= '<p>' . t('If you have chosen this shortcut set as the default for some or all users, they may also be affected by deleting it.') . '</p>';
}
$form['info'] = array(
$form['info'] = [
'#markup' => $info,
);
];
return parent::buildForm($form, $form_state);
}

View file

@ -77,60 +77,60 @@ class SwitchShortcutSet extends FormBase {
$account_is_user = $this->user->id() == $account->id();
if (count($options) > 1) {
$form['set'] = array(
$form['set'] = [
'#type' => 'radios',
'#title' => $account_is_user ? $this->t('Choose a set of shortcuts to use') : $this->t('Choose a set of shortcuts for this user'),
'#options' => $options,
'#default_value' => $current_set->id(),
);
];
$form['label'] = array(
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#description' => $this->t('The new set is created by copying items from your default shortcut set.'),
'#access' => $add_access,
'#states' => array(
'visible' => array(
':input[name="set"]' => array('value' => 'new'),
),
'required' => array(
':input[name="set"]' => array('value' => 'new'),
),
),
);
$form['id'] = array(
'#states' => [
'visible' => [
':input[name="set"]' => ['value' => 'new'],
],
'required' => [
':input[name="set"]' => ['value' => 'new'],
],
],
];
$form['id'] = [
'#type' => 'machine_name',
'#machine_name' => array(
'exists' => array($this, 'exists'),
'#machine_name' => [
'exists' => [$this, 'exists'],
'replace_pattern' => '[^a-z0-9-]+',
'replace' => '-',
),
],
// This ID could be used for menu name.
'#maxlength' => 23,
'#states' => array(
'required' => array(
':input[name="set"]' => array('value' => 'new'),
),
),
'#states' => [
'required' => [
':input[name="set"]' => ['value' => 'new'],
],
],
'#required' => FALSE,
);
];
if (!$account_is_user) {
$default_set = $this->shortcutSetStorage->getDefaultSet($this->user);
$form['new']['#description'] = $this->t('The new set is created by copying items from the %default set.', array('%default' => $default_set->label()));
$form['new']['#description'] = $this->t('The new set is created by copying items from the %default set.', ['%default' => $default_set->label()]);
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Change set'),
);
];
}
else {
// There is only 1 option, so output a message in the $form array.
$form['info'] = array(
'#markup' => '<p>' . $this->t('You are currently using the %set-name shortcut set.', array('%set-name' => $current_set->label())) . '</p>',
);
$form['info'] = [
'#markup' => '<p>' . $this->t('You are currently using the %set-name shortcut set.', ['%set-name' => $current_set->label()]) . '</p>',
];
}
return $form;
@ -173,16 +173,16 @@ class SwitchShortcutSet extends FormBase {
if ($form_state->getValue('set') == 'new') {
// Save a new shortcut set with links copied from the user's default set.
/* @var \Drupal\shortcut\Entity\ShortcutSet $set */
$set = $this->shortcutSetStorage->create(array(
$set = $this->shortcutSetStorage->create([
'id' => $form_state->getValue('id'),
'label' => $form_state->getValue('label'),
));
]);
$set->save();
$replacements = array(
$replacements = [
'%user' => $this->user->label(),
'%set_name' => $set->label(),
':switch-url' => $this->url('<current>'),
);
];
if ($account_is_user) {
// Only administrators can create new shortcut sets, so we know they have
// access to switch back.
@ -193,17 +193,17 @@ class SwitchShortcutSet extends FormBase {
}
$form_state->setRedirect(
'entity.shortcut_set.customize_form',
array('shortcut_set' => $set->id())
['shortcut_set' => $set->id()]
);
}
else {
// Switch to a different shortcut set.
/* @var \Drupal\shortcut\Entity\ShortcutSet $set */
$set = $this->shortcutSetStorage->load($form_state->getValue('set'));
$replacements = array(
$replacements = [
'%user' => $this->user->getDisplayName(),
'%set_name' => $set->label(),
);
];
drupal_set_message($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements));
}

View file

@ -21,9 +21,9 @@ class ShortcutsBlock extends BlockBase {
* {@inheritdoc}
*/
public function build() {
return array(
return [
shortcut_renderable_links(shortcut_current_displayed_set()),
);
];
}
/**

View file

@ -60,14 +60,14 @@ class ShortcutSetUsers extends DestinationBase implements ContainerFactoryPlugin
* {@inheritdoc}
*/
public function getIds() {
return array(
'set_name' => array(
return [
'set_name' => [
'type' => 'string',
),
'uid' => array(
],
'uid' => [
'type' => 'integer',
),
);
],
];
}
/**
@ -83,14 +83,14 @@ class ShortcutSetUsers extends DestinationBase implements ContainerFactoryPlugin
/**
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array()) {
public function import(Row $row, array $old_destination_id_values = []) {
/** @var \Drupal\shortcut\ShortcutSetInterface $set */
$set = $this->shortcutSetStorage->load($row->getDestinationProperty('set_name'));
/** @var \Drupal\user\UserInterface $account */
$account = User::load($row->getDestinationProperty('uid'));
$this->shortcutSetStorage->assignUser($set, $account);
return array($set->id(), $account->id());
return [$set->id(), $account->id()];
}
}

View file

@ -19,7 +19,7 @@ class Shortcut extends DrupalSqlBase {
*/
public function query() {
return $this->select('menu_links', 'ml')
->fields('ml', array('mlid', 'menu_name', 'link_path', 'link_title', 'weight'))
->fields('ml', ['mlid', 'menu_name', 'link_path', 'link_title', 'weight'])
->condition('hidden', '0')
->condition('menu_name', 'shortcut-set-%', 'LIKE')
->orderBy('ml.mlid');
@ -29,13 +29,13 @@ class Shortcut extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
return array(
return [
'mlid' => $this->t("The menu.mlid primary key for this menu item (= shortcut link)."),
'menu_name' => $this->t("The menu_name (= set name) for this shortcut link."),
'link_path' => $this->t("The link for this shortcut."),
'link_title' => $this->t("The title for this shortcut."),
'weight' => $this->t("The weight for this shortcut"),
);
];
}
/**

View file

@ -25,10 +25,10 @@ class ShortcutSet extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
return array(
return [
'set_name' => $this->t("The name under which the set's links are stored."),
'title' => $this->t("The title of the set."),
);
];
}
/**

View file

@ -25,24 +25,24 @@ class ShortcutSetUsers extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
return array(
return [
'uid' => $this->t('The users.uid for this set.'),
'set_name' => $this->t('The shortcut_set.set_name that will be displayed for this user.'),
);
];
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array(
'set_name' => array(
return [
'set_name' => [
'type' => 'string',
),
'uid' => array(
],
'uid' => [
'type' => 'integer',
),
);
],
];
}
}

View file

@ -35,16 +35,16 @@ class ShortcutForm extends ContentEntityForm {
}
if ($status == SAVED_UPDATED) {
$message = $this->t('The shortcut %link has been updated.', array('%link' => $view_link));
$message = $this->t('The shortcut %link has been updated.', ['%link' => $view_link]);
}
else {
$message = $this->t('Added a shortcut for %title.', array('%title' => $view_link));
$message = $this->t('Added a shortcut for %title.', ['%title' => $view_link]);
}
drupal_set_message($message);
$form_state->setRedirect(
'entity.shortcut_set.customize_form',
array('shortcut_set' => $entity->bundle())
['shortcut_set' => $entity->bundle()]
);
}

View file

@ -17,25 +17,25 @@ class ShortcutSetForm extends BundleEntityFormBase {
$form = parent::form($form, $form_state);
$entity = $this->entity;
$form['label'] = array(
$form['label'] = [
'#type' => 'textfield',
'#title' => t('Set name'),
'#description' => t('The new set is created by copying items from your default shortcut set.'),
'#required' => TRUE,
'#default_value' => $entity->label(),
);
$form['id'] = array(
];
$form['id'] = [
'#type' => 'machine_name',
'#machine_name' => array(
'#machine_name' => [
'exists' => '\Drupal\shortcut\Entity\ShortcutSet::load',
'source' => array('label'),
'source' => ['label'],
'replace_pattern' => '[^a-z0-9-]+',
'replace' => '-',
),
],
'#default_value' => $entity->id(),
// This id could be used for menu name.
'#maxlength' => 23,
);
];
$form['actions']['submit']['#value'] = t('Create new set');
@ -51,10 +51,10 @@ class ShortcutSetForm extends BundleEntityFormBase {
$entity->save();
if ($is_new) {
drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', array('%set_name' => $entity->label())));
drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', ['%set_name' => $entity->label()]));
}
else {
drupal_set_message(t('Updated set name to %set-name.', array('%set-name' => $entity->label())));
drupal_set_message(t('Updated set name to %set-name.', ['%set-name' => $entity->label()]));
}
$form_state->setRedirectUrl($this->entity->urlInfo('customize-form'));
}

View file

@ -30,10 +30,10 @@ class ShortcutSetListBuilder extends ConfigEntityListBuilder {
$operations['edit']['title'] = t('Edit shortcut set');
}
$operations['list'] = array(
$operations['list'] = [
'title' => t('List links'),
'url' => $entity->urlInfo('customize-form'),
);
];
return $operations;
}

View file

@ -73,7 +73,7 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
db_merge('shortcut_set_users')
->key('uid', $account->id())
->fields(array('set_name' => $shortcut_set->id()))
->fields(['set_name' => $shortcut_set->id()])
->execute();
drupal_static_reset('shortcut_current_displayed_set');
}
@ -93,7 +93,7 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
*/
public function getAssignedToUser($account) {
$query = db_select('shortcut_set_users', 'ssu');
$query->fields('ssu', array('set_name'));
$query->fields('ssu', ['set_name']);
$query->condition('ssu.uid', $account->id());
return $query->execute()->fetchField();
}
@ -102,7 +102,7 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
* {@inheritdoc}
*/
public function countAssignedUsers(ShortcutSetInterface $shortcut_set) {
return db_query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $shortcut_set->id()))->fetchField();
return db_query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', [':name' => $shortcut_set->id()])->fetchField();
}
/**
@ -113,7 +113,7 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
// have one, we allow the last module which returns a valid result to take
// precedence. If no module returns a valid set, fall back on the site-wide
// default, which is the lowest-numbered shortcut set.
$suggestions = array_reverse($this->moduleHandler->invokeAll('shortcut_default_set', array($account)));
$suggestions = array_reverse($this->moduleHandler->invokeAll('shortcut_default_set', [$account]));
$suggestions[] = 'default';
$shortcut_set = NULL;
foreach ($suggestions as $name) {

View file

@ -1,71 +0,0 @@
<?php
namespace Drupal\shortcut\Tests;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\system\Tests\Entity\EntityCacheTagsTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests the Shortcut entity's cache tags.
*
* @group shortcut
*/
class ShortcutCacheTagsTest extends EntityCacheTagsTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('shortcut');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Give anonymous users permission to customize shortcut links, so that we
// can verify the cache tags of cached versions of shortcuts.
$user_role = Role::load(RoleInterface::ANONYMOUS_ID);
$user_role->grantPermission('customize shortcut links');
$user_role->grantPermission('access shortcuts');
$user_role->save();
}
/**
* {@inheritdoc}
*/
protected function createEntity() {
// Create a "Llama" shortcut.
$shortcut = Shortcut::create(array(
'shortcut_set' => 'default',
'title' => t('Llama'),
'weight' => 0,
'link' => [['uri' => 'internal:/admin']],
));
$shortcut->save();
return $shortcut;
}
/**
* Tests that when creating a shortcut, the shortcut set tag is invalidated.
*/
public function testEntityCreation() {
// Create a cache entry that is tagged with a shortcut set cache tag.
$cache_tags = ['config:shortcut.set.default'];
\Drupal::cache('render')->set('foo', 'bar', CacheBackendInterface::CACHE_PERMANENT, $cache_tags);
// Verify a cache hit.
$this->verifyRenderCache('foo', $cache_tags);
// Now create a shortcut entity in that shortcut set.
$this->createEntity();
// Verify a cache miss.
$this->assertFalse(\Drupal::cache('render')->get('foo'), 'Creating a new shortcut invalidates the cache tag of the shortcut set.');
}
}

View file

@ -22,7 +22,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
*
* @var array
*/
public static $modules = array('router_test', 'views', 'block');
public static $modules = ['router_test', 'views', 'block'];
/**
* {@inheritdoc}
@ -40,10 +40,10 @@ class ShortcutLinksTest extends ShortcutTestBase {
$set = $this->set;
// Create an alias for the node so we can test aliases.
$path = array(
$path = [
'source' => '/node/' . $this->node->id(),
'alias' => '/' . $this->randomMachineName(8),
);
];
$this->container->get('path.alias_storage')->save($path['source'], $path['alias']);
// Create some paths to test.
@ -65,13 +65,13 @@ class ShortcutLinksTest extends ShortcutTestBase {
// Check that each new shortcut links where it should.
foreach ($test_cases as $test_path) {
$title = $this->randomMachineName();
$form_data = array(
$form_data = [
'title[0][value]' => $title,
'link[0][uri]' => $test_path,
);
];
$this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
$this->assertResponse(200);
$this->assertText(t('Added a shortcut for @title.', array('@title' => $title)));
$this->assertText(t('Added a shortcut for @title.', ['@title' => $title]));
$saved_set = ShortcutSet::load($set->id());
$paths = $this->getShortcutInformation($saved_set, 'link');
$this->assertTrue(in_array('internal:' . $test_path, $paths), 'Shortcut created: ' . $test_path);
@ -115,10 +115,10 @@ class ShortcutLinksTest extends ShortcutTestBase {
// Create a new shortcut set and add a link to it.
$this->drupalLogin($this->adminUser);
$edit = array(
$edit = [
'label' => $this->randomMachineName(),
'id' => strtolower($this->randomMachineName()),
);
];
$this->drupalPostForm('admin/config/user-interface/shortcut/add-set', $edit, t('Save'));
$title = $this->randomMachineName();
$form_data = [
@ -133,7 +133,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
* Tests that the "add to shortcut" and "remove from shortcut" links work.
*/
public function testShortcutQuickLink() {
\Drupal::service('theme_handler')->install(array('seven'));
\Drupal::service('theme_handler')->install(['seven']);
$this->config('system.theme')->set('admin', 'seven')->save();
$this->config('node.settings')->set('use_admin_theme', '1')->save();
$this->container->get('router.builder')->rebuild();
@ -177,7 +177,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
$this->assertText('Added a shortcut for Create Basic page.');
// Assure that Article does not have its shortcut indicated as set.
$this->drupalGet('node/add/article');
$link = $this->xpath('//a[normalize-space()=:label]', array(':label' => 'Remove from Default shortcuts'));
$link = $this->xpath('//a[normalize-space()=:label]', [':label' => 'Remove from Default shortcuts']);
$this->assertTrue(empty($link), 'Link Remove to Default shortcuts not found for Create Article page.');
// Add Shortcut for Article.
$this->clickLink('Add to Default shortcuts');
@ -198,11 +198,11 @@ class ShortcutLinksTest extends ShortcutTestBase {
$this->assertShortcutQuickLink('Add to Default shortcuts');
\Drupal::service('module_installer')->install(['block_content']);
BlockContentType::create(array(
BlockContentType::create([
'id' => 'basic',
'label' => 'Basic block',
'revision' => FALSE,
))->save();
])->save();
// Test page with HTML tags in title.
$this->drupalGet('admin/structure/block/block-content/manage/basic');
$page_title = new FormattableMarkup('Edit %label custom block type', ['%label' => 'Basic block']);
@ -226,12 +226,12 @@ class ShortcutLinksTest extends ShortcutTestBase {
$shortcuts = $set->getShortcuts();
$shortcut = reset($shortcuts);
$this->drupalPostForm('admin/config/user-interface/shortcut/link/' . $shortcut->id(), array('title[0][value]' => $new_link_name), t('Save'));
$this->drupalPostForm('admin/config/user-interface/shortcut/link/' . $shortcut->id(), ['title[0][value]' => $new_link_name], t('Save'));
$saved_set = ShortcutSet::load($set->id());
$titles = $this->getShortcutInformation($saved_set, 'title');
$this->assertTrue(in_array($new_link_name, $titles), 'Shortcut renamed: ' . $new_link_name);
$this->assertLink($new_link_name, 0, 'Renamed shortcut link appears on the page.');
$this->assertText(t('The shortcut @link has been updated.', array('@link' => $new_link_name)));
$this->assertText(t('The shortcut @link has been updated.', ['@link' => $new_link_name]));
}
/**
@ -245,12 +245,12 @@ class ShortcutLinksTest extends ShortcutTestBase {
$shortcuts = $set->getShortcuts();
$shortcut = reset($shortcuts);
$this->drupalPostForm('admin/config/user-interface/shortcut/link/' . $shortcut->id(), array('title[0][value]' => $shortcut->getTitle(), 'link[0][uri]' => $new_link_path), t('Save'));
$this->drupalPostForm('admin/config/user-interface/shortcut/link/' . $shortcut->id(), ['title[0][value]' => $shortcut->getTitle(), 'link[0][uri]' => $new_link_path], t('Save'));
$saved_set = ShortcutSet::load($set->id());
$paths = $this->getShortcutInformation($saved_set, 'link');
$this->assertTrue(in_array('internal:' . $new_link_path, $paths), 'Shortcut path changed: ' . $new_link_path);
$this->assertLinkByHref($new_link_path, 0, 'Shortcut with new path appears on the page.');
$this->assertText(t('The shortcut @link has been updated.', array('@link' => $shortcut->getTitle())));
$this->assertText(t('The shortcut @link has been updated.', ['@link' => $shortcut->getTitle()]));
}
/**
@ -277,7 +277,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
$shortcuts = $set->getShortcuts();
$shortcut = reset($shortcuts);
$this->drupalPostForm('admin/config/user-interface/shortcut/link/' . $shortcut->id() . '/delete', array(), 'Delete');
$this->drupalPostForm('admin/config/user-interface/shortcut/link/' . $shortcut->id() . '/delete', [], 'Delete');
$saved_set = ShortcutSet::load($set->id());
$ids = $this->getShortcutInformation($saved_set, 'id');
$this->assertFalse(in_array($shortcut->id(), $ids), 'Successfully deleted a shortcut.');
@ -297,7 +297,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
*/
public function testNoShortcutLink() {
// Change to a theme that displays shortcuts.
\Drupal::service('theme_handler')->install(array('seven'));
\Drupal::service('theme_handler')->install(['seven']);
$this->config('system.theme')
->set('default', 'seven')
->save();
@ -328,7 +328,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
*/
public function testAccessShortcutsPermission() {
// Change to a theme that displays shortcuts.
\Drupal::service('theme_handler')->install(array('seven'));
\Drupal::service('theme_handler')->install(['seven']);
$this->config('system.theme')
->set('default', 'seven')
->save();
@ -340,20 +340,20 @@ class ShortcutLinksTest extends ShortcutTestBase {
// Verify that users without the 'access shortcuts' permission can't see the
// shortcuts.
$this->drupalLogin($this->drupalCreateUser(array('access toolbar')));
$this->drupalLogin($this->drupalCreateUser(['access toolbar']));
$this->assertNoLink('Shortcuts', 'Shortcut link not found on page.');
// Verify that users without the 'administer site configuration' permission
// can't see the cron shortcuts.
$this->drupalLogin($this->drupalCreateUser(array('access toolbar', 'access shortcuts')));
$this->drupalLogin($this->drupalCreateUser(['access toolbar', 'access shortcuts']));
$this->assertNoLink('Shortcuts', 'Shortcut link not found on page.');
$this->assertNoLink('Cron', 'Cron shortcut link not found on page.');
// Verify that users with the 'access shortcuts' permission can see the
// shortcuts.
$this->drupalLogin($this->drupalCreateUser(array(
$this->drupalLogin($this->drupalCreateUser([
'access toolbar', 'access shortcuts', 'administer site configuration',
)));
]));
$this->clickLink('Shortcuts', 0, 'Shortcut link found on page.');
$this->assertLink('Cron', 0, 'Cron shortcut link found on page.');
@ -365,7 +365,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
*/
public function testShortcutLinkOrder() {
// Ensure to give permissions to access the shortcuts.
$this->drupalLogin($this->drupalCreateUser(array('access toolbar', 'access shortcuts', 'access content overview', 'administer content types')));
$this->drupalLogin($this->drupalCreateUser(['access toolbar', 'access shortcuts', 'access content overview', 'administer content types']));
$this->drupalGet(Url::fromRoute('<front>'));
$shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
$this->assertEqual((string) $shortcuts[0], 'Add content');
@ -386,24 +386,24 @@ class ShortcutLinksTest extends ShortcutTestBase {
private function verifyAccessShortcutsPermissionForEditPages() {
// Create a user with customize links and switch sets permissions but
// without the 'access shortcuts' permission.
$test_permissions = array(
$test_permissions = [
'customize shortcut links',
'switch shortcut sets',
);
];
$noaccess_user = $this->drupalCreateUser($test_permissions);
$this->drupalLogin($noaccess_user);
// Verify that set administration pages are inaccessible without the
// 'access shortcuts' permission.
$edit_paths = array(
$edit_paths = [
'admin/config/user-interface/shortcut/manage/default/customize',
'admin/config/user-interface/shortcut/manage/default',
'user/' . $noaccess_user->id() . '/shortcuts',
);
];
foreach ($edit_paths as $path) {
$this->drupalGet($path);
$message = format_string('Access is denied on %s', array('%s' => $path));
$message = format_string('Access is denied on %s', ['%s' => $path]);
$this->assertResponse(403, $message);
}
}
@ -426,7 +426,7 @@ class ShortcutLinksTest extends ShortcutTestBase {
// Verify that users without the 'access shortcuts' permission can see the
// shortcut block.
$this->drupalLogin($this->drupalCreateUser(array()));
$this->drupalLogin($this->drupalCreateUser([]));
$this->drupalGet('');
$this->assertNoBlockAppears($block);
}
@ -454,8 +454,8 @@ class ShortcutLinksTest extends ShortcutTestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertShortcutQuickLink($label, $index = 0, $message = '', $group = 'Other') {
$links = $this->xpath('//a[normalize-space()=:label]', array(':label' => $label));
$message = ($message ? $message : SafeMarkup::format('Shortcut quick link with label %label found.', array('%label' => $label)));
$links = $this->xpath('//a[normalize-space()=:label]', [':label' => $label]);
$message = ($message ? $message : SafeMarkup::format('Shortcut quick link with label %label found.', ['%label' => $label]));
return $this->assert(isset($links[$index]), $message, $group);
}

View file

@ -30,13 +30,13 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests creating a shortcut set.
*/
function testShortcutSetAdd() {
public function testShortcutSetAdd() {
$this->drupalGet('admin/config/user-interface/shortcut');
$this->clickLink(t('Add shortcut set'));
$edit = array(
$edit = [
'label' => $this->randomMachineName(),
'id' => strtolower($this->randomMachineName()),
);
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$new_set = $this->container->get('entity.manager')->getStorage('shortcut_set')->load($edit['id']);
$this->assertIdentical($new_set->id(), $edit['id'], 'Successfully created a shortcut set.');
@ -47,7 +47,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests editing a shortcut set.
*/
function testShortcutSetEdit() {
public function testShortcutSetEdit() {
$set = $this->set;
$shortcuts = $set->getShortcuts();
@ -66,14 +66,14 @@ class ShortcutSetsTest extends ShortcutTestBase {
$this->assertEqual(count($elements), 3, 'Correct number of table header cells found.');
// Test the contents of each th cell.
$expected_items = array(t('Name'), t('Weight'), t('Operations'));
$expected_items = [t('Name'), t('Weight'), t('Operations')];
foreach ($elements as $key => $element) {
$this->assertEqual((string) $element[0], $expected_items[$key]);
}
// Look for test shortcuts in the table.
$weight = count($shortcuts);
$edit = array();
$edit = [];
foreach ($shortcuts as $shortcut) {
$title = $shortcut->getTitle();
@ -100,12 +100,12 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests switching a user's own shortcut set.
*/
function testShortcutSetSwitchOwn() {
public function testShortcutSetSwitchOwn() {
$new_set = $this->generateShortcutSet($this->randomMachineName());
// Attempt to switch the default shortcut set to the newly created shortcut
// set.
$this->drupalPostForm('user/' . $this->adminUser->id() . '/shortcuts', array('set' => $new_set->id()), t('Change set'));
$this->drupalPostForm('user/' . $this->adminUser->id() . '/shortcuts', ['set' => $new_set->id()], t('Change set'));
$this->assertResponse(200);
$current_set = shortcut_current_displayed_set($this->adminUser);
$this->assertTrue($new_set->id() == $current_set->id(), 'Successfully switched own shortcut set.');
@ -114,7 +114,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests switching another user's shortcut set.
*/
function testShortcutSetAssign() {
public function testShortcutSetAssign() {
$new_set = $this->generateShortcutSet($this->randomMachineName());
\Drupal::entityManager()->getStorage('shortcut_set')->assignUser($new_set, $this->shortcutUser);
@ -125,12 +125,12 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests switching a user's shortcut set and creating one at the same time.
*/
function testShortcutSetSwitchCreate() {
$edit = array(
public function testShortcutSetSwitchCreate() {
$edit = [
'set' => 'new',
'id' => strtolower($this->randomMachineName()),
'label' => $this->randomString(),
);
];
$this->drupalPostForm('user/' . $this->adminUser->id() . '/shortcuts', $edit, t('Change set'));
$current_set = shortcut_current_displayed_set($this->adminUser);
$this->assertNotEqual($current_set->id(), $this->set->id(), 'A shortcut set can be switched to at the same time as it is created.');
@ -140,8 +140,8 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests switching a user's shortcut set without providing a new set name.
*/
function testShortcutSetSwitchNoSetName() {
$edit = array('set' => 'new');
public function testShortcutSetSwitchNoSetName() {
$edit = ['set' => 'new'];
$this->drupalPostForm('user/' . $this->adminUser->id() . '/shortcuts', $edit, t('Change set'));
$this->assertText(t('The new set label is required.'));
$current_set = shortcut_current_displayed_set($this->adminUser);
@ -152,13 +152,13 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests renaming a shortcut set.
*/
function testShortcutSetRename() {
public function testShortcutSetRename() {
$set = $this->set;
$new_label = $this->randomMachineName();
$this->drupalGet('admin/config/user-interface/shortcut');
$this->clickLink(t('Edit shortcut set'));
$this->drupalPostForm(NULL, array('label' => $new_label), t('Save'));
$this->drupalPostForm(NULL, ['label' => $new_label], t('Save'));
$set = ShortcutSet::load($set->id());
$this->assertTrue($set->label() == $new_label, 'Shortcut set has been successfully renamed.');
}
@ -166,7 +166,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests unassigning a shortcut set.
*/
function testShortcutSetUnassign() {
public function testShortcutSetUnassign() {
$new_set = $this->generateShortcutSet($this->randomMachineName());
$shortcut_set_storage = \Drupal::entityManager()->getStorage('shortcut_set');
@ -180,10 +180,10 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests deleting a shortcut set.
*/
function testShortcutSetDelete() {
public function testShortcutSetDelete() {
$new_set = $this->generateShortcutSet($this->randomMachineName());
$this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $new_set->id() . '/delete', array(), t('Delete'));
$this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $new_set->id() . '/delete', [], t('Delete'));
$sets = ShortcutSet::loadMultiple();
$this->assertFalse(isset($sets[$new_set->id()]), 'Successfully deleted a shortcut set.');
}
@ -191,7 +191,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests deleting the default shortcut set.
*/
function testShortcutSetDeleteDefault() {
public function testShortcutSetDeleteDefault() {
$this->drupalGet('admin/config/user-interface/shortcut/manage/default/delete');
$this->assertResponse(403);
}
@ -199,7 +199,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
/**
* Tests creating a new shortcut set with a defined set name.
*/
function testShortcutSetCreateWithSetName() {
public function testShortcutSetCreateWithSetName() {
$random_name = $this->randomMachineName();
$new_set = $this->generateShortcutSet($random_name, $random_name);
$sets = ShortcutSet::loadMultiple();

View file

@ -17,7 +17,7 @@ abstract class ShortcutTestBase extends WebTestBase {
*
* @var array
*/
public static $modules = array('node', 'toolbar', 'shortcut');
public static $modules = ['node', 'toolbar', 'shortcut'];
/**
* User with permission to administer shortcuts.
@ -52,37 +52,37 @@ abstract class ShortcutTestBase extends WebTestBase {
if ($this->profile != 'standard') {
// Create Basic page and Article node types.
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
// Populate the default shortcut set.
$shortcut = Shortcut::create(array(
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => -20,
'link' => array(
'link' => [
'uri' => 'internal:/node/add',
),
));
],
]);
$shortcut->save();
$shortcut = Shortcut::create(array(
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('All content'),
'weight' => -19,
'link' => array(
'link' => [
'uri' => 'internal:/admin/content',
),
));
],
]);
$shortcut->save();
}
// Create users.
$this->adminUser = $this->drupalCreateUser(array('access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview', 'administer users', 'link to any page', 'edit any article content'));
$this->shortcutUser = $this->drupalCreateUser(array('customize shortcut links', 'switch shortcut sets', 'access shortcuts', 'access content'));
$this->adminUser = $this->drupalCreateUser(['access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview', 'administer users', 'link to any page', 'edit any article content']);
$this->shortcutUser = $this->drupalCreateUser(['customize shortcut links', 'switch shortcut sets', 'access shortcuts', 'access content']);
// Create a node.
$this->node = $this->drupalCreateNode(array('type' => 'article'));
$this->node = $this->drupalCreateNode(['type' => 'article']);
// Log in as admin and grab the default shortcut set.
$this->drupalLogin($this->adminUser);
@ -93,11 +93,11 @@ abstract class ShortcutTestBase extends WebTestBase {
/**
* Creates a generic shortcut set.
*/
function generateShortcutSet($label = '', $id = NULL) {
$set = ShortcutSet::create(array(
public function generateShortcutSet($label = '', $id = NULL) {
$set = ShortcutSet::create([
'id' => isset($id) ? $id : strtolower($this->randomMachineName()),
'label' => empty($label) ? $this->randomString() : $label,
));
]);
$set->save();
return $set;
}
@ -116,8 +116,8 @@ abstract class ShortcutTestBase extends WebTestBase {
* @return array
* Array of the requested information from each link.
*/
function getShortcutInformation(ShortcutSetInterface $set, $key) {
$info = array();
public function getShortcutInformation(ShortcutSetInterface $set, $key) {
$info = [];
\Drupal::entityManager()->getStorage('shortcut')->resetCache();
foreach ($set->getShortcuts() as $shortcut) {
if ($key == 'link') {

View file

@ -23,13 +23,13 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
*
* @var array
*/
public static $modules = array(
public static $modules = [
'language',
'content_translation',
'link',
'shortcut',
'toolbar'
);
];
/**
* {@inheritdoc}
@ -44,7 +44,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
* {@inheritdoc}
*/
protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), array('access shortcuts', 'administer shortcuts', 'access toolbar'));
return array_merge(parent::getTranslatorPermissions(), ['access shortcuts', 'administer shortcuts', 'access toolbar']);
}
/**
@ -59,7 +59,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
* {@inheritdoc}
*/
protected function getNewEntityValues($langcode) {
return array('title' => array(array('value' => $this->randomMachineName()))) + parent::getNewEntityValues($langcode);
return ['title' => [['value' => $this->randomMachineName()]]] + parent::getNewEntityValues($langcode);
}
protected function doTestBasicTranslation() {
@ -71,14 +71,14 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
$entity = $storage->load($this->entityId);
foreach ($this->langcodes as $langcode) {
if ($entity->hasTranslation($langcode)) {
$language = new Language(array('id' => $langcode));
$language = new Language(['id' => $langcode]);
// Request the front page in this language and assert that the right
// translation shows up in the shortcut list with the right path.
$this->drupalGet('<front>', array('language' => $language));
$expected_path = \Drupal::urlGenerator()->generateFromRoute('user.page', array(), array('language' => $language));
$this->drupalGet('<front>', ['language' => $language]);
$expected_path = \Drupal::urlGenerator()->generateFromRoute('user.page', [], ['language' => $language]);
$label = $entity->getTranslation($langcode)->label();
$elements = $this->xpath('//nav[contains(@class, "toolbar-lining")]/ul[@class="toolbar-menu"]/li/a[contains(@href, :href) and normalize-space(text())=:label]', array(':href' => $expected_path, ':label' => $label));
$this->assertTrue(!empty($elements), format_string('Translated @language shortcut link @label found.', array('@label' => $label, '@language' => $language->getName())));
$elements = $this->xpath('//nav[contains(@class, "toolbar-lining")]/ul[@class="toolbar-menu"]/li/a[contains(@href, :href) and normalize-space(text())=:label]', [':href' => $expected_path, ':label' => $label]);
$this->assertTrue(!empty($elements), format_string('Translated @language shortcut link @label found.', ['@label' => $label, '@language' => $language->getName()]));
}
}
}
@ -96,14 +96,14 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
foreach ($this->langcodes as $langcode) {
// We only want to test the title for non-english translations.
if ($langcode != 'en') {
$options = array('language' => $languages[$langcode]);
$options = ['language' => $languages[$langcode]];
$url = $entity->urlInfo('edit-form', $options);
$this->drupalGet($url);
$title = t('@title [%language translation]', array(
$title = t('@title [%language translation]', [
'@title' => $entity->getTranslation($langcode)->label(),
'%language' => $languages[$langcode]->getName(),
));
]);
$this->assertRaw($title);
}
}
@ -120,7 +120,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
$this->assertFalse(
$entity instanceof EntityChangedInterface,
format_string('%entity is not implementing EntityChangedInterface.', array('%entity' => $this->entityTypeId))
format_string('%entity is not implementing EntityChangedInterface.', ['%entity' => $this->entityTypeId])
);
}