Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -49,7 +49,7 @@ class MenuController extends ControllerBase {
|
|||
* The available menu and menu items.
|
||||
*/
|
||||
public function getParentOptions(Request $request) {
|
||||
$available_menus = array();
|
||||
$available_menus = [];
|
||||
if ($menus = $request->request->get('menus')) {
|
||||
foreach ($menus as $menu) {
|
||||
$available_menus[$menu] = $menu;
|
||||
|
|
|
@ -57,7 +57,7 @@ class MenuDeleteForm extends EntityDeleteForm {
|
|||
$caption = '';
|
||||
$num_links = $this->menuLinkManager->countMenuLinks($this->entity->id());
|
||||
if ($num_links) {
|
||||
$caption .= '<p>' . $this->formatPlural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $this->entity->label())) . '</p>';
|
||||
$caption .= '<p>' . $this->formatPlural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', ['%title' => $this->entity->label()]) . '</p>';
|
||||
}
|
||||
$caption .= '<p>' . t('This action cannot be undone.') . '</p>';
|
||||
return $caption;
|
||||
|
@ -67,7 +67,7 @@ class MenuDeleteForm extends EntityDeleteForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function logDeletionMessage() {
|
||||
$this->logger('menu')->notice('Deleted custom menu %title and all its menu links.', array('%title' => $this->entity->label()));
|
||||
$this->logger('menu')->notice('Deleted custom menu %title and all its menu links.', ['%title' => $this->entity->label()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,7 +85,7 @@ class MenuDeleteForm extends EntityDeleteForm {
|
|||
// parameter that is being removed. Also, consider moving this to
|
||||
// menu_ui.module as part of a generic response to entity deletion.
|
||||
// https://www.drupal.org/node/2310329
|
||||
$menu_links = $this->menuLinkManager->loadLinksByRoute('entity.menu.edit_form', array('menu' => $this->entity->id()), TRUE);
|
||||
$menu_links = $this->menuLinkManager->loadLinksByRoute('entity.menu.edit_form', ['menu' => $this->entity->id()], TRUE);
|
||||
foreach ($menu_links as $id => $link) {
|
||||
$this->menuLinkManager->removeDefinition($id);
|
||||
}
|
||||
|
|
|
@ -57,22 +57,22 @@ class MenuLinkEditForm extends FormBase {
|
|||
* The plugin instance to use for this form.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, MenuLinkInterface $menu_link_plugin = NULL) {
|
||||
$form['menu_link_id'] = array(
|
||||
$form['menu_link_id'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $menu_link_plugin->getPluginId(),
|
||||
);
|
||||
];
|
||||
$class_name = $menu_link_plugin->getFormClass();
|
||||
$form['#plugin_form'] = $this->classResolver->getInstanceFromDefinition($class_name);
|
||||
$form['#plugin_form']->setMenuLinkInstance($menu_link_plugin);
|
||||
|
||||
$form += $form['#plugin_form']->buildConfigurationForm($form, $form_state);
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save'),
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ class MenuLinkEditForm extends FormBase {
|
|||
drupal_set_message($this->t('The menu link has been saved.'));
|
||||
$form_state->setRedirect(
|
||||
'entity.menu.edit_form',
|
||||
array('menu' => $link->getMenuName())
|
||||
['menu' => $link->getMenuName()]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,16 +59,16 @@ class MenuLinkResetForm extends ConfirmFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to reset the link %item to its default values?', array('%item' => $this->link->getTitle()));
|
||||
return $this->t('Are you sure you want to reset the link %item to its default values?', ['%item' => $this->link->getTitle()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelUrl() {
|
||||
return new Url('entity.menu.edit_form', array(
|
||||
return new Url('entity.menu.edit_form', [
|
||||
'menu' => $this->link->getMenuName(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace Drupal\menu_ui;
|
|||
use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Link;
|
||||
|
@ -23,13 +22,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
*/
|
||||
class MenuForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* The factory for entity queries.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQueryFactory;
|
||||
|
||||
/**
|
||||
* The menu link manager.
|
||||
*
|
||||
|
@ -56,13 +48,11 @@ class MenuForm extends EntityForm {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $overviewTreeForm = array('#tree' => TRUE);
|
||||
protected $overviewTreeForm = ['#tree' => TRUE];
|
||||
|
||||
/**
|
||||
* Constructs a MenuForm object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory
|
||||
* The factory for entity queries.
|
||||
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager
|
||||
* The menu link manager.
|
||||
* @param \Drupal\Core\Menu\MenuLinkTreeInterface $menu_tree
|
||||
|
@ -70,8 +60,7 @@ class MenuForm extends EntityForm {
|
|||
* @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
|
||||
* The link generator.
|
||||
*/
|
||||
public function __construct(QueryFactory $entity_query_factory, MenuLinkManagerInterface $menu_link_manager, MenuLinkTreeInterface $menu_tree, LinkGeneratorInterface $link_generator) {
|
||||
$this->entityQueryFactory = $entity_query_factory;
|
||||
public function __construct(MenuLinkManagerInterface $menu_link_manager, MenuLinkTreeInterface $menu_tree, LinkGeneratorInterface $link_generator) {
|
||||
$this->menuLinkManager = $menu_link_manager;
|
||||
$this->menuTree = $menu_tree;
|
||||
$this->linkGenerator = $link_generator;
|
||||
|
@ -82,7 +71,6 @@ class MenuForm extends EntityForm {
|
|||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.query'),
|
||||
$container->get('plugin.manager.menu.link'),
|
||||
$container->get('menu.link_tree'),
|
||||
$container->get('link_generator')
|
||||
|
@ -96,43 +84,43 @@ class MenuForm extends EntityForm {
|
|||
$menu = $this->entity;
|
||||
|
||||
if ($this->operation == 'edit') {
|
||||
$form['#title'] = $this->t('Edit menu %label', array('%label' => $menu->label()));
|
||||
$form['#title'] = $this->t('Edit menu %label', ['%label' => $menu->label()]);
|
||||
}
|
||||
|
||||
$form['label'] = array(
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Title'),
|
||||
'#default_value' => $menu->label(),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['id'] = array(
|
||||
];
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#title' => $this->t('Menu name'),
|
||||
'#default_value' => $menu->id(),
|
||||
'#maxlength' => MENU_MAX_MENU_NAME_LENGTH_UI,
|
||||
'#description' => $this->t('A unique name to construct the URL for the menu. It must only contain lowercase letters, numbers and hyphens.'),
|
||||
'#machine_name' => array(
|
||||
'exists' => array($this, 'menuNameExists'),
|
||||
'source' => array('label'),
|
||||
'#machine_name' => [
|
||||
'exists' => [$this, 'menuNameExists'],
|
||||
'source' => ['label'],
|
||||
'replace_pattern' => '[^a-z0-9-]+',
|
||||
'replace' => '-',
|
||||
),
|
||||
],
|
||||
// A menu's machine name cannot be changed.
|
||||
'#disabled' => !$menu->isNew() || $menu->isLocked(),
|
||||
);
|
||||
$form['description'] = array(
|
||||
];
|
||||
$form['description'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Administrative summary'),
|
||||
'#maxlength' => 512,
|
||||
'#default_value' => $menu->getDescription(),
|
||||
);
|
||||
];
|
||||
|
||||
$form['langcode'] = array(
|
||||
$form['langcode'] = [
|
||||
'#type' => 'language_select',
|
||||
'#title' => t('Menu language'),
|
||||
'#languages' => LanguageInterface::STATE_ALL,
|
||||
'#default_value' => $menu->language()->getId(),
|
||||
);
|
||||
];
|
||||
|
||||
// Add menu links administration form for existing menus.
|
||||
if (!$menu->isNew() || $menu->isLocked()) {
|
||||
|
@ -142,7 +130,7 @@ class MenuForm extends EntityForm {
|
|||
// the parents of the form section.
|
||||
// @see self::submitOverviewForm()
|
||||
$form_state->set('menu_overview_form_parents', ['links']);
|
||||
$form['links'] = array();
|
||||
$form['links'] = [];
|
||||
$form['links'] = $this->buildOverviewForm($form['links'], $form_state);
|
||||
}
|
||||
|
||||
|
@ -160,7 +148,7 @@ class MenuForm extends EntityForm {
|
|||
*/
|
||||
public function menuNameExists($value) {
|
||||
// Check first to see if a menu with this ID exists.
|
||||
if ($this->entityQueryFactory->get('menu')->condition('id', $value)->range(0, 1)->count()->execute()) {
|
||||
if ($this->entityTypeManager->getStorage('menu')->getQuery()->condition('id', $value)->range(0, 1)->count()->execute()) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -176,12 +164,12 @@ class MenuForm extends EntityForm {
|
|||
$status = $menu->save();
|
||||
$edit_link = $this->entity->link($this->t('Edit'));
|
||||
if ($status == SAVED_UPDATED) {
|
||||
drupal_set_message($this->t('Menu %label has been updated.', array('%label' => $menu->label())));
|
||||
$this->logger('menu')->notice('Menu %label has been updated.', array('%label' => $menu->label(), 'link' => $edit_link));
|
||||
drupal_set_message($this->t('Menu %label has been updated.', ['%label' => $menu->label()]));
|
||||
$this->logger('menu')->notice('Menu %label has been updated.', ['%label' => $menu->label(), 'link' => $edit_link]);
|
||||
}
|
||||
else {
|
||||
drupal_set_message($this->t('Menu %label has been added.', array('%label' => $menu->label())));
|
||||
$this->logger('menu')->notice('Menu %label has been added.', array('%label' => $menu->label(), 'link' => $edit_link));
|
||||
drupal_set_message($this->t('Menu %label has been added.', ['%label' => $menu->label()]));
|
||||
$this->logger('menu')->notice('Menu %label has been added.', ['%label' => $menu->label(), 'link' => $edit_link]);
|
||||
}
|
||||
|
||||
$form_state->setRedirectUrl($this->entity->urlInfo('edit-form'));
|
||||
|
@ -225,10 +213,10 @@ class MenuForm extends EntityForm {
|
|||
|
||||
// We indicate that a menu administrator is running the menu access check.
|
||||
$this->getRequest()->attributes->set('_menu_admin', TRUE);
|
||||
$manipulators = array(
|
||||
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
|
||||
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
|
||||
);
|
||||
$manipulators = [
|
||||
['callable' => 'menu.default_tree_manipulators:checkAccess'],
|
||||
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
|
||||
];
|
||||
$tree = $this->menuTree->transform($tree, $manipulators);
|
||||
$this->getRequest()->attributes->set('_menu_admin', FALSE);
|
||||
|
||||
|
@ -241,26 +229,26 @@ class MenuForm extends EntityForm {
|
|||
};
|
||||
$delta = max($count($tree), 50);
|
||||
|
||||
$form['links'] = array(
|
||||
$form['links'] = [
|
||||
'#type' => 'table',
|
||||
'#theme' => 'table__menu_overview',
|
||||
'#header' => array(
|
||||
'#header' => [
|
||||
$this->t('Menu link'),
|
||||
array(
|
||||
[
|
||||
'data' => $this->t('Enabled'),
|
||||
'class' => array('checkbox'),
|
||||
),
|
||||
'class' => ['checkbox'],
|
||||
],
|
||||
$this->t('Weight'),
|
||||
array(
|
||||
[
|
||||
'data' => $this->t('Operations'),
|
||||
'colspan' => 3,
|
||||
),
|
||||
),
|
||||
'#attributes' => array(
|
||||
],
|
||||
],
|
||||
'#attributes' => [
|
||||
'id' => 'menu-overview',
|
||||
),
|
||||
'#tabledrag' => array(
|
||||
array(
|
||||
],
|
||||
'#tabledrag' => [
|
||||
[
|
||||
'action' => 'match',
|
||||
'relationship' => 'parent',
|
||||
'group' => 'menu-parent',
|
||||
|
@ -268,14 +256,14 @@ class MenuForm extends EntityForm {
|
|||
'source' => 'menu-id',
|
||||
'hidden' => TRUE,
|
||||
'limit' => \Drupal::menuTree()->maxDepth() - 1,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'menu-weight',
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$form['links']['#empty'] = $this->t('There are no menu links yet. <a href=":url">Add link</a>.', [
|
||||
':url' => $this->url('entity.menu.add_link_form', ['menu' => $this->entity->id()], [
|
||||
|
@ -297,19 +285,19 @@ class MenuForm extends EntityForm {
|
|||
$form['links'][$id]['#weight'] = $element['#item']->link->getWeight();
|
||||
|
||||
// Add special classes to be used for tabledrag.js.
|
||||
$element['parent']['#attributes']['class'] = array('menu-parent');
|
||||
$element['weight']['#attributes']['class'] = array('menu-weight');
|
||||
$element['id']['#attributes']['class'] = array('menu-id');
|
||||
$element['parent']['#attributes']['class'] = ['menu-parent'];
|
||||
$element['weight']['#attributes']['class'] = ['menu-weight'];
|
||||
$element['id']['#attributes']['class'] = ['menu-id'];
|
||||
|
||||
$form['links'][$id]['title'] = array(
|
||||
array(
|
||||
$form['links'][$id]['title'] = [
|
||||
[
|
||||
'#theme' => 'indentation',
|
||||
'#size' => $element['#item']->depth - 1,
|
||||
),
|
||||
],
|
||||
$element['title'],
|
||||
);
|
||||
];
|
||||
$form['links'][$id]['enabled'] = $element['enabled'];
|
||||
$form['links'][$id]['enabled']['#wrapper_attributes']['class'] = array('checkbox', 'menu-enabled');
|
||||
$form['links'][$id]['enabled']['#wrapper_attributes']['class'] = ['checkbox', 'menu-enabled'];
|
||||
|
||||
$form['links'][$id]['weight'] = $element['weight'];
|
||||
|
||||
|
@ -351,7 +339,7 @@ class MenuForm extends EntityForm {
|
|||
if ($link) {
|
||||
$id = 'menu_plugin_id:' . $link->getPluginId();
|
||||
$form[$id]['#item'] = $element;
|
||||
$form[$id]['#attributes'] = $link->isEnabled() ? array('class' => array('menu-enabled')) : array('class' => array('menu-disabled'));
|
||||
$form[$id]['#attributes'] = $link->isEnabled() ? ['class' => ['menu-enabled']] : ['class' => ['menu-disabled']];
|
||||
$form[$id]['title'] = Link::fromTextAndUrl($link->getTitle(), $link->getUrlObject())->toRenderable();
|
||||
if (!$link->isEnabled()) {
|
||||
$form[$id]['title']['#suffix'] = ' (' . $this->t('disabled') . ')';
|
||||
|
@ -365,32 +353,32 @@ class MenuForm extends EntityForm {
|
|||
$form[$id]['title']['#suffix'] = ' (' . $this->t('logged in users only') . ')';
|
||||
}
|
||||
|
||||
$form[$id]['enabled'] = array(
|
||||
$form[$id]['enabled'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Enable @title menu link', array('@title' => $link->getTitle())),
|
||||
'#title' => $this->t('Enable @title menu link', ['@title' => $link->getTitle()]),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $link->isEnabled(),
|
||||
);
|
||||
$form[$id]['weight'] = array(
|
||||
];
|
||||
$form[$id]['weight'] = [
|
||||
'#type' => 'weight',
|
||||
'#delta' => $delta,
|
||||
'#default_value' => $link->getWeight(),
|
||||
'#title' => $this->t('Weight for @title', array('@title' => $link->getTitle())),
|
||||
'#title' => $this->t('Weight for @title', ['@title' => $link->getTitle()]),
|
||||
'#title_display' => 'invisible',
|
||||
);
|
||||
$form[$id]['id'] = array(
|
||||
];
|
||||
$form[$id]['id'] = [
|
||||
'#type' => 'hidden',
|
||||
'#value' => $link->getPluginId(),
|
||||
);
|
||||
$form[$id]['parent'] = array(
|
||||
];
|
||||
$form[$id]['parent'] = [
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => $link->getParent(),
|
||||
);
|
||||
];
|
||||
// Build a list of operations.
|
||||
$operations = array();
|
||||
$operations['edit'] = array(
|
||||
$operations = [];
|
||||
$operations['edit'] = [
|
||||
'title' => $this->t('Edit'),
|
||||
);
|
||||
];
|
||||
// Allow for a custom edit link per plugin.
|
||||
$edit_route = $link->getEditRoute();
|
||||
if ($edit_route) {
|
||||
|
@ -400,16 +388,16 @@ class MenuForm extends EntityForm {
|
|||
}
|
||||
else {
|
||||
// Fall back to the standard edit link.
|
||||
$operations['edit'] += array(
|
||||
$operations['edit'] += [
|
||||
'url' => Url::fromRoute('menu_ui.link_edit', ['menu_link_plugin' => $link->getPluginId()]),
|
||||
);
|
||||
];
|
||||
}
|
||||
// Links can either be reset or deleted, not both.
|
||||
if ($link->isResettable()) {
|
||||
$operations['reset'] = array(
|
||||
$operations['reset'] = [
|
||||
'title' => $this->t('Reset'),
|
||||
'url' => Url::fromRoute('menu_ui.link_reset', ['menu_link_plugin' => $link->getPluginId()]),
|
||||
);
|
||||
];
|
||||
}
|
||||
elseif ($delete_link = $link->getDeleteRoute()) {
|
||||
$operations['delete']['url'] = $delete_link;
|
||||
|
@ -417,15 +405,15 @@ class MenuForm extends EntityForm {
|
|||
$operations['delete']['title'] = $this->t('Delete');
|
||||
}
|
||||
if ($link->isTranslatable()) {
|
||||
$operations['translate'] = array(
|
||||
$operations['translate'] = [
|
||||
'title' => $this->t('Translate'),
|
||||
'url' => $link->getTranslateRoute(),
|
||||
);
|
||||
];
|
||||
}
|
||||
$form[$id]['operations'] = array(
|
||||
$form[$id]['operations'] = [
|
||||
'#type' => 'operations',
|
||||
'#links' => $operations,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
if ($element->subtree) {
|
||||
|
@ -461,16 +449,16 @@ class MenuForm extends EntityForm {
|
|||
// parent. To prevent this, save items in the form in the same order they
|
||||
// are sent, ensuring parents are saved first, then their children.
|
||||
// See https://www.drupal.org/node/181126#comment-632270.
|
||||
$order = is_array($input) ? array_flip(array_keys($input)) : array();
|
||||
$order = is_array($input) ? array_flip(array_keys($input)) : [];
|
||||
// Update our original form with the new order.
|
||||
$form = array_intersect_key(array_merge($order, $form), $form);
|
||||
|
||||
$fields = array('weight', 'parent', 'enabled');
|
||||
$fields = ['weight', 'parent', 'enabled'];
|
||||
$form_links = $form['links'];
|
||||
foreach (Element::children($form_links) as $id) {
|
||||
if (isset($form_links[$id]['#item'])) {
|
||||
$element = $form_links[$id];
|
||||
$updated_values = array();
|
||||
$updated_values = [];
|
||||
// Update any fields that have changed in this menu item.
|
||||
foreach ($fields as $field) {
|
||||
if ($element[$field]['#value'] != $element[$field]['#default_value']) {
|
||||
|
|
|
@ -18,10 +18,10 @@ class MenuListBuilder extends ConfigEntityListBuilder {
|
|||
*/
|
||||
public function buildHeader() {
|
||||
$header['title'] = t('Title');
|
||||
$header['description'] = array(
|
||||
$header['description'] = [
|
||||
'data' => t('Description'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
|
||||
);
|
||||
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
|
||||
];
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
|
@ -29,10 +29,10 @@ class MenuListBuilder extends ConfigEntityListBuilder {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['title'] = array(
|
||||
$row['title'] = [
|
||||
'data' => $entity->label(),
|
||||
'class' => array('menu-label'),
|
||||
);
|
||||
'class' => ['menu-label'],
|
||||
];
|
||||
$row['description']['data'] = ['#markup' => $entity->getDescription()];
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
@ -45,11 +45,11 @@ class MenuListBuilder extends ConfigEntityListBuilder {
|
|||
|
||||
if (isset($operations['edit'])) {
|
||||
$operations['edit']['title'] = t('Edit menu');
|
||||
$operations['add'] = array(
|
||||
$operations['add'] = [
|
||||
'title' => t('Add link'),
|
||||
'weight' => 20,
|
||||
'url' => $entity->urlInfo('add-link-form'),
|
||||
);
|
||||
];
|
||||
}
|
||||
if (isset($operations['delete'])) {
|
||||
$operations['delete']['title'] = t('Delete menu');
|
||||
|
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\menu_ui\Tests;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
use Drupal\system\Tests\Cache\PageCacheTagsTestBase;
|
||||
use Drupal\system\Entity\Menu;
|
||||
|
||||
/**
|
||||
* Tests the Menu and Menu Link entities' cache tags.
|
||||
*
|
||||
* @group menu_ui
|
||||
*/
|
||||
class MenuCacheTagsTest extends PageCacheTagsTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('menu_ui', 'block', 'test_page_test');
|
||||
|
||||
/**
|
||||
* Tests cache tags presence and invalidation of the Menu entity.
|
||||
*
|
||||
* Tests the following cache tags:
|
||||
* - "menu:<menu ID>"
|
||||
*/
|
||||
public function testMenuBlock() {
|
||||
$url = Url::fromRoute('test_page_test.test_page');
|
||||
|
||||
// Create a Llama menu, add a link to it and place the corresponding block.
|
||||
$menu = Menu::create(array(
|
||||
'id' => 'llama',
|
||||
'label' => 'Llama',
|
||||
'description' => 'Description text',
|
||||
));
|
||||
$menu->save();
|
||||
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
|
||||
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
|
||||
// Move a link into the new menu.
|
||||
$menu_link = $menu_link_manager->updateDefinition('test_page_test.test_page', array('menu_name' => 'llama', 'parent' => ''));
|
||||
$block = $this->drupalPlaceBlock('system_menu_block:llama', array('label' => 'Llama', 'provider' => 'system', 'region' => 'footer'));
|
||||
|
||||
// Prime the page cache.
|
||||
$this->verifyPageCache($url, 'MISS');
|
||||
|
||||
// Verify a cache hit, but also the presence of the correct cache tags.
|
||||
$expected_tags = array(
|
||||
'rendered',
|
||||
'block_view',
|
||||
'config:block_list',
|
||||
'config:block.block.' . $block->id(),
|
||||
'config:system.menu.llama',
|
||||
// The cache contexts associated with the (in)accessible menu links are
|
||||
// bubbled.
|
||||
'config:user.role.anonymous',
|
||||
);
|
||||
$this->verifyPageCache($url, 'HIT', $expected_tags);
|
||||
|
||||
// Verify that after modifying the menu, there is a cache miss.
|
||||
$this->pass('Test modification of menu.', 'Debug');
|
||||
$menu->set('label', 'Awesome llama');
|
||||
$menu->save();
|
||||
$this->verifyPageCache($url, 'MISS');
|
||||
|
||||
// Verify a cache hit.
|
||||
$this->verifyPageCache($url, 'HIT');
|
||||
|
||||
// Verify that after modifying the menu link weight, there is a cache miss.
|
||||
$menu_link_manager->updateDefinition('test_page_test.test_page', array('weight' => -10));
|
||||
$this->pass('Test modification of menu link.', 'Debug');
|
||||
$this->verifyPageCache($url, 'MISS');
|
||||
|
||||
// Verify a cache hit.
|
||||
$this->verifyPageCache($url, 'HIT');
|
||||
|
||||
// Verify that after adding a menu link, there is a cache miss.
|
||||
$this->pass('Test addition of menu link.', 'Debug');
|
||||
$menu_link_2 = MenuLinkContent::create(array(
|
||||
'id' => '',
|
||||
'parent' => '',
|
||||
'title' => 'Alpaca',
|
||||
'menu_name' => 'llama',
|
||||
'link' => [[
|
||||
'uri' => 'internal:/',
|
||||
]],
|
||||
'bundle' => 'menu_name',
|
||||
));
|
||||
$menu_link_2->save();
|
||||
$this->verifyPageCache($url, 'MISS');
|
||||
|
||||
// Verify a cache hit.
|
||||
$this->verifyPageCache($url, 'HIT');
|
||||
|
||||
// Verify that after resetting the first menu link, there is a cache miss.
|
||||
$this->pass('Test reset of menu link.', 'Debug');
|
||||
$this->assertTrue($menu_link->isResettable(), 'First link can be reset');
|
||||
$menu_link = $menu_link_manager->resetLink($menu_link->getPluginId());
|
||||
$this->verifyPageCache($url, 'MISS');
|
||||
|
||||
// Verify a cache hit.
|
||||
$this->verifyPageCache($url, 'HIT', $expected_tags);
|
||||
|
||||
// Verify that after deleting the menu, there is a cache miss.
|
||||
$this->pass('Test deletion of menu.', 'Debug');
|
||||
$menu->delete();
|
||||
$this->verifyPageCache($url, 'MISS');
|
||||
|
||||
// Verify a cache hit.
|
||||
$this->verifyPageCache($url, 'HIT', ['config:block_list', 'config:user.role.anonymous', 'rendered']);
|
||||
}
|
||||
|
||||
}
|
|
@ -21,36 +21,36 @@ class MenuLanguageTest extends MenuWebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
public static $modules = ['language'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer menu')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['access administration pages', 'administer menu']));
|
||||
|
||||
// Add some custom languages.
|
||||
foreach (array('aa', 'bb', 'cc', 'cs') as $language_code) {
|
||||
ConfigurableLanguage::create(array(
|
||||
foreach (['aa', 'bb', 'cc', 'cs'] as $language_code) {
|
||||
ConfigurableLanguage::create([
|
||||
'id' => $language_code,
|
||||
'label' => $this->randomMachineName(),
|
||||
))->save();
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests menu language settings and the defaults for menu link items.
|
||||
*/
|
||||
function testMenuLanguage() {
|
||||
public function testMenuLanguage() {
|
||||
// Create a test menu to test the various language-related settings.
|
||||
// Machine name has to be lowercase.
|
||||
$menu_name = Unicode::strtolower($this->randomMachineName(16));
|
||||
$label = $this->randomString();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => $menu_name,
|
||||
'description' => '',
|
||||
'label' => $label,
|
||||
'langcode' => 'aa',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
|
||||
ContentLanguageSettings::loadByEntityTypeBundle('menu_link_content', 'menu_link_content')
|
||||
->setDefaultLangcode('bb')
|
||||
|
@ -65,19 +65,19 @@ class MenuLanguageTest extends MenuWebTestBase {
|
|||
|
||||
// Add a menu link.
|
||||
$link_title = $this->randomString();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'title[0][value]' => $link_title,
|
||||
'link[0][uri]' => $link_path,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save'));
|
||||
// Check the link was added with the correct menu link default language.
|
||||
$menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $link_title));
|
||||
$menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $link_title]);
|
||||
$menu_link = reset($menu_links);
|
||||
$this->assertMenuLink($menu_link->getPluginId(), array(
|
||||
$this->assertMenuLink($menu_link->getPluginId(), [
|
||||
'menu_name' => $menu_name,
|
||||
'route_name' => '<front>',
|
||||
'langcode' => 'bb',
|
||||
));
|
||||
]);
|
||||
|
||||
// Edit menu link default, changing it to cc.
|
||||
ContentLanguageSettings::loadByEntityTypeBundle('menu_link_content', 'menu_link_content')
|
||||
|
@ -87,30 +87,30 @@ class MenuLanguageTest extends MenuWebTestBase {
|
|||
|
||||
// Add a menu link.
|
||||
$link_title = $this->randomString();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'title[0][value]' => $link_title,
|
||||
'link[0][uri]' => $link_path,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save'));
|
||||
// Check the link was added with the correct new menu link default language.
|
||||
$menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $link_title));
|
||||
$menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $link_title]);
|
||||
$menu_link = reset($menu_links);
|
||||
$this->assertMenuLink($menu_link->getPluginId(), array(
|
||||
$this->assertMenuLink($menu_link->getPluginId(), [
|
||||
'menu_name' => $menu_name,
|
||||
'route_name' => '<front>',
|
||||
'langcode' => 'cc',
|
||||
));
|
||||
]);
|
||||
|
||||
// Now change the language of the new link to 'bb'.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'langcode[0][value]' => 'bb',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/menu/item/' . $menu_link->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertMenuLink($menu_link->getPluginId(), array(
|
||||
$this->assertMenuLink($menu_link->getPluginId(), [
|
||||
'menu_name' => $menu_name,
|
||||
'route_name' => '<front>',
|
||||
'langcode' => 'bb',
|
||||
));
|
||||
]);
|
||||
|
||||
// Saving menu link items ends up on the edit menu page. To check the menu
|
||||
// link has the correct language default on edit, go to the menu link edit
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\menu_ui\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
* Reorder menu items.
|
||||
*
|
||||
* @group menu_ui
|
||||
*/
|
||||
class MenuLinkReorderTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* An administrator user.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $administrator;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('menu_ui', 'test_page_test', 'node', 'block');
|
||||
|
||||
/**
|
||||
* Test creating, editing, deleting menu links via node form widget.
|
||||
*/
|
||||
function testDefaultMenuLinkReorder() {
|
||||
|
||||
// Add the main menu block.
|
||||
$this->drupalPlaceBlock('system_menu_block:main');
|
||||
|
||||
// Assert that the Home link is available.
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertLink('Home');
|
||||
|
||||
// The administrator user that can re-order menu links.
|
||||
$this->administrator = $this->drupalCreateUser(array(
|
||||
'administer site configuration',
|
||||
'access administration pages',
|
||||
'administer menu',
|
||||
));
|
||||
$this->drupalLogin($this->administrator);
|
||||
|
||||
// Change the weight of the link to a non default value.
|
||||
$edit = array(
|
||||
'links[menu_plugin_id:test_page_test.front_page][weight]' => -10,
|
||||
);
|
||||
$this->drupalPostForm('admin/structure/menu/manage/main', $edit, t('Save'));
|
||||
|
||||
// The link is still there.
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertLink('Home');
|
||||
|
||||
// Clear all caches.
|
||||
$this->drupalPostForm('admin/config/development/performance', [], t('Clear all caches'));
|
||||
|
||||
// Clearing all caches should not affect the state of the menu link.
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertLink('Home');
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@ class MenuNodeTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('menu_ui', 'test_page_test', 'node', 'block', 'locale', 'language', 'content_translation');
|
||||
public static $modules = ['menu_ui', 'test_page_test', 'node', 'block', 'locale', 'language', 'content_translation'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -34,9 +34,9 @@ class MenuNodeTest extends WebTestBase {
|
|||
$this->drupalPlaceBlock('system_menu_block:main');
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
$this->editor = $this->drupalCreateUser(array(
|
||||
$this->editor = $this->drupalCreateUser([
|
||||
'access administration pages',
|
||||
'administer content types',
|
||||
'administer menu',
|
||||
|
@ -47,14 +47,14 @@ class MenuNodeTest extends WebTestBase {
|
|||
'update content translations',
|
||||
'delete content translations',
|
||||
'translate any entity',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($this->editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creating, editing, deleting menu links via node form widget.
|
||||
*/
|
||||
function testMenuNodeFormWidget() {
|
||||
public function testMenuNodeFormWidget() {
|
||||
// Verify that cacheability metadata is bubbled from the menu link tree
|
||||
// access checking that is performed when determining the "default parent
|
||||
// item" options in menu_ui_form_node_type_form_alter(). The "log out" link
|
||||
|
@ -68,9 +68,9 @@ class MenuNodeTest extends WebTestBase {
|
|||
$this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $max_length . '" .* \/>/', 'Menu link title field has correct maxlength in node add form.');
|
||||
|
||||
// Disable the default main menu, so that no menus are enabled.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'menu_options[main]' => FALSE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
|
||||
|
||||
// Verify that no menu settings are displayed and nodes can be created.
|
||||
|
@ -78,47 +78,47 @@ class MenuNodeTest extends WebTestBase {
|
|||
$this->assertText(t('Create Basic page'));
|
||||
$this->assertNoText(t('Menu settings'));
|
||||
$node_title = $this->randomMachineName();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'title[0][value]' => $node_title,
|
||||
'body[0][value]' => $this->randomString(),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$node = $this->drupalGetNodeByTitle($node_title);
|
||||
$this->assertEqual($node->getTitle(), $edit['title[0][value]']);
|
||||
|
||||
// Test that we cannot set a menu item from a menu that is not set as
|
||||
// available.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'menu_options[tools]' => 1,
|
||||
'menu_parent' => 'main:',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
|
||||
$this->assertText(t('The selected menu item is not under one of the selected menus.'));
|
||||
$this->assertNoRaw(t('The content type %name has been updated.', array('%name' => 'Basic page')));
|
||||
$this->assertNoRaw(t('The content type %name has been updated.', ['%name' => 'Basic page']));
|
||||
|
||||
// Enable Tools menu as available menu.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'menu_options[main]' => 1,
|
||||
'menu_options[tools]' => 1,
|
||||
'menu_parent' => 'main:',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
|
||||
$this->assertRaw(t('The content type %name has been updated.', array('%name' => 'Basic page')));
|
||||
$this->assertRaw(t('The content type %name has been updated.', ['%name' => 'Basic page']));
|
||||
|
||||
// Test that we can preview a node that will create a menu item.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'title[0][value]' => $node_title,
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => 'Test preview',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('node/add/page', $edit, t('Preview'));
|
||||
|
||||
// Create a node.
|
||||
$node_title = $this->randomMachineName();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'title[0][value]' => $node_title,
|
||||
'body[0][value]' => $this->randomString(),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('node/add/page', $edit, t('Save'));
|
||||
$node = $this->drupalGetNodeByTitle($node_title);
|
||||
// Assert that there is no link for the node.
|
||||
|
@ -126,9 +126,9 @@ class MenuNodeTest extends WebTestBase {
|
|||
$this->assertNoLink($node_title);
|
||||
|
||||
// Edit the node, enable the menu link setting, but skip the link title.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'menu[enabled]' => 1,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
// Assert that there is no link for the node.
|
||||
$this->drupalGet('test-page');
|
||||
|
@ -165,11 +165,11 @@ class MenuNodeTest extends WebTestBase {
|
|||
// Log back in as normal user.
|
||||
$this->drupalLogin($this->editor);
|
||||
// Edit the node and create a menu link.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => $node_title,
|
||||
'menu[weight]' => 17,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
// Assert that the link exists.
|
||||
$this->drupalGet('test-page');
|
||||
|
@ -190,20 +190,20 @@ class MenuNodeTest extends WebTestBase {
|
|||
$this->assertFalse($link->isEnabled(), 'Saving a node with a disabled menu link keeps the menu link disabled.');
|
||||
|
||||
// Edit the node and remove the menu link.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'menu[enabled]' => FALSE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
// Assert that there is no link for the node.
|
||||
$this->drupalGet('test-page');
|
||||
$this->assertNoLink($node_title);
|
||||
|
||||
// Add a menu link to the Administration menu.
|
||||
$item = MenuLinkContent::create(array(
|
||||
$item = MenuLinkContent::create([
|
||||
'link' => [['uri' => 'entity:node/' . $node->id()]],
|
||||
'title' => $this->randomMachineName(16),
|
||||
'menu_name' => 'admin',
|
||||
));
|
||||
]);
|
||||
$item->save();
|
||||
|
||||
// Assert that disabled Administration menu is not shown on the
|
||||
|
@ -219,14 +219,14 @@ class MenuNodeTest extends WebTestBase {
|
|||
$item->menu_name->value = 'tools';
|
||||
$item->save();
|
||||
// Create a second node.
|
||||
$child_node = $this->drupalCreateNode(array('type' => 'article'));
|
||||
$child_node = $this->drupalCreateNode(['type' => 'article']);
|
||||
// Assign a menu link to the second node, being a child of the first one.
|
||||
$child_item = MenuLinkContent::create(array(
|
||||
$child_item = MenuLinkContent::create([
|
||||
'link' => [['uri' => 'entity:node/' . $child_node->id()]],
|
||||
'title' => $this->randomMachineName(16),
|
||||
'parent' => $item->getPluginId(),
|
||||
'menu_name' => $item->getMenuName(),
|
||||
));
|
||||
]);
|
||||
$child_item->save();
|
||||
// Edit the first node.
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
|
@ -240,9 +240,9 @@ class MenuNodeTest extends WebTestBase {
|
|||
/**
|
||||
* Testing correct loading and saving of menu links via node form widget in a multilingual environment.
|
||||
*/
|
||||
function testMultilingualMenuNodeFormWidget() {
|
||||
public function testMultilingualMenuNodeFormWidget() {
|
||||
// Setup languages.
|
||||
$langcodes = array('de');
|
||||
$langcodes = ['de'];
|
||||
foreach ($langcodes as $langcode) {
|
||||
ConfigurableLanguage::createFromLangcode($langcode)->save();
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ class MenuNodeTest extends WebTestBase {
|
|||
|
||||
$this->rebuildContainer();
|
||||
|
||||
$languages = array();
|
||||
$languages = [];
|
||||
foreach ($langcodes as $langcode) {
|
||||
$languages[$langcode] = ConfigurableLanguage::load($langcode);
|
||||
}
|
||||
|
@ -265,14 +265,14 @@ class MenuNodeTest extends WebTestBase {
|
|||
// Use a UI form submission to make the node type and menu link content entity translatable.
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'entity_types[node]' => TRUE,
|
||||
'entity_types[menu_link_content]' => TRUE,
|
||||
'settings[node][page][settings][language][language_alterable]' => TRUE,
|
||||
'settings[node][page][translatable]' => TRUE,
|
||||
'settings[node][page][fields][title]' => TRUE,
|
||||
'settings[menu_link_content][menu_link_content][translatable]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
|
||||
|
||||
// Log out and back in as normal user.
|
||||
|
@ -297,42 +297,42 @@ class MenuNodeTest extends WebTestBase {
|
|||
$node->save();
|
||||
|
||||
// Edit the node and create a menu link.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => $node_title,
|
||||
'menu[weight]' => 17,
|
||||
);
|
||||
$options = array('language' => $languages[$langcodes[0]]);
|
||||
];
|
||||
$options = ['language' => $languages[$langcodes[0]]];
|
||||
$url = $node->toUrl('edit-form', $options);
|
||||
$this->drupalPostForm($url, $edit, t('Save') . ' ' . t('(this translation)'));
|
||||
|
||||
// Edit the node in a different language and translate the menu link.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'menu[enabled]' => 1,
|
||||
'menu[title]' => $translated_node_title,
|
||||
'menu[weight]' => 17,
|
||||
);
|
||||
$options = array('language' => $languages[$langcodes[1]]);
|
||||
];
|
||||
$options = ['language' => $languages[$langcodes[1]]];
|
||||
$url = $node->toUrl('edit-form', $options);
|
||||
$this->drupalPostForm($url, $edit, t('Save') . ' ' . t('(this translation)'));
|
||||
|
||||
// Assert that the original link exists in the frontend.
|
||||
$this->drupalGet('node/' . $node->id(), array('language' => $languages[$langcodes[0]]));
|
||||
$this->drupalGet('node/' . $node->id(), ['language' => $languages[$langcodes[0]]]);
|
||||
$this->assertLink($node_title);
|
||||
|
||||
// Assert that the translated link exists in the frontend.
|
||||
$this->drupalGet('node/' . $node->id(), array('language' => $languages[$langcodes[1]]));
|
||||
$this->drupalGet('node/' . $node->id(), ['language' => $languages[$langcodes[1]]]);
|
||||
$this->assertLink($translated_node_title);
|
||||
|
||||
// Revisit the edit page in original language, check the loaded menu item title and save.
|
||||
$options = array('language' => $languages[$langcodes[0]]);
|
||||
$options = ['language' => $languages[$langcodes[0]]];
|
||||
$url = $node->toUrl('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
$this->assertFieldById('edit-menu-title', $node_title);
|
||||
$this->drupalPostForm(NULL, [], t('Save') . ' ' . t('(this translation)'));
|
||||
|
||||
// Revisit the edit page of the translation and check the loaded menu item title.
|
||||
$options = array('language' => $languages[$langcodes[1]]);
|
||||
$options = ['language' => $languages[$langcodes[1]]];
|
||||
$url = $node->toUrl('edit-form', $options);
|
||||
$this->drupalGet($url);
|
||||
$this->assertFieldById('edit-menu-title', $translated_node_title);
|
||||
|
|
|
@ -10,6 +10,7 @@ use Drupal\Core\Url;
|
|||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
use Drupal\system\Entity\Menu;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
* Add a custom menu, add menu links to the custom menu and Tools menu, check
|
||||
|
@ -24,7 +25,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'block', 'contextual', 'help', 'path', 'test_page_test');
|
||||
public static $modules = ['node', 'block', 'contextual', 'help', 'path', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* A user with administration rights.
|
||||
|
@ -66,20 +67,20 @@ class MenuTest extends MenuWebTestBase {
|
|||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
||||
// Create users.
|
||||
$this->adminUser = $this->drupalCreateUser(array('access administration pages', 'administer blocks', 'administer menu', 'create article content'));
|
||||
$this->authenticatedUser = $this->drupalCreateUser(array());
|
||||
$this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer blocks', 'administer menu', 'create article content']);
|
||||
$this->authenticatedUser = $this->drupalCreateUser([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests menu functionality using the admin and user interfaces.
|
||||
*/
|
||||
function testMenu() {
|
||||
public function testMenu() {
|
||||
// Log in the user.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->items = array();
|
||||
$this->items = [];
|
||||
|
||||
$this->menu = $this->addCustomMenu();
|
||||
$this->doMenuTests();
|
||||
|
@ -131,7 +132,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
$instance = $this->getStandardMenuLink();
|
||||
$old_weight = $instance->getWeight();
|
||||
// Edit the static menu link.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['weight'] = 10;
|
||||
$id = $instance->getPluginId();
|
||||
$this->drupalPostForm("admin/structure/menu/link/$id/edit", $edit, t('Save'));
|
||||
|
@ -147,16 +148,16 @@ class MenuTest extends MenuWebTestBase {
|
|||
/**
|
||||
* Adds a custom menu using CRUD functions.
|
||||
*/
|
||||
function addCustomMenuCRUD() {
|
||||
public function addCustomMenuCRUD() {
|
||||
// Add a new custom menu.
|
||||
$menu_name = substr(hash('sha256', $this->randomMachineName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
|
||||
$label = $this->randomMachineName(16);
|
||||
|
||||
$menu = Menu::create(array(
|
||||
$menu = Menu::create([
|
||||
'id' => $menu_name,
|
||||
'label' => $label,
|
||||
'description' => 'Description text',
|
||||
));
|
||||
]);
|
||||
$menu->save();
|
||||
|
||||
// Assert the new menu.
|
||||
|
@ -177,25 +178,25 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @return \Drupal\system\Entity\Menu
|
||||
* The custom menu that has been created.
|
||||
*/
|
||||
function addCustomMenu() {
|
||||
public function addCustomMenu() {
|
||||
// Try adding a menu using a menu_name that is too long.
|
||||
$this->drupalGet('admin/structure/menu/add');
|
||||
$menu_name = substr(hash('sha256', $this->randomMachineName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI + 1);
|
||||
$label = $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'id' => $menu_name,
|
||||
'description' => '',
|
||||
'label' => $label,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
|
||||
|
||||
// Verify that using a menu_name that is too long results in a validation
|
||||
// message.
|
||||
$this->assertRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', array(
|
||||
$this->assertRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', [
|
||||
'@name' => t('Menu name'),
|
||||
'%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
|
||||
'%length' => Unicode::strlen($menu_name),
|
||||
)));
|
||||
]));
|
||||
|
||||
// Change the menu_name so it no longer exceeds the maximum length.
|
||||
$menu_name = substr(hash('sha256', $this->randomMachineName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
|
||||
|
@ -203,13 +204,13 @@ class MenuTest extends MenuWebTestBase {
|
|||
$this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
|
||||
|
||||
// Verify that no validation error is given for menu_name length.
|
||||
$this->assertNoRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', array(
|
||||
$this->assertNoRaw(t('@name cannot be longer than %max characters but is currently %length characters long.', [
|
||||
'@name' => t('Menu name'),
|
||||
'%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
|
||||
'%length' => Unicode::strlen($menu_name),
|
||||
)));
|
||||
]));
|
||||
// Verify that the confirmation message is displayed.
|
||||
$this->assertRaw(t('Menu %label has been added.', array('%label' => $label)));
|
||||
$this->assertRaw(t('Menu %label has been added.', ['%label' => $label]));
|
||||
$this->drupalGet('admin/structure/menu');
|
||||
$this->assertText($label, 'Menu created');
|
||||
|
||||
|
@ -230,18 +231,18 @@ class MenuTest extends MenuWebTestBase {
|
|||
* This deletes the custom menu that is stored in $this->menu and performs
|
||||
* tests on the menu delete user interface.
|
||||
*/
|
||||
function deleteCustomMenu() {
|
||||
public function deleteCustomMenu() {
|
||||
$menu_name = $this->menu->id();
|
||||
$label = $this->menu->label();
|
||||
|
||||
// Delete custom menu.
|
||||
$this->drupalPostForm("admin/structure/menu/manage/$menu_name/delete", array(), t('Delete'));
|
||||
$this->drupalPostForm("admin/structure/menu/manage/$menu_name/delete", [], t('Delete'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertRaw(t('The menu %title has been deleted.', array('%title' => $label)), 'Custom menu was deleted');
|
||||
$this->assertRaw(t('The menu %title has been deleted.', ['%title' => $label]), 'Custom menu was deleted');
|
||||
$this->assertNull(Menu::load($menu_name), 'Custom menu was deleted');
|
||||
// Test if all menu links associated with the menu were removed from
|
||||
// database.
|
||||
$result = entity_load_multiple_by_properties('menu_link_content', array('menu_name' => $menu_name));
|
||||
$result = entity_load_multiple_by_properties('menu_link_content', ['menu_name' => $menu_name]);
|
||||
$this->assertFalse($result, 'All menu links associated with the custom menu were deleted.');
|
||||
|
||||
// Make sure there's no delete button on system menus.
|
||||
|
@ -256,7 +257,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
/**
|
||||
* Tests menu functionality.
|
||||
*/
|
||||
function doMenuTests() {
|
||||
public function doMenuTests() {
|
||||
$menu_name = $this->menu->id();
|
||||
|
||||
// Test the 'Add link' local action.
|
||||
|
@ -264,32 +265,32 @@ class MenuTest extends MenuWebTestBase {
|
|||
|
||||
$this->clickLink(t('Add link'));
|
||||
$link_title = $this->randomString();
|
||||
$this->drupalPostForm(NULL, array('link[0][uri]' => '/', 'title[0][value]' => $link_title), t('Save'));
|
||||
$this->drupalPostForm(NULL, ['link[0][uri]' => '/', 'title[0][value]' => $link_title], t('Save'));
|
||||
$this->assertUrl(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]));
|
||||
// Test the 'Edit' operation.
|
||||
$this->clickLink(t('Edit'));
|
||||
$this->assertFieldByName('title[0][value]', $link_title);
|
||||
$link_title = $this->randomString();
|
||||
$this->drupalPostForm(NULL, array('title[0][value]' => $link_title), t('Save'));
|
||||
$this->drupalPostForm(NULL, ['title[0][value]' => $link_title], t('Save'));
|
||||
$this->assertUrl(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]));
|
||||
// Test the 'Delete' operation.
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->assertRaw(t('Are you sure you want to delete the custom menu link %item?', array('%item' => $link_title)));
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->assertRaw(t('Are you sure you want to delete the custom menu link %item?', ['%item' => $link_title]));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$this->assertUrl(Url::fromRoute('entity.menu.edit_form', ['menu' => $menu_name]));
|
||||
|
||||
// Add nodes to use as links for menu links.
|
||||
$node1 = $this->drupalCreateNode(array('type' => 'article'));
|
||||
$node2 = $this->drupalCreateNode(array('type' => 'article'));
|
||||
$node3 = $this->drupalCreateNode(array('type' => 'article'));
|
||||
$node4 = $this->drupalCreateNode(array('type' => 'article'));
|
||||
$node1 = $this->drupalCreateNode(['type' => 'article']);
|
||||
$node2 = $this->drupalCreateNode(['type' => 'article']);
|
||||
$node3 = $this->drupalCreateNode(['type' => 'article']);
|
||||
$node4 = $this->drupalCreateNode(['type' => 'article']);
|
||||
// Create a node with an alias.
|
||||
$node5 = $this->drupalCreateNode(array(
|
||||
$node5 = $this->drupalCreateNode([
|
||||
'type' => 'article',
|
||||
'path' => array(
|
||||
'path' => [
|
||||
'alias' => '/node5',
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
|
||||
// Verify add link button.
|
||||
$this->drupalGet('admin/structure/menu');
|
||||
|
@ -309,25 +310,25 @@ class MenuTest extends MenuWebTestBase {
|
|||
// -- item2
|
||||
// --- item3
|
||||
|
||||
$this->assertMenuLink($item1->getPluginId(), array(
|
||||
'children' => array($item2->getPluginId(), $item3->getPluginId()),
|
||||
'parents' => array($item1->getPluginId()),
|
||||
$this->assertMenuLink($item1->getPluginId(), [
|
||||
'children' => [$item2->getPluginId(), $item3->getPluginId()],
|
||||
'parents' => [$item1->getPluginId()],
|
||||
// We assert the language code here to make sure that the language
|
||||
// selection element degrades gracefully without the Language module.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
$this->assertMenuLink($item2->getPluginId(), array(
|
||||
'children' => array($item3->getPluginId()),
|
||||
'parents' => array($item2->getPluginId(), $item1->getPluginId()),
|
||||
]);
|
||||
$this->assertMenuLink($item2->getPluginId(), [
|
||||
'children' => [$item3->getPluginId()],
|
||||
'parents' => [$item2->getPluginId(), $item1->getPluginId()],
|
||||
// See above.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
$this->assertMenuLink($item3->getPluginId(), array(
|
||||
'children' => array(),
|
||||
'parents' => array($item3->getPluginId(), $item2->getPluginId(), $item1->getPluginId()),
|
||||
]);
|
||||
$this->assertMenuLink($item3->getPluginId(), [
|
||||
'children' => [],
|
||||
'parents' => [$item3->getPluginId(), $item2->getPluginId(), $item1->getPluginId()],
|
||||
// See above.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
]);
|
||||
|
||||
// Verify menu links.
|
||||
$this->verifyMenuLink($item1, $node1);
|
||||
|
@ -349,26 +350,26 @@ class MenuTest extends MenuWebTestBase {
|
|||
// -- item5
|
||||
// -- item6
|
||||
|
||||
$this->assertMenuLink($item4->getPluginId(), array(
|
||||
'children' => array($item5->getPluginId(), $item6->getPluginId()),
|
||||
'parents' => array($item4->getPluginId()),
|
||||
$this->assertMenuLink($item4->getPluginId(), [
|
||||
'children' => [$item5->getPluginId(), $item6->getPluginId()],
|
||||
'parents' => [$item4->getPluginId()],
|
||||
// See above.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
$this->assertMenuLink($item5->getPluginId(), array(
|
||||
'children' => array(),
|
||||
'parents' => array($item5->getPluginId(), $item4->getPluginId()),
|
||||
]);
|
||||
$this->assertMenuLink($item5->getPluginId(), [
|
||||
'children' => [],
|
||||
'parents' => [$item5->getPluginId(), $item4->getPluginId()],
|
||||
'langcode' => 'en',
|
||||
));
|
||||
$this->assertMenuLink($item6->getPluginId(), array(
|
||||
'children' => array(),
|
||||
'parents' => array($item6->getPluginId(), $item4->getPluginId()),
|
||||
]);
|
||||
$this->assertMenuLink($item6->getPluginId(), [
|
||||
'children' => [],
|
||||
'parents' => [$item6->getPluginId(), $item4->getPluginId()],
|
||||
'route_name' => 'entity.node.canonical',
|
||||
'route_parameters' => array('node' => $node5->id()),
|
||||
'route_parameters' => ['node' => $node5->id()],
|
||||
'url' => '',
|
||||
// See above.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
]);
|
||||
|
||||
// Modify menu links.
|
||||
$this->modifyMenuLink($item1);
|
||||
|
@ -389,49 +390,49 @@ class MenuTest extends MenuWebTestBase {
|
|||
// ---- item3
|
||||
// -- item6
|
||||
|
||||
$this->assertMenuLink($item1->getPluginId(), array(
|
||||
'children' => array(),
|
||||
'parents' => array($item1->getPluginId()),
|
||||
$this->assertMenuLink($item1->getPluginId(), [
|
||||
'children' => [],
|
||||
'parents' => [$item1->getPluginId()],
|
||||
// See above.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
$this->assertMenuLink($item4->getPluginId(), array(
|
||||
'children' => array($item5->getPluginId(), $item6->getPluginId(), $item2->getPluginId(), $item3->getPluginId()),
|
||||
'parents' => array($item4->getPluginId()),
|
||||
]);
|
||||
$this->assertMenuLink($item4->getPluginId(), [
|
||||
'children' => [$item5->getPluginId(), $item6->getPluginId(), $item2->getPluginId(), $item3->getPluginId()],
|
||||
'parents' => [$item4->getPluginId()],
|
||||
// See above.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
]);
|
||||
|
||||
$this->assertMenuLink($item5->getPluginId(), array(
|
||||
'children' => array($item2->getPluginId(), $item3->getPluginId()),
|
||||
'parents' => array($item5->getPluginId(), $item4->getPluginId()),
|
||||
$this->assertMenuLink($item5->getPluginId(), [
|
||||
'children' => [$item2->getPluginId(), $item3->getPluginId()],
|
||||
'parents' => [$item5->getPluginId(), $item4->getPluginId()],
|
||||
// See above.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
$this->assertMenuLink($item2->getPluginId(), array(
|
||||
'children' => array($item3->getPluginId()),
|
||||
'parents' => array($item2->getPluginId(), $item5->getPluginId(), $item4->getPluginId()),
|
||||
]);
|
||||
$this->assertMenuLink($item2->getPluginId(), [
|
||||
'children' => [$item3->getPluginId()],
|
||||
'parents' => [$item2->getPluginId(), $item5->getPluginId(), $item4->getPluginId()],
|
||||
// See above.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
$this->assertMenuLink($item3->getPluginId(), array(
|
||||
'children' => array(),
|
||||
'parents' => array($item3->getPluginId(), $item2->getPluginId(), $item5->getPluginId(), $item4->getPluginId()),
|
||||
]);
|
||||
$this->assertMenuLink($item3->getPluginId(), [
|
||||
'children' => [],
|
||||
'parents' => [$item3->getPluginId(), $item2->getPluginId(), $item5->getPluginId(), $item4->getPluginId()],
|
||||
// See above.
|
||||
'langcode' => 'en',
|
||||
));
|
||||
]);
|
||||
|
||||
// Add 102 menu links with increasing weights, then make sure the last-added
|
||||
// item's weight doesn't get changed because of the old hardcoded delta=50.
|
||||
$items = array();
|
||||
$items = [];
|
||||
for ($i = -50; $i <= 51; $i++) {
|
||||
$items[$i] = $this->addMenuLink('', '/node/' . $node1->id(), $menu_name, TRUE, strval($i));
|
||||
}
|
||||
$this->assertMenuLink($items[51]->getPluginId(), array('weight' => '51'));
|
||||
$this->assertMenuLink($items[51]->getPluginId(), ['weight' => '51']);
|
||||
|
||||
// Disable a link and then re-enable the link via the overview form.
|
||||
$this->disableMenuLink($item1);
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['links[menu_plugin_id:' . $item1->getPluginId() . '][enabled]'] = TRUE;
|
||||
$this->drupalPostForm('admin/structure/menu/manage/' . $item1->getMenuName(), $edit, t('Save'));
|
||||
|
||||
|
@ -445,15 +446,15 @@ class MenuTest extends MenuWebTestBase {
|
|||
$item5->save();
|
||||
|
||||
// Verify in the database.
|
||||
$this->assertMenuLink($item1->getPluginId(), array('enabled' => 1));
|
||||
$this->assertMenuLink($item1->getPluginId(), ['enabled' => 1]);
|
||||
|
||||
// Add an external link.
|
||||
$item7 = $this->addMenuLink('', 'https://www.drupal.org', $menu_name);
|
||||
$this->assertMenuLink($item7->getPluginId(), array('url' => 'https://www.drupal.org'));
|
||||
$this->assertMenuLink($item7->getPluginId(), ['url' => 'https://www.drupal.org']);
|
||||
|
||||
// Add <front> menu item.
|
||||
$item8 = $this->addMenuLink('', '/', $menu_name);
|
||||
$this->assertMenuLink($item8->getPluginId(), array('route_name' => '<front>'));
|
||||
$this->assertMenuLink($item8->getPluginId(), ['route_name' => '<front>']);
|
||||
$this->drupalGet('');
|
||||
$this->assertResponse(200);
|
||||
// Make sure we get routed correctly.
|
||||
|
@ -488,7 +489,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
/**
|
||||
* Adds and removes a menu link with a query string and fragment.
|
||||
*/
|
||||
function testMenuQueryAndFragment() {
|
||||
public function testMenuQueryAndFragment() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Make a path with query and fragment on.
|
||||
|
@ -500,7 +501,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
|
||||
// Now change the path to something without query and fragment.
|
||||
$path = '/test-page';
|
||||
$this->drupalPostForm('admin/structure/menu/item/' . $item->id() . '/edit', array('link[0][uri]' => $path), t('Save'));
|
||||
$this->drupalPostForm('admin/structure/menu/item/' . $item->id() . '/edit', ['link[0][uri]' => $path], t('Save'));
|
||||
$this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
|
||||
$this->assertFieldByName('link[0][uri]', $path, 'Path no longer has query or fragment.');
|
||||
|
||||
|
@ -511,7 +512,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
$this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
|
||||
$this->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.');
|
||||
|
||||
$this->drupalPostForm('admin/structure/menu/item/' . $item->id() . '/edit', array(), t('Save'));
|
||||
$this->drupalPostForm('admin/structure/menu/item/' . $item->id() . '/edit', [], t('Save'));
|
||||
|
||||
$this->drupalGet('admin/structure/menu/item/' . $item->id() . '/edit');
|
||||
$this->assertFieldByName('link[0][uri]', $path, 'Path is found with both query and fragment.');
|
||||
|
@ -520,11 +521,11 @@ class MenuTest extends MenuWebTestBase {
|
|||
/**
|
||||
* Tests renaming the built-in menu.
|
||||
*/
|
||||
function testSystemMenuRename() {
|
||||
public function testSystemMenuRename() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'label' => $this->randomMachineName(16),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/menu/manage/main', $edit, t('Save'));
|
||||
|
||||
// Make sure menu shows up with new name in block addition.
|
||||
|
@ -537,13 +538,13 @@ class MenuTest extends MenuWebTestBase {
|
|||
/**
|
||||
* Tests that menu items pointing to unpublished nodes are editable.
|
||||
*/
|
||||
function testUnpublishedNodeMenuItem() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer blocks', 'administer menu', 'create article content', 'bypass node access')));
|
||||
public function testUnpublishedNodeMenuItem() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['access administration pages', 'administer blocks', 'administer menu', 'create article content', 'bypass node access']));
|
||||
// Create an unpublished node.
|
||||
$node = $this->drupalCreateNode(array(
|
||||
$node = $this->drupalCreateNode([
|
||||
'type' => 'article',
|
||||
'status' => NODE_NOT_PUBLISHED,
|
||||
));
|
||||
'status' => NodeInterface::NOT_PUBLISHED,
|
||||
]);
|
||||
|
||||
$item = $this->addMenuLink('', '/node/' . $node->id());
|
||||
$this->modifyMenuLink($item);
|
||||
|
@ -563,20 +564,20 @@ class MenuTest extends MenuWebTestBase {
|
|||
* Tests the contextual links on a menu block.
|
||||
*/
|
||||
public function testBlockContextualLinks() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer menu', 'access contextual links', 'administer blocks')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer menu', 'access contextual links', 'administer blocks']));
|
||||
$custom_menu = $this->addCustomMenu();
|
||||
$this->addMenuLink('', '/', $custom_menu->id());
|
||||
$block = $this->drupalPlaceBlock('system_menu_block:' . $custom_menu->id(), array('label' => 'Custom menu', 'provider' => 'system'));
|
||||
$block = $this->drupalPlaceBlock('system_menu_block:' . $custom_menu->id(), ['label' => 'Custom menu', 'provider' => 'system']);
|
||||
$this->drupalGet('test-page');
|
||||
|
||||
$id = 'block:block=' . $block->id() . ':langcode=en|menu:menu=' . $custom_menu->id() . ':langcode=en';
|
||||
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder()
|
||||
$this->assertRaw('<div data-contextual-id="' . $id . '"></div>', format_string('Contextual link placeholder with id @id exists.', array('@id' => $id)));
|
||||
$this->assertRaw('<div data-contextual-id="' . $id . '"></div>', format_string('Contextual link placeholder with id @id exists.', ['@id' => $id]));
|
||||
|
||||
// Get server-rendered contextual links.
|
||||
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()
|
||||
$post = array('ids[0]' => $id);
|
||||
$response = $this->drupalPost('contextual/render', 'application/json', $post, array('query' => array('destination' => 'test-page')));
|
||||
$post = ['ids[0]' => $id];
|
||||
$response = $this->drupalPost('contextual/render', 'application/json', $post, ['query' => ['destination' => 'test-page']]);
|
||||
$this->assertResponse(200);
|
||||
$json = Json::decode($response);
|
||||
$this->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li class="entitymenuedit-form"><a href="' . base_path() . 'admin/structure/menu/manage/' . $custom_menu->id() . '">Edit menu</a></li></ul>');
|
||||
|
@ -601,13 +602,13 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @return \Drupal\menu_link_content\Entity\MenuLinkContent
|
||||
* A menu link entity.
|
||||
*/
|
||||
function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $expanded = FALSE, $weight = '0') {
|
||||
public function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $expanded = FALSE, $weight = '0') {
|
||||
// View add menu link page.
|
||||
$this->drupalGet("admin/structure/menu/manage/$menu_name/add");
|
||||
$this->assertResponse(200);
|
||||
|
||||
$title = '!link_' . $this->randomMachineName(16);
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'link[0][uri]' => $path,
|
||||
'title[0][value]' => $title,
|
||||
'description[0][value]' => '',
|
||||
|
@ -615,18 +616,18 @@ class MenuTest extends MenuWebTestBase {
|
|||
'expanded[value]' => $expanded,
|
||||
'menu_parent' => $menu_name . ':' . $parent,
|
||||
'weight[0][value]' => $weight,
|
||||
);
|
||||
];
|
||||
|
||||
// Add menu link.
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('The menu link has been saved.');
|
||||
|
||||
$menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $title));
|
||||
$menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $title]);
|
||||
|
||||
$menu_link = reset($menu_links);
|
||||
$this->assertTrue($menu_link, 'Menu link was found in database.');
|
||||
$this->assertMenuLink($menu_link->getPluginId(), array('menu_name' => $menu_name, 'children' => array(), 'parent' => $parent));
|
||||
$this->assertMenuLink($menu_link->getPluginId(), ['menu_name' => $menu_name, 'children' => [], 'parent' => $parent]);
|
||||
|
||||
return $menu_link;
|
||||
}
|
||||
|
@ -634,23 +635,23 @@ class MenuTest extends MenuWebTestBase {
|
|||
/**
|
||||
* Attempts to add menu link with invalid path or no access permission.
|
||||
*/
|
||||
function addInvalidMenuLink() {
|
||||
foreach (array('access' => '/admin/people/permissions') as $type => $link_path) {
|
||||
$edit = array(
|
||||
public function addInvalidMenuLink() {
|
||||
foreach (['access' => '/admin/people/permissions'] as $type => $link_path) {
|
||||
$edit = [
|
||||
'link[0][uri]' => $link_path,
|
||||
'title[0][value]' => 'title',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm("admin/structure/menu/manage/{$this->menu->id()}/add", $edit, t('Save'));
|
||||
$this->assertRaw(t("The path '@link_path' is inaccessible.", array('@link_path' => $link_path)), 'Menu link was not created');
|
||||
$this->assertRaw(t("The path '@link_path' is inaccessible.", ['@link_path' => $link_path]), 'Menu link was not created');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that parent options are limited by depth when adding menu links.
|
||||
*/
|
||||
function checkInvalidParentMenuLinks() {
|
||||
public function checkInvalidParentMenuLinks() {
|
||||
$last_link = NULL;
|
||||
$created_links = array();
|
||||
$created_links = [];
|
||||
|
||||
// Get the max depth of the tree.
|
||||
$menu_link_tree = \Drupal::service('menu.link_tree');
|
||||
|
@ -660,7 +661,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
for ($i = 0; $i <= $max_depth - 1; $i++) {
|
||||
$parent = $last_link ? 'tools:' . $last_link->getPluginId() : 'tools:';
|
||||
$title = 'title' . $i;
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'link[0][uri]' => '/',
|
||||
'title[0][value]' => $title,
|
||||
'menu_parent' => $parent,
|
||||
|
@ -668,9 +669,9 @@ class MenuTest extends MenuWebTestBase {
|
|||
'enabled[value]' => 1,
|
||||
'expanded[value]' => FALSE,
|
||||
'weight[0][value]' => '0',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm("admin/structure/menu/manage/{$this->menu->id()}/add", $edit, t('Save'));
|
||||
$menu_links = entity_load_multiple_by_properties('menu_link_content', array('title' => $title));
|
||||
$menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $title]);
|
||||
$last_link = reset($menu_links);
|
||||
$created_links[] = 'tools:' . $last_link->getPluginId();
|
||||
}
|
||||
|
@ -699,7 +700,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @param object $parent_node
|
||||
* Parent menu link content node.
|
||||
*/
|
||||
function verifyMenuLink(MenuLinkContent $item, $item_node, MenuLinkContent $parent = NULL, $parent_node = NULL) {
|
||||
public function verifyMenuLink(MenuLinkContent $item, $item_node, MenuLinkContent $parent = NULL, $parent_node = NULL) {
|
||||
// View home page.
|
||||
$this->drupalGet('');
|
||||
$this->assertResponse(200);
|
||||
|
@ -713,7 +714,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
// Verify menu link link.
|
||||
$this->clickLink($title);
|
||||
$title = $parent_node->label();
|
||||
$this->assertTitle(t("@title | Drupal", array('@title' => $title)), 'Parent menu link link target was correct');
|
||||
$this->assertTitle(t("@title | Drupal", ['@title' => $title]), 'Parent menu link link target was correct');
|
||||
}
|
||||
|
||||
// Verify menu link.
|
||||
|
@ -723,7 +724,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
// Verify menu link link.
|
||||
$this->clickLink($title);
|
||||
$title = $item_node->label();
|
||||
$this->assertTitle(t("@title | Drupal", array('@title' => $title)), 'Menu link link target was correct');
|
||||
$this->assertTitle(t("@title | Drupal", ['@title' => $title]), 'Menu link link target was correct');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -736,12 +737,12 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @param string $menu_name
|
||||
* The menu the menu link will be moved to.
|
||||
*/
|
||||
function moveMenuLink(MenuLinkContent $item, $parent, $menu_name) {
|
||||
public function moveMenuLink(MenuLinkContent $item, $parent, $menu_name) {
|
||||
$mlid = $item->id();
|
||||
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'menu_parent' => $menu_name . ':' . $parent,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
@ -752,14 +753,14 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
|
||||
* Menu link entity.
|
||||
*/
|
||||
function modifyMenuLink(MenuLinkContent $item) {
|
||||
public function modifyMenuLink(MenuLinkContent $item) {
|
||||
$item->title->value = $this->randomMachineName(16);
|
||||
|
||||
$mlid = $item->id();
|
||||
$title = $item->getTitle();
|
||||
|
||||
// Edit menu link.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['title[0][value]'] = $title;
|
||||
$this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
|
||||
$this->assertResponse(200);
|
||||
|
@ -777,9 +778,9 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @param int $old_weight
|
||||
* Original title for menu link.
|
||||
*/
|
||||
function resetMenuLink(MenuLinkInterface $menu_link, $old_weight) {
|
||||
public function resetMenuLink(MenuLinkInterface $menu_link, $old_weight) {
|
||||
// Reset menu link.
|
||||
$this->drupalPostForm("admin/structure/menu/link/{$menu_link->getPluginId()}/reset", array(), t('Reset'));
|
||||
$this->drupalPostForm("admin/structure/menu/link/{$menu_link->getPluginId()}/reset", [], t('Reset'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertRaw(t('The menu link was reset to its default settings.'), 'Menu link was reset');
|
||||
|
||||
|
@ -794,14 +795,14 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
|
||||
* Menu link.
|
||||
*/
|
||||
function deleteMenuLink(MenuLinkContent $item) {
|
||||
public function deleteMenuLink(MenuLinkContent $item) {
|
||||
$mlid = $item->id();
|
||||
$title = $item->getTitle();
|
||||
|
||||
// Delete menu link.
|
||||
$this->drupalPostForm("admin/structure/menu/item/$mlid/delete", array(), t('Delete'));
|
||||
$this->drupalPostForm("admin/structure/menu/item/$mlid/delete", [], t('Delete'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertRaw(t('The menu link %title has been deleted.', array('%title' => $title)), 'Menu link was deleted');
|
||||
$this->assertRaw(t('The menu link %title has been deleted.', ['%title' => $title]), 'Menu link was deleted');
|
||||
|
||||
// Verify deletion.
|
||||
$this->drupalGet('');
|
||||
|
@ -814,7 +815,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
|
||||
* Menu link.
|
||||
*/
|
||||
function toggleMenuLink(MenuLinkContent $item) {
|
||||
public function toggleMenuLink(MenuLinkContent $item) {
|
||||
$this->disableMenuLink($item);
|
||||
|
||||
// Verify menu link is absent.
|
||||
|
@ -833,14 +834,14 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
|
||||
* Menu link.
|
||||
*/
|
||||
function disableMenuLink(MenuLinkContent $item) {
|
||||
public function disableMenuLink(MenuLinkContent $item) {
|
||||
$mlid = $item->id();
|
||||
$edit['enabled[value]'] = FALSE;
|
||||
$this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
|
||||
|
||||
// Unlike most other modules, there is no confirmation message displayed.
|
||||
// Verify in the database.
|
||||
$this->assertMenuLink($item->getPluginId(), array('enabled' => 0));
|
||||
$this->assertMenuLink($item->getPluginId(), ['enabled' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -849,13 +850,13 @@ class MenuTest extends MenuWebTestBase {
|
|||
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $item
|
||||
* Menu link.
|
||||
*/
|
||||
function enableMenuLink(MenuLinkContent $item) {
|
||||
public function enableMenuLink(MenuLinkContent $item) {
|
||||
$mlid = $item->id();
|
||||
$edit['enabled[value]'] = TRUE;
|
||||
$this->drupalPostForm("admin/structure/menu/item/$mlid/edit", $edit, t('Save'));
|
||||
|
||||
// Verify in the database.
|
||||
$this->assertMenuLink($item->getPluginId(), array('enabled' => 1));
|
||||
$this->assertMenuLink($item->getPluginId(), ['enabled' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -863,7 +864,7 @@ class MenuTest extends MenuWebTestBase {
|
|||
* AJAX callback.
|
||||
*/
|
||||
public function testMenuParentsJsAccess() {
|
||||
$admin = $this->drupalCreateUser(array('administer menu'));
|
||||
$admin = $this->drupalCreateUser(['administer menu']);
|
||||
$this->drupalLogin($admin);
|
||||
// Just check access to the callback overall, the POST data is irrelevant.
|
||||
$this->drupalGetAjax('admin/structure/menu/parents');
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\menu_ui\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\system\Entity\Menu;
|
||||
|
||||
/**
|
||||
* Tests that uninstalling menu does not remove custom menus.
|
||||
*
|
||||
* @group menu_ui
|
||||
*/
|
||||
class MenuUninstallTest extends WebTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('menu_ui');
|
||||
|
||||
/**
|
||||
* Tests Menu uninstall.
|
||||
*/
|
||||
public function testMenuUninstall() {
|
||||
\Drupal::service('module_installer')->uninstall(array('menu_ui'));
|
||||
|
||||
\Drupal::entityManager()->getStorage('menu')->resetCache(array('admin'));
|
||||
|
||||
$this->assertTrue(Menu::load('admin'), 'The \'admin\' menu still exists after uninstalling Menu UI module.');
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ abstract class MenuWebTestBase extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('menu_ui', 'menu_link_content');
|
||||
public static $modules = ['menu_ui', 'menu_link_content'];
|
||||
|
||||
/**
|
||||
* Fetches the menu item from the database and compares it to expected item.
|
||||
|
@ -24,7 +24,7 @@ abstract class MenuWebTestBase extends WebTestBase {
|
|||
* @param array $expected_item
|
||||
* Array containing properties to verify.
|
||||
*/
|
||||
function assertMenuLink($menu_plugin_id, array $expected_item) {
|
||||
public function assertMenuLink($menu_plugin_id, array $expected_item) {
|
||||
// Retrieve menu link.
|
||||
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
|
||||
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
|
||||
|
|
Reference in a new issue