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

@ -9,39 +9,39 @@
* Implements hook_schema().
*/
function shortcut_schema() {
$schema['shortcut_set_users'] = array(
$schema['shortcut_set_users'] = [
'description' => 'Maps users to shortcut sets.',
'fields' => array(
'uid' => array(
'fields' => [
'uid' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {users}.uid for this set.',
),
'set_name' => array(
],
'set_name' => [
'type' => 'varchar_ascii',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => "The {shortcut_set}.set_name that will be displayed for this user.",
),
),
'primary key' => array('uid'),
'indexes' => array(
'set_name' => array('set_name'),
),
'foreign keys' => array(
'set_user' => array(
],
],
'primary key' => ['uid'],
'indexes' => [
'set_name' => ['set_name'],
],
'foreign keys' => [
'set_user' => [
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
'set_name' => array(
'columns' => ['uid' => 'uid'],
],
'set_name' => [
'table' => 'shortcut_set',
'columns' => array('set_name' => 'set_name'),
),
),
);
'columns' => ['set_name' => 'set_name'],
],
],
];
return $schema;
}

View file

@ -20,16 +20,16 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.shortcut':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Shortcut module allows users to create sets of <em>shortcut</em> links to commonly-visited pages of the site. Shortcuts are contained within <em>sets</em>. Each user with <em>Select any shortcut set</em> permission can select a shortcut set created by anyone at the site. For more information, see the <a href=":shortcut">online documentation for the Shortcut module</a>.', array(':shortcut' => 'https://www.drupal.org/documentation/modules/shortcut')) . '</p>';
$output .= '<p>' . t('The Shortcut module allows users to create sets of <em>shortcut</em> links to commonly-visited pages of the site. Shortcuts are contained within <em>sets</em>. Each user with <em>Select any shortcut set</em> permission can select a shortcut set created by anyone at the site. For more information, see the <a href=":shortcut">online documentation for the Shortcut module</a>.', [':shortcut' => 'https://www.drupal.org/documentation/modules/shortcut']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl><dt>' . t('Administering shortcuts') . '</dt>';
$output .= '<dd>' . t('Users with the <em>Administer shortcuts</em> permission can manage shortcut sets and edit the shortcuts within sets from the <a href=":shortcuts">Shortcuts administration page</a>.', array(':shortcuts' => \Drupal::url('entity.shortcut_set.collection'))) . '</dd>';
$output .= '<dd>' . t('Users with the <em>Administer shortcuts</em> permission can manage shortcut sets and edit the shortcuts within sets from the <a href=":shortcuts">Shortcuts administration page</a>.', [':shortcuts' => \Drupal::url('entity.shortcut_set.collection')]) . '</dd>';
$output .= '<dt>' . t('Choosing shortcut sets') . '</dt>';
$output .= '<dd>' . t('Users with permission to switch shortcut sets can choose a shortcut set to use from the Shortcuts tab of their user account page.') . '</dd>';
$output .= '<dt>' . t('Adding and removing shortcuts') . '</dt>';
$output .= '<dd>' . t('The Shortcut module creates an add/remove link for each page on your site; the link lets you add or remove the current page from the currently-enabled set of shortcuts (if your theme displays it and you have permission to edit your shortcut set). The core Seven administration theme displays this link next to the page title, as a grey or yellow star. If you click on the grey star, you will add that page to your preferred set of shortcuts. If the page is already part of your shortcut set, the link will be a yellow star, and will allow you to remove the current page from your shortcut set.') . '</dd>';
$output .= '<dt>' . t('Displaying shortcuts') . '</dt>';
$output .= '<dd>' . t('You can display your shortcuts by enabling the <em>Shortcuts</em> block on the <a href=":blocks">Blocks administration page</a>. Certain administrative modules also display your shortcuts; for example, the core <a href=":toolbar-help">Toolbar module</a> provides a corresponding menu item.', array(':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#', ':toolbar-help' => (\Drupal::moduleHandler()->moduleExists('toolbar')) ? \Drupal::url('help.page', array('name' => 'toolbar')) : '#')) . '</dd>';
$output .= '<dd>' . t('You can display your shortcuts by enabling the <em>Shortcuts</em> block on the <a href=":blocks">Blocks administration page</a>. Certain administrative modules also display your shortcuts; for example, the core <a href=":toolbar-help">Toolbar module</a> provides a corresponding menu item.', [':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#', ':toolbar-help' => (\Drupal::moduleHandler()->moduleExists('toolbar')) ? \Drupal::url('help.page', ['name' => 'toolbar']) : '#']) . '</dd>';
$output .= '</dl>';
return $output;
@ -38,7 +38,7 @@ function shortcut_help($route_name, RouteMatchInterface $route_match) {
case 'entity.shortcut_set.edit_form':
$user = \Drupal::currentUser();
if ($user->hasPermission('access shortcuts') && $user->hasPermission('switch shortcut sets')) {
$output = '<p>' . t('Define which shortcut set you are using on the <a href=":shortcut-link">Shortcuts tab</a> of your account page.', array(':shortcut-link' => \Drupal::url('shortcut.set_switch', array('user' => $user->id())))) . '</p>';
$output = '<p>' . t('Define which shortcut set you are using on the <a href=":shortcut-link">Shortcuts tab</a> of your account page.', [':shortcut-link' => \Drupal::url('shortcut.set_switch', ['user' => $user->id()])]) . '</p>';
return $output;
}
}
@ -65,7 +65,11 @@ function shortcut_set_edit_access(ShortcutSetInterface $shortcut_set = NULL) {
// Sufficiently-privileged users can edit their currently displayed shortcut
// set, but not other sets. They must also be able to access shortcuts.
$may_edit_current_shortcut_set = $account->hasPermission('customize shortcut links') && (!isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set()) && $account->hasPermission('access shortcuts');
return AccessResult::allowedIf($may_edit_current_shortcut_set)->cachePerPermissions();
$result = AccessResult::allowedIf($may_edit_current_shortcut_set)->cachePerPermissions();
if (!$result->isAllowed()) {
$result->setReason("The shortcut set must be the currently displayed set for the user and the user must have 'access shortcuts' AND 'customize shortcut links' permissions.");
}
return $result;
}
/**
@ -162,7 +166,7 @@ function shortcut_set_unassign_user($account) {
* the default set is returned.
*/
function shortcut_current_displayed_set($account = NULL) {
$shortcut_sets = &drupal_static(__FUNCTION__, array());
$shortcut_sets = &drupal_static(__FUNCTION__, []);
$user = \Drupal::currentUser();
if (!isset($account)) {
$account = $user;
@ -209,7 +213,7 @@ function shortcut_default_set($account = NULL) {
// 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(\Drupal::moduleHandler()->invokeAll('shortcut_default_set', array($account)));
$suggestions = array_reverse(\Drupal::moduleHandler()->invokeAll('shortcut_default_set', [$account]));
$suggestions[] = 'default';
foreach ($suggestions as $name) {
if ($shortcut_set = ShortcutSet::load($name)) {
@ -252,37 +256,37 @@ function shortcut_set_title_exists($title) {
* An array of shortcut links, in the format returned by the menu system.
*/
function shortcut_renderable_links($shortcut_set = NULL) {
$shortcut_links = array();
$shortcut_links = [];
if (!isset($shortcut_set)) {
$shortcut_set = shortcut_current_displayed_set();
}
$cache_tags = array();
$cache_tags = [];
foreach ($shortcut_set->getShortcuts() as $shortcut) {
$shortcut = \Drupal::entityManager()->getTranslationFromContext($shortcut);
$url = $shortcut->getUrl();
if ($url->access()) {
$links[$shortcut->id()] = array(
$links[$shortcut->id()] = [
'type' => 'link',
'title' => $shortcut->label(),
'url' => $shortcut->getUrl(),
);
];
$cache_tags = Cache::mergeTags($cache_tags, $shortcut->getCacheTags());
}
}
if (!empty($links)) {
$shortcut_links = array(
$shortcut_links = [
'#theme' => 'links__toolbar_shortcuts',
'#links' => $links,
'#attributes' => array(
'class' => array('toolbar-menu'),
),
'#cache' => array(
'#attributes' => [
'class' => ['toolbar-menu'],
],
'#cache' => [
'tags' => $cache_tags,
),
);
],
];
}
return $shortcut_links;
@ -313,15 +317,15 @@ function shortcut_preprocess_page_title(&$variables) {
// string form, so we can set the default name for the shortcut.
// Strip HTML tags from the title.
$name = trim(strip_tags(render($variables['title'])));
$query = array(
$query = [
'link' => $link,
'name' => $name,
);
];
$shortcut_set = shortcut_current_displayed_set();
// Check if $link is already a shortcut and set $link_mode accordingly.
$shortcuts = \Drupal::entityManager()->getStorage('shortcut')->loadByProperties(array('shortcut_set' => $shortcut_set->id()));
$shortcuts = \Drupal::entityManager()->getStorage('shortcut')->loadByProperties(['shortcut_set' => $shortcut_set->id()]);
/** @var \Drupal\shortcut\ShortcutInterface $shortcut */
foreach ($shortcuts as $shortcut) {
if (($shortcut_url = $shortcut->getUrl()) && $shortcut_url->isRouted() && $shortcut_url->getRouteName() == $route_match->getRouteName() && $shortcut_url->getRouteParameters() == $route_match->getRawParameters()->all()) {
@ -332,36 +336,36 @@ function shortcut_preprocess_page_title(&$variables) {
$link_mode = isset($shortcut_id) ? "remove" : "add";
if ($link_mode == "add") {
$link_text = shortcut_set_switch_access()->isAllowed() ? t('Add to %shortcut_set shortcuts', array('%shortcut_set' => $shortcut_set->label())) : t('Add to shortcuts');
$link_text = shortcut_set_switch_access()->isAllowed() ? t('Add to %shortcut_set shortcuts', ['%shortcut_set' => $shortcut_set->label()]) : t('Add to shortcuts');
$route_name = 'shortcut.link_add_inline';
$route_parameters = array('shortcut_set' => $shortcut_set->id());
$route_parameters = ['shortcut_set' => $shortcut_set->id()];
}
else {
$query['id'] = $shortcut_id;
$link_text = shortcut_set_switch_access()->isAllowed() ? t('Remove from %shortcut_set shortcuts', array('%shortcut_set' => $shortcut_set->label())) : t('Remove from shortcuts');
$link_text = shortcut_set_switch_access()->isAllowed() ? t('Remove from %shortcut_set shortcuts', ['%shortcut_set' => $shortcut_set->label()]) : t('Remove from shortcuts');
$route_name = 'entity.shortcut.link_delete_inline';
$route_parameters = array('shortcut' => $shortcut_id);
$route_parameters = ['shortcut' => $shortcut_id];
}
if (theme_get_setting('third_party_settings.shortcut.module_link')) {
$query += \Drupal::destination()->getAsArray();
$variables['title_suffix']['add_or_remove_shortcut'] = array(
'#attached' => array(
'library' => array(
$variables['title_suffix']['add_or_remove_shortcut'] = [
'#attached' => [
'library' => [
'shortcut/drupal.shortcut',
),
),
],
],
'#type' => 'link',
'#title' => SafeMarkup::format('<span class="shortcut-action__icon"></span><span class="shortcut-action__message">@text</span>', array('@text' => $link_text)),
'#title' => SafeMarkup::format('<span class="shortcut-action__icon"></span><span class="shortcut-action__message">@text</span>', ['@text' => $link_text]),
'#url' => Url::fromRoute($route_name, $route_parameters),
'#options' => array('query' => $query),
'#attributes' => array(
'class' => array(
'#options' => ['query' => $query],
'#attributes' => [
'class' => [
'shortcut-action',
'shortcut-action--' . $link_mode,
),
),
);
],
],
];
}
}
}
@ -390,37 +394,37 @@ function shortcut_toolbar() {
\Drupal::service('renderer')->addCacheableDependency($items['shortcuts'], $shortcut_set);
$configure_link = NULL;
if (shortcut_set_edit_access($shortcut_set)->isAllowed()) {
$configure_link = array(
$configure_link = [
'#type' => 'link',
'#title' => t('Edit shortcuts'),
'#url' => Url::fromRoute('entity.shortcut_set.customize_form', ['shortcut_set' => $shortcut_set->id()]),
'#options' => array('attributes' => array('class' => array('edit-shortcuts'))),
);
'#options' => ['attributes' => ['class' => ['edit-shortcuts']]],
];
}
if (!empty($links) || !empty($configure_link)) {
$items['shortcuts'] += array(
$items['shortcuts'] += [
'#type' => 'toolbar_item',
'tab' => array(
'tab' => [
'#type' => 'link',
'#title' => t('Shortcuts'),
'#url' => $shortcut_set->urlInfo('collection'),
'#attributes' => array(
'#attributes' => [
'title' => t('Shortcuts'),
'class' => array('toolbar-icon', 'toolbar-icon-shortcut'),
),
),
'tray' => array(
'class' => ['toolbar-icon', 'toolbar-icon-shortcut'],
],
],
'tray' => [
'#heading' => t('User-defined shortcuts'),
'shortcuts' => $links,
'configure' => $configure_link,
),
],
'#weight' => -10,
'#attached' => array(
'library' => array(
'#attached' => [
'library' => [
'shortcut/drupal.shortcut',
),
),
);
],
],
];
}
}

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

@ -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])
);
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\shortcut\Tests;
namespace Drupal\Tests\shortcut\Functional;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\shortcut\Entity\Shortcut;
@ -18,7 +18,7 @@ class ShortcutCacheTagsTest extends EntityCacheTagsTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('shortcut');
public static $modules = ['shortcut'];
/**
* {@inheritdoc}
@ -39,12 +39,12 @@ class ShortcutCacheTagsTest extends EntityCacheTagsTestBase {
*/
protected function createEntity() {
// Create a "Llama" shortcut.
$shortcut = Shortcut::create(array(
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Llama'),
'weight' => 0,
'link' => [['uri' => 'internal:/admin']],
));
]);
$shortcut->save();
return $shortcut;

View file

@ -18,12 +18,12 @@ class MigrateShortcutSetTest extends MigrateDrupal7TestBase {
*
* @var array
*/
public static $modules = array(
public static $modules = [
'link',
'field',
'shortcut',
'menu_link_content',
);
];
/**
* {@inheritdoc}

View file

@ -17,12 +17,12 @@ class MigrateShortcutSetUsersTest extends MigrateDrupal7TestBase {
*
* @var array
*/
public static $modules = array(
public static $modules = [
'link',
'field',
'shortcut',
'menu_link_content',
);
];
/**
* {@inheritdoc}

View file

@ -18,12 +18,12 @@ class MigrateShortcutTest extends MigrateDrupal7TestBase {
*
* @var array
*/
public static $modules = array(
public static $modules = [
'link',
'field',
'shortcut',
'menu_link_content',
);
];
/**
* {@inheritdoc}

View file

@ -12,10 +12,10 @@ use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
class ShortcutLocalTasksTest extends LocalTaskIntegrationTestBase {
protected function setUp() {
$this->directoryList = array(
$this->directoryList = [
'shortcut' => 'core/modules/shortcut',
'user' => 'core/modules/user',
);
];
parent::setUp();
}
@ -25,9 +25,9 @@ class ShortcutLocalTasksTest extends LocalTaskIntegrationTestBase {
* @dataProvider getShortcutPageRoutes
*/
public function testShortcutPageLocalTasks($route) {
$tasks = array(
0 => array('shortcut.set_switch', 'entity.user.canonical', 'entity.user.edit_form',),
);
$tasks = [
0 => ['shortcut.set_switch', 'entity.user.canonical', 'entity.user.edit_form'],
];
$this->assertLocalTasks($route, $tasks);
}
@ -35,11 +35,11 @@ class ShortcutLocalTasksTest extends LocalTaskIntegrationTestBase {
* Provides a list of routes to test.
*/
public function getShortcutPageRoutes() {
return array(
array('entity.user.canonical'),
array('entity.user.edit_form'),
array('shortcut.set_switch'),
);
return [
['entity.user.canonical'],
['entity.user.edit_form'],
['shortcut.set_switch'],
];
}
}