Update core 8.3.0

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

View file

@ -18,10 +18,10 @@ function menu_link_content_help($route_name, RouteMatchInterface $route_match) {
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Custom Menu Links module allows users to create menu links. These links can be translated if multiple languages are used for the site.');
if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
$output .= ' ' . t('It is required by the Menu UI module, which provides an interface for managing menus and menu links. For more information, see the <a href=":menu-help">Menu UI module help page</a> and the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>.', array(':menu-help' => \Drupal::url('help.page', array('name' => 'menu_ui')), ':drupal-org-help' => 'https://www.drupal.org/documentation/modules/menu_link'));
$output .= ' ' . t('It is required by the Menu UI module, which provides an interface for managing menus and menu links. For more information, see the <a href=":menu-help">Menu UI module help page</a> and the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>.', [':menu-help' => \Drupal::url('help.page', ['name' => 'menu_ui']), ':drupal-org-help' => 'https://www.drupal.org/documentation/modules/menu_link']);
}
else {
$output .= ' ' . t('For more information, see the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>. If you enable the Menu UI module, it provides an interface for managing menus and menu links.', array(':drupal-org-help' => 'https://www.drupal.org/documentation/modules/menu_link'));
$output .= ' ' . t('For more information, see the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>. If you enable the Menu UI module, it provides an interface for managing menus and menu links.', [':drupal-org-help' => 'https://www.drupal.org/documentation/modules/menu_link']);
}
$output .= '</p>';
return $output;
@ -33,7 +33,7 @@ function menu_link_content_help($route_name, RouteMatchInterface $route_match) {
*/
function menu_link_content_menu_delete(MenuInterface $menu) {
$storage = \Drupal::entityManager()->getStorage('menu_link_content');
$menu_links = $storage->loadByProperties(array('menu_name' => $menu->id()));
$menu_links = $storage->loadByProperties(['menu_name' => $menu->id()]);
$storage->delete($menu_links);
}

View file

@ -20,12 +20,12 @@ class MenuController extends ControllerBase {
* Returns the menu link creation form.
*/
public function addLink(MenuInterface $menu) {
$menu_link = $this->entityManager()->getStorage('menu_link_content')->create(array(
$menu_link = $this->entityManager()->getStorage('menu_link_content')->create([
'id' => '',
'parent' => '',
'menu_name' => $menu->id(),
'bundle' => 'menu_link_content',
));
]);
return $this->entityFormBuilder()->getForm($menu_link);
}

View file

@ -133,7 +133,7 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf
* {@inheritdoc}
*/
public function getPluginDefinition() {
$definition = array();
$definition = [];
$definition['class'] = 'Drupal\menu_link_content\Plugin\Menu\MenuLinkContent';
$definition['menu_name'] = $this->getMenuName();
@ -155,7 +155,7 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf
$definition['description'] = $this->getDescription();
$definition['weight'] = $this->getWeight();
$definition['id'] = $this->getPluginId();
$definition['metadata'] = array('entity_id' => $this->id());
$definition['metadata'] = ['entity_id' => $this->id()];
$definition['form_class'] = '\Drupal\menu_link_content\Form\MenuLinkContentForm';
$definition['enabled'] = $this->isEnabled() ? 1 : 0;
$definition['expanded'] = $this->isExpanded() ? 1 : 0;
@ -256,15 +256,15 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf
->setRequired(TRUE)
->setTranslatable(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('view', array(
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
'weight' => -5,
))
->setDisplayOptions('form', array(
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -5,
))
])
->setDisplayConfigurable('form', TRUE);
$fields['description'] = BaseFieldDefinition::create('string')
@ -272,15 +272,15 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf
->setDescription(t('Shown when hovering over the menu link.'))
->setTranslatable(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('view', array(
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
'weight' => 0,
))
->setDisplayOptions('form', array(
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 0,
));
]);
$fields['menu_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Menu name'))
@ -292,14 +292,14 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf
->setLabel(t('Link'))
->setDescription(t('The location this menu link points to.'))
->setRequired(TRUE)
->setSettings(array(
->setSettings([
'link_type' => LinkItemInterface::LINK_GENERIC,
'title' => DRUPAL_DISABLED,
))
->setDisplayOptions('form', array(
])
->setDisplayOptions('form', [
'type' => 'link_default',
'weight' => -2,
));
]);
$fields['external'] = BaseFieldDefinition::create('boolean')
->setLabel(t('External'))
@ -314,43 +314,43 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf
->setLabel(t('Weight'))
->setDescription(t('Link weight among links in the same menu at the same depth. In the menu, the links with high weight will sink and links with a low weight will be positioned nearer the top.'))
->setDefaultValue(0)
->setDisplayOptions('view', array(
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'integer',
'weight' => 0,
))
->setDisplayOptions('form', array(
])
->setDisplayOptions('form', [
'type' => 'number',
'weight' => 20,
));
]);
$fields['expanded'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Show as expanded'))
->setDescription(t('If selected and this menu link has children, the menu will always appear expanded.'))
->setDefaultValue(FALSE)
->setDisplayOptions('view', array(
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'boolean',
'weight' => 0,
))
->setDisplayOptions('form', array(
'settings' => array('display_label' => TRUE),
])
->setDisplayOptions('form', [
'settings' => ['display_label' => TRUE],
'weight' => 0,
));
]);
$fields['enabled'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Enabled'))
->setDescription(t('A flag for whether the link should be enabled in menus or hidden.'))
->setDefaultValue(TRUE)
->setDisplayOptions('view', array(
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'boolean',
'weight' => 0,
))
->setDisplayOptions('form', array(
'settings' => array('display_label' => TRUE),
])
->setDisplayOptions('form', [
'settings' => ['display_label' => TRUE],
'weight' => -1,
));
]);
$fields['parent'] = BaseFieldDefinition::create('string')
->setLabel(t('Parent plugin ID'))

View file

@ -15,7 +15,7 @@ class MenuLinkContentDeleteForm extends ContentEntityDeleteForm {
*/
public function getCancelUrl() {
if ($this->moduleHandler->moduleExists('menu_ui')) {
return new Url('entity.menu.edit_form', array('menu' => $this->entity->getMenuName()));
return new Url('entity.menu.edit_form', ['menu' => $this->entity->getMenuName()]);
}
return $this->entity->urlInfo();
}
@ -31,7 +31,7 @@ class MenuLinkContentDeleteForm extends ContentEntityDeleteForm {
* {@inheritdoc}
*/
protected function getDeletionMessage() {
return $this->t('The menu link %title has been deleted.', array('%title' => $this->entity->label()));
return $this->t('The menu link %title has been deleted.', ['%title' => $this->entity->label()]);
}
}

View file

@ -2,8 +2,10 @@
namespace Drupal\menu_link_content\Form;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
@ -47,9 +49,13 @@ class MenuLinkContentForm extends ContentEntityForm {
* The language manager.
* @param \Drupal\Core\Path\PathValidatorInterface $path_validator
* The path validator.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(EntityManagerInterface $entity_manager, MenuParentFormSelectorInterface $menu_parent_selector, LanguageManagerInterface $language_manager, PathValidatorInterface $path_validator) {
parent::__construct($entity_manager, $language_manager);
public function __construct(EntityManagerInterface $entity_manager, MenuParentFormSelectorInterface $menu_parent_selector, LanguageManagerInterface $language_manager, PathValidatorInterface $path_validator, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
parent::__construct($entity_manager, $entity_type_bundle_info, $time);
$this->menuParentSelector = $menu_parent_selector;
$this->pathValidator = $path_validator;
}
@ -62,7 +68,9 @@ class MenuLinkContentForm extends ContentEntityForm {
$container->get('entity.manager'),
$container->get('menu.parent_form_selector'),
$container->get('language_manager'),
$container->get('path.validator')
$container->get('path.validator'),
$container->get('entity_type.bundle.info'),
$container->get('datetime.time')
);
}
@ -105,8 +113,8 @@ class MenuLinkContentForm extends ContentEntityForm {
$entity->parent->value = $parent;
$entity->menu_name->value = $menu_name;
$entity->enabled->value = (!$form_state->isValueEmpty(array('enabled', 'value')));
$entity->expanded->value = (!$form_state->isValueEmpty(array('expanded', 'value')));
$entity->enabled->value = (!$form_state->isValueEmpty(['enabled', 'value']));
$entity->expanded->value = (!$form_state->isValueEmpty(['expanded', 'value']));
return $entity;
}
@ -123,7 +131,7 @@ class MenuLinkContentForm extends ContentEntityForm {
drupal_set_message($this->t('The menu link has been saved.'));
$form_state->setRedirect(
'entity.menu_link_content.canonical',
array('menu_link_content' => $menu_link->id())
['menu_link_content' => $menu_link->id()]
);
}
else {

View file

@ -56,14 +56,15 @@ class MenuLinkContentAccessControlHandler extends EntityAccessControlHandler imp
case 'update':
if (!$account->hasPermission('administer menu')) {
return AccessResult::neutral()->cachePerPermissions();
return AccessResult::neutral("The 'administer menu' permission is required.")->cachePerPermissions();
}
else {
// If there is a URL, this is an external link so always accessible.
// Assume that access is allowed.
$access = AccessResult::allowed()->cachePerPermissions()->addCacheableDependency($entity);
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $entity */
// We allow access, but only if the link is accessible as well.
if (($url_object = $entity->getUrlObject()) && $url_object->isRouted()) {
// If the link is routed determine whether the user has access unless
// they have the 'link to any page' permission.
if (!$account->hasPermission('link to any page') && ($url_object = $entity->getUrlObject()) && $url_object->isRouted()) {
$link_access = $this->accessManager->checkNamedRoute($url_object->getRouteName(), $url_object->getRouteParameters(), $account, TRUE);
$access = $access->andIf($link_access);
}

View file

@ -4,7 +4,6 @@ namespace Drupal\menu_link_content\Plugin\Deriver;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -17,13 +16,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class MenuLinkContentDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* The query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/**
* The entity manager.
*
@ -41,15 +33,12 @@ class MenuLinkContentDeriver extends DeriverBase implements ContainerDeriverInte
/**
* Constructs a MenuLinkContentDeriver instance.
*
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The query factory.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager
* The menu link manager.
*/
public function __construct(QueryFactory $query_factory, EntityManagerInterface $entity_manager, MenuLinkManagerInterface $menu_link_manager) {
$this->queryFactory = $query_factory;
public function __construct(EntityManagerInterface $entity_manager, MenuLinkManagerInterface $menu_link_manager) {
$this->entityManager = $entity_manager;
$this->menuLinkManager = $menu_link_manager;
}
@ -59,7 +48,6 @@ class MenuLinkContentDeriver extends DeriverBase implements ContainerDeriverInte
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$container->get('entity.query'),
$container->get('entity.manager'),
$container->get('plugin.manager.menu.link')
);
@ -70,7 +58,7 @@ class MenuLinkContentDeriver extends DeriverBase implements ContainerDeriverInte
*/
public function getDerivativeDefinitions($base_plugin_definition) {
// Get all custom menu links which should be rediscovered.
$entity_ids = $this->queryFactory->get('menu_link_content')
$entity_ids = $this->entityManager->getStorage('menu_link_content')->getQuery()
->condition('rediscover', TRUE)
->execute();
$plugin_definitions = [];

View file

@ -21,12 +21,12 @@ class MenuLinkContent extends MenuLinkBase implements ContainerFactoryPluginInte
*
* @var array
*/
protected static $entityIdsToLoad = array();
protected static $entityIdsToLoad = [];
/**
* {@inheritdoc}
*/
protected $overrideAllowed = array(
protected $overrideAllowed = [
'menu_name' => 1,
'parent' => 1,
'weight' => 1,
@ -38,7 +38,7 @@ class MenuLinkContent extends MenuLinkBase implements ContainerFactoryPluginInte
'route_parameters' => 1,
'url' => 1,
'options' => 1,
);
];
/**
* The menu link content entity connected to this plugin instance.
@ -123,12 +123,12 @@ class MenuLinkContent extends MenuLinkBase implements ContainerFactoryPluginInte
static::$entityIdsToLoad[$entity_id] = $entity_id;
$entities = $storage->loadMultiple(array_values(static::$entityIdsToLoad));
$entity = isset($entities[$entity_id]) ? $entities[$entity_id] : NULL;
static::$entityIdsToLoad = array();
static::$entityIdsToLoad = [];
}
if (!$entity) {
// Fallback to the loading by the UUID.
$uuid = $this->getUuid();
$loaded_entities = $storage->loadByProperties(array('uuid' => $uuid));
$loaded_entities = $storage->loadByProperties(['uuid' => $uuid]);
$entity = reset($loaded_entities);
}
if (!$entity) {

View file

@ -39,7 +39,7 @@ class MenuLink extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
return array(
return [
'menu_name' => t("The menu name. All links with the same menu name (such as 'navigation') are part of the same menu."),
'mlid' => t('The menu link ID (mlid) is the integer primary key.'),
'plid' => t('The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.'),
@ -65,7 +65,7 @@ class MenuLink extends DrupalSqlBase {
'p8' => t('The eighth mlid in the materialized path. See p1.'),
'p9' => t('The ninth mlid in the materialized path. See p1.'),
'updated' => t('Flag that indicates that this link was generated during the update from Drupal 5.'),
);
];
}
/**

View file

@ -2,6 +2,7 @@
namespace Drupal\menu_link_content\Tests;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\simpletest\WebTestBase;
/**
@ -16,17 +17,57 @@ class MenuLinkContentFormTest extends WebTestBase {
*
* @var array
*/
public static $modules = array(
public static $modules = [
'menu_link_content',
);
];
/**
* User with 'administer menu' and 'link to any page' permission.
*
* @var \Drupal\user\Entity\User
*/
protected $adminUser;
/**
* User with only 'administer menu' permission.
*
* @var \Drupal\user\Entity\User
*/
protected $basicUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array('administer menu'));
$this->drupalLogin($web_user);
$this->adminUser = $this->drupalCreateUser(['administer menu', 'link to any page']);
$this->basicUser = $this->drupalCreateUser(['administer menu']);
$this->drupalLogin($this->adminUser);
}
/**
* Tests the 'link to any page' permission for a restricted page.
*/
public function testMenuLinkContentFormLinkToAnyPage() {
$menu_link = MenuLinkContent::create([
'title' => 'Menu link test',
'provider' => 'menu_link_content',
'menu_name' => 'admin',
'link' => ['uri' => 'internal:/user/login'],
]);
$menu_link->save();
// The user should be able to edit a menu link to the page, even though
// the user cannot access the page itself.
$this->drupalGet('/admin/structure/menu/item/' . $menu_link->id() . '/edit');
$this->assertResponse(200);
$this->drupalLogin($this->basicUser);
$this->drupalGet('/admin/structure/menu/item/' . $menu_link->id() . '/edit');
$this->assertResponse(403);
}
/**
@ -34,16 +75,16 @@ class MenuLinkContentFormTest extends WebTestBase {
*/
public function testMenuLinkContentForm() {
$this->drupalGet('admin/structure/menu/manage/admin/add');
$element = $this->xpath('//select[@id = :id]/option[@selected]', array(':id' => 'edit-menu-parent'));
$element = $this->xpath('//select[@id = :id]/option[@selected]', [':id' => 'edit-menu-parent']);
$this->assertTrue($element, 'A default menu parent was found.');
$this->assertEqual('admin:', $element[0]['value'], '<Administration> menu is the parent.');
$this->drupalPostForm(
NULL,
array(
[
'title[0][value]' => t('Front page'),
'link[0][uri]' => '<front>',
),
],
t('Save')
);
$this->assertText(t('The menu link has been saved.'));
@ -56,10 +97,10 @@ class MenuLinkContentFormTest extends WebTestBase {
$this->drupalGet('admin/structure/menu/manage/admin/add');
$this->drupalPostForm(
NULL,
array(
[
'title[0][value]' => t('Test page'),
'link[0][uri]' => '<test>',
),
],
t('Save')
);
$this->assertText(t('Manually entered paths should start with /, ? or #.'));

View file

@ -22,12 +22,12 @@ class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase {
*
* @var array
*/
public static $modules = array(
public static $modules = [
'language',
'content_translation',
'menu_link_content',
'menu_ui',
);
];
/**
* {@inheritdoc}
@ -42,14 +42,14 @@ class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase {
* {@inheritdoc}
*/
protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), array('administer menu'));
return array_merge(parent::getTranslatorPermissions(), ['administer menu']);
}
/**
* {@inheritdoc}
*/
protected function getAdministratorPermissions() {
return array_merge(parent::getAdministratorPermissions(), array('administer themes', 'view the administration theme'));
return array_merge(parent::getAdministratorPermissions(), ['administer themes', 'view the administration theme']);
}
/**
@ -79,13 +79,13 @@ class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase {
/**
* Tests that translation page inherits admin status of edit page.
*/
function testTranslationLinkTheme() {
public function testTranslationLinkTheme() {
$this->drupalLogin($this->administrator);
$entityId = $this->createEntity(array(), 'en');
$entityId = $this->createEntity([], 'en');
// Set up Seven as the admin theme to test.
$this->container->get('theme_handler')->install(array('seven'));
$edit = array();
$this->container->get('theme_handler')->install(['seven']);
$edit = [];
$edit['admin_theme'] = 'seven';
$this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
$this->drupalGet('admin/structure/menu/item/' . $entityId . '/edit');
@ -107,14 +107,14 @@ class MenuLinkContentTranslationUITest 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);
}
}

View file

@ -1,10 +1,10 @@
<?php
namespace Drupal\menu_link_content\Tests;
namespace Drupal\Tests\menu_link_content\Functional;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\system\Entity\Menu;
/**
@ -12,14 +12,14 @@ use Drupal\system\Entity\Menu;
*
* @group Menu
*/
class LinksTest extends WebTestBase {
class LinksTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('router_test', 'menu_link_content');
public static $modules = ['router_test', 'menu_link_content'];
/**
* The menu link plugin manager.
@ -36,17 +36,17 @@ class LinksTest extends WebTestBase {
$this->menuLinkManager = \Drupal::service('plugin.manager.menu.link');
Menu::create(array(
Menu::create([
'id' => 'menu_test',
'label' => 'Test menu',
'description' => 'Description text',
))->save();
])->save();
}
/**
* Create a simple hierarchy of links.
*/
function createLinkHierarchy($module = 'menu_test') {
public function createLinkHierarchy($module = 'menu_test') {
// First remove all the menu links in the menu.
$this->menuLinkManager->deleteLinksInMenu('menu_test');
@ -56,47 +56,47 @@ class LinksTest extends WebTestBase {
// - child-1-1
// - child-1-2
// - child-2
$base_options = array(
$base_options = [
'title' => 'Menu link test',
'provider' => $module,
'menu_name' => 'menu_test',
);
];
$parent = $base_options + array(
$parent = $base_options + [
'link' => ['uri' => 'internal:/menu-test/hierarchy/parent'],
);
];
$link = MenuLinkContent::create($parent);
$link->save();
$links['parent'] = $link->getPluginId();
$child_1 = $base_options + array(
$child_1 = $base_options + [
'link' => ['uri' => 'internal:/menu-test/hierarchy/parent/child'],
'parent' => $links['parent'],
);
];
$link = MenuLinkContent::create($child_1);
$link->save();
$links['child-1'] = $link->getPluginId();
$child_1_1 = $base_options + array(
$child_1_1 = $base_options + [
'link' => ['uri' => 'internal:/menu-test/hierarchy/parent/child2/child'],
'parent' => $links['child-1'],
);
];
$link = MenuLinkContent::create($child_1_1);
$link->save();
$links['child-1-1'] = $link->getPluginId();
$child_1_2 = $base_options + array(
$child_1_2 = $base_options + [
'link' => ['uri' => 'internal:/menu-test/hierarchy/parent/child2/child'],
'parent' => $links['child-1'],
);
];
$link = MenuLinkContent::create($child_1_2);
$link->save();
$links['child-1-2'] = $link->getPluginId();
$child_2 = $base_options + array(
$child_2 = $base_options + [
'link' => ['uri' => 'internal:/menu-test/hierarchy/parent/child'],
'parent' => $links['parent'],
);
];
$link = MenuLinkContent::create($child_2);
$link->save();
$links['child-2'] = $link->getPluginId();
@ -107,13 +107,13 @@ class LinksTest extends WebTestBase {
/**
* Assert that at set of links is properly parented.
*/
function assertMenuLinkParents($links, $expected_hierarchy) {
public function assertMenuLinkParents($links, $expected_hierarchy) {
foreach ($expected_hierarchy as $id => $parent) {
/* @var \Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin */
$menu_link_plugin = $this->menuLinkManager->createInstance($links[$id]);
$expected_parent = isset($links[$parent]) ? $links[$parent] : '';
$this->assertEqual($menu_link_plugin->getParent(), $expected_parent, SafeMarkup::format('Menu link %id has parent of %parent, expected %expected_parent.', array('%id' => $id, '%parent' => $menu_link_plugin->getParent(), '%expected_parent' => $expected_parent)));
$this->assertEqual($menu_link_plugin->getParent(), $expected_parent, SafeMarkup::format('Menu link %id has parent of %parent, expected %expected_parent.', ['%id' => $id, '%parent' => $menu_link_plugin->getParent(), '%expected_parent' => $expected_parent]));
}
}
@ -121,18 +121,18 @@ class LinksTest extends WebTestBase {
* Assert that a link entity's created timestamp is set.
*/
public function testCreateLink() {
$options = array(
$options = [
'menu_name' => 'menu_test',
'bundle' => 'menu_link_content',
'link' => [['uri' => 'internal:/']],
);
];
$link = MenuLinkContent::create($options);
$link->save();
// Make sure the changed timestamp is set.
$this->assertEqual($link->getChangedTime(), REQUEST_TIME, 'Creating a menu link sets the "changed" timestamp.');
$options = array(
$options = [
'title' => 'Test Link',
);
];
$link->link->options = $options;
$link->changed->value = 0;
$link->save();
@ -143,36 +143,36 @@ class LinksTest extends WebTestBase {
/**
* Test automatic reparenting of menu links.
*/
function testMenuLinkReparenting($module = 'menu_test') {
public function testMenuLinkReparenting($module = 'menu_test') {
// Check the initial hierarchy.
$links = $this->createLinkHierarchy($module);
$expected_hierarchy = array(
$expected_hierarchy = [
'parent' => '',
'child-1' => 'parent',
'child-1-1' => 'child-1',
'child-1-2' => 'child-1',
'child-2' => 'parent',
);
];
$this->assertMenuLinkParents($links, $expected_hierarchy);
// Start over, and move child-1 under child-2, and check that all the
// children of child-1 have been moved too.
$links = $this->createLinkHierarchy($module);
/* @var \Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin */
$this->menuLinkManager->updateDefinition($links['child-1'], array('parent' => $links['child-2']));
$this->menuLinkManager->updateDefinition($links['child-1'], ['parent' => $links['child-2']]);
// Verify that the entity was updated too.
$menu_link_plugin = $this->menuLinkManager->createInstance($links['child-1']);
$entity = \Drupal::entityManager()->loadEntityByUuid('menu_link_content', $menu_link_plugin->getDerivativeId());
$this->assertEqual($entity->getParentId(), $links['child-2']);
$expected_hierarchy = array(
$expected_hierarchy = [
'parent' => '',
'child-1' => 'child-2',
'child-1-1' => 'child-1',
'child-1-2' => 'child-1',
'child-2' => 'parent',
);
];
$this->assertMenuLinkParents($links, $expected_hierarchy);
// Start over, and delete child-1, and check that the children of child-1
@ -180,12 +180,12 @@ class LinksTest extends WebTestBase {
$links = $this->createLinkHierarchy($module);
$this->menuLinkManager->removeDefinition($links['child-1']);
$expected_hierarchy = array(
$expected_hierarchy = [
'parent' => FALSE,
'child-1-1' => 'parent',
'child-1-2' => 'parent',
'child-2' => 'parent',
);
];
$this->assertMenuLinkParents($links, $expected_hierarchy);
// Try changing the parent at the entity level.
@ -194,12 +194,12 @@ class LinksTest extends WebTestBase {
$entity->parent->value = '';
$entity->save();
$expected_hierarchy = array(
$expected_hierarchy = [
'parent' => '',
'child-1-1' => 'parent',
'child-1-2' => '',
'child-2' => 'parent',
);
];
$this->assertMenuLinkParents($links, $expected_hierarchy);
// @todo Figure out what makes sense to test in terms of automatic
@ -210,7 +210,7 @@ class LinksTest extends WebTestBase {
* Tests uninstalling a module providing default links.
*/
public function testModuleUninstalledMenuLinks() {
\Drupal::service('module_installer')->install(array('menu_test'));
\Drupal::service('module_installer')->install(['menu_test']);
\Drupal::service('router.builder')->rebuild();
\Drupal::service('plugin.manager.menu.link')->rebuild();
$menu_links = $this->menuLinkManager->loadLinksByRoute('menu_test.menu_test');
@ -219,7 +219,7 @@ class LinksTest extends WebTestBase {
$this->assertEqual($menu_link->getPluginId(), 'menu_test');
// Uninstall the module and ensure the menu link got removed.
\Drupal::service('module_installer')->uninstall(array('menu_test'));
\Drupal::service('module_installer')->uninstall(['menu_test']);
\Drupal::service('plugin.manager.menu.link')->rebuild();
$menu_links = $this->menuLinkManager->loadLinksByRoute('menu_test.menu_test');
$this->assertEqual(count($menu_links), 0);

View file

@ -15,7 +15,7 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('menu_ui', 'menu_link_content');
public static $modules = ['menu_ui', 'menu_link_content'];
/**
* {@inheritdoc}

View file

@ -19,7 +19,7 @@ class MigrateMenuLinkTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('link', 'menu_ui', 'menu_link_content', 'node');
public static $modules = ['link', 'menu_ui', 'menu_link_content', 'node'];
/**
* {@inheritdoc}

View file

@ -35,7 +35,7 @@ class MenuLinkTest extends MigrateSqlSourceTestBase {
'link_path' => 'admin/config/system/cron',
'router_path' => 'admin/config/system/cron',
'link_title' => 'Cron',
'options' => array(),
'options' => [],
'module' => 'system',
'hidden' => 0,
'external' => 0,
@ -64,7 +64,7 @@ class MenuLinkTest extends MigrateSqlSourceTestBase {
'link_path' => 'node/141',
'router_path' => 'node/%',
'link_title' => 'Node 141',
'options' => array(),
'options' => [],
'module' => 'menu',
'hidden' => 0,
'external' => 0,
@ -93,7 +93,7 @@ class MenuLinkTest extends MigrateSqlSourceTestBase {
'link_path' => 'node/142',
'router_path' => 'node/%',
'link_title' => 'Node 142',
'options' => array(),
'options' => [],
'module' => 'menu',
'hidden' => 0,
'external' => 0,
@ -121,7 +121,7 @@ class MenuLinkTest extends MigrateSqlSourceTestBase {
'link_path' => 'admin',
'router_path' => 'admin',
'link_title' => 'Test 1',
'options' => array('attributes' => array('title' => 'Test menu link 1')),
'options' => ['attributes' => ['title' => 'Test menu link 1']],
'module' => 'menu',
'hidden' => 0,
'external' => 0,
@ -149,7 +149,7 @@ class MenuLinkTest extends MigrateSqlSourceTestBase {
'link_path' => 'admin/modules',
'router_path' => 'admin/modules',
'link_title' => 'Test 2',
'options' => array('attributes' => array('title' => 'Test menu link 2')),
'options' => ['attributes' => ['title' => 'Test menu link 2']],
'module' => 'menu',
'hidden' => 0,
'external' => 0,
@ -177,7 +177,7 @@ class MenuLinkTest extends MigrateSqlSourceTestBase {
'link_path' => 'admin/build/menu-customize/navigation',
'router_path' => 'admin/build/menu-customize/%',
'link_title' => 'Navigation',
'options' => array(),
'options' => [],
'module' => 'menu',
'hidden' => 0,
'external' => 0,