diff --git a/core/core.services.yml b/core/core.services.yml index 9137380..9291712 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -353,7 +353,7 @@ services: arguments: ['@menu.tree_storage', '@plugin.manager.menu.link', '@router.route_provider', '@menu.active_trail', '@controller_resolver', '@cache.menu', '@current_route_match'] menu.default_tree_manipulators: class: Drupal\Core\Menu\DefaultMenuLinkTreeManipulators - arguments: ['@access_manager', '@current_user', '@entity.query', '@entity.manager'] + arguments: ['@access_manager', '@current_user', '@entity.query'] menu.active_trail: class: Drupal\Core\Menu\MenuActiveTrail arguments: ['@plugin.manager.menu.link', '@current_route_match'] diff --git a/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php b/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php index 7a5f75a..29fa9bc 100644 --- a/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php +++ b/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Menu; use Drupal\Core\Access\AccessManagerInterface; -use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Session\AccountInterface; @@ -46,13 +45,6 @@ class DefaultMenuLinkTreeManipulators { protected $queryFactory; /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityManagerInterface - */ - protected $entityManager; - - /** * Constructs a \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators object. * * @param \Drupal\Core\Access\AccessManagerInterface $access_manager @@ -61,14 +53,11 @@ class DefaultMenuLinkTreeManipulators { * The current user. * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory * The entity query factory. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. */ - public function __construct(AccessManagerInterface $access_manager, AccountInterface $account, QueryFactory $query_factory, EntityManagerInterface $entity_manager) { + public function __construct(AccessManagerInterface $access_manager, AccountInterface $account, QueryFactory $query_factory) { $this->accessManager = $access_manager; $this->account = $account; $this->queryFactory = $query_factory; - $this->entityManager = $entity_manager; } /** @@ -150,54 +139,6 @@ public function checkNodeAccess(array $tree) { } /** - * Load all entities which are part of the menu tree using loadMultiple(). - * - * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree - * The menu link tree. - * - * @return \Drupal\Core\Menu\MenuLinkTreeElement[] $tree - * The unmanipulated menu link tree. - */ - public function loadEntities(array $tree) { - $entity_ids = []; - $this->collectEntityIds($tree, $entity_ids); - - foreach ($entity_ids as $entity_type => $ids) { - $this->entityManager->getStorage($entity_type)->loadMultiple(array_unique($ids)); - } - - return $tree; - } - - /** - * Collect all entity IDs of all referenced entities. - * - * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree - * The menu link tree to manipulate. - * @param array $entity_ids - * The entity IDs keyed by entity type. - */ - protected function collectEntityIds(array &$tree, array &$entity_ids) { - foreach ($tree as $key => &$element) { - if (isset($element->access)) { - continue; - } - $route_name = $element->link->getRouteName(); - // Find a better way to extract the entity type. - if (strpos($route_name, 'entity.') === 0 && strpos($route_name, '.canonical') !== FALSE) { - $entity_type = substr($route_name, 7, -10); - $parameters = $element->link->getRouteParameters(); - if (isset($parameters[$entity_type])) { - $entity_ids[$entity_type][] = $parameters[$entity_type]; - } - } - if ($element->hasChildren) { - $this->collectNodeLinks($element->subtree, $entity_ids); - } - } - } - - /** * Collects the node links in the menu tree. * * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree diff --git a/core/lib/Drupal/Core/Menu/MenuParentFormSelector.php b/core/lib/Drupal/Core/Menu/MenuParentFormSelector.php index 1aa812f..e5a1264 100644 --- a/core/lib/Drupal/Core/Menu/MenuParentFormSelector.php +++ b/core/lib/Drupal/Core/Menu/MenuParentFormSelector.php @@ -68,7 +68,6 @@ public function getParentSelectOptions($id = '', array $menus = NULL) { $tree = $this->menuLinkTree->load($menu_name, $parameters); $manipulators = array( array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'), - array('callable' => 'menu.default_tree_manipulators:loadEntities'), array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), ); diff --git a/core/modules/menu_link/src/Plugin/Field/FieldWidget/MenuLinkWidget.php b/core/modules/menu_link/src/Plugin/Field/FieldWidget/MenuLinkWidget.php index 1c0510a..59ac4f6 100644 --- a/core/modules/menu_link/src/Plugin/Field/FieldWidget/MenuLinkWidget.php +++ b/core/modules/menu_link/src/Plugin/Field/FieldWidget/MenuLinkWidget.php @@ -72,7 +72,6 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { - $default_weight = isset($items[$delta]->weight) ? $items[$delta]->weight : 0; $available_menus = array_filter($items->getSetting('available_menus')); @@ -83,7 +82,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $default_menu_parent = "$menu:$parent"; if (!$this->account->hasPermission('administer menu')) { - $element['weight'] = [ '#type' => 'value', '#value' => $default_weight, diff --git a/core/modules/menu_link/src/Plugin/Menu/MenuLinkField.php b/core/modules/menu_link/src/Plugin/Menu/MenuLinkField.php index 05da9a6..f90ebc5 100644 --- a/core/modules/menu_link/src/Plugin/Menu/MenuLinkField.php +++ b/core/modules/menu_link/src/Plugin/Menu/MenuLinkField.php @@ -19,15 +19,6 @@ class MenuLinkField extends MenuLinkBase implements ContainerFactoryPluginInterface { /** - * Entities IDs to load. - * - * It is an array of entity IDs keyed by entity IDs. - * - * @var array - */ - protected static $entityIdsToLoad = array(); - - /** * The entity connected to this plugin instance. * * @var \Drupal\Core\Entity\EntityInterface @@ -67,12 +58,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->entityManager = $entity_manager; $this->languageManager = $language_manager; - - $entity_type_id = $this->pluginDefinition['metadata']['entity_type_id']; - $entity_id = $this->pluginDefinition['metadata']['entity_id']; - // Builds a list of entity IDs to take advantage of the more efficient - // EntityStorageInterface::loadMultiple() in getEntity() at render time. - static::$entityIdsToLoad[$entity_type_id][$entity_id] = $entity_id; } /** diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php index 1909664..7b540af 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -225,7 +225,6 @@ protected function buildOverviewForm(array &$form, FormStateInterface $form_stat $this->getRequest()->attributes->set('_menu_admin', TRUE); $manipulators = array( array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'), - array('callable' => 'menu.default_tree_manipulators:loadEntities'), array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), ); diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php index 073e872..9e976c5 100644 --- a/core/modules/system/src/Controller/SystemController.php +++ b/core/modules/system/src/Controller/SystemController.php @@ -125,7 +125,6 @@ public function overview($link_id) { $tree = $this->menuLinkTree->load(NULL, $parameters); $manipulators = array( array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'), - array('callable' => 'menu.default_tree_manipulators:loadEntities'), array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), ); diff --git a/core/modules/system/src/Plugin/Block/SystemMenuBlock.php b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php index 17d3c29..93d1dfa 100644 --- a/core/modules/system/src/Plugin/Block/SystemMenuBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemMenuBlock.php @@ -147,7 +147,6 @@ public function build() { $tree = $this->menuTree->load($menu_name, $parameters); $manipulators = array( array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'), - array('callable' => 'menu.default_tree_manipulators:loadEntities'), array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), ); diff --git a/core/modules/system/src/SystemManager.php b/core/modules/system/src/SystemManager.php index ab3e929..d5fae71 100644 --- a/core/modules/system/src/SystemManager.php +++ b/core/modules/system/src/SystemManager.php @@ -196,7 +196,6 @@ public function getAdminBlock(MenuLinkInterface $instance) { $tree = $this->menuTree->load(NULL, $parameters); $manipulators = array( array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'), - array('callable' => 'menu.default_tree_manipulators:loadEntities'), array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), ); diff --git a/core/modules/system/src/Tests/System/AdminTest.php b/core/modules/system/src/Tests/System/AdminTest.php index 8dc9aa0..83048a0 100644 --- a/core/modules/system/src/Tests/System/AdminTest.php +++ b/core/modules/system/src/Tests/System/AdminTest.php @@ -132,7 +132,6 @@ protected function getTopLevelMenuLinks() { $tree = $menu_tree->load(NULL, $parameters); $manipulators = array( array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'), - array('callable' => 'menu.default_tree_manipulators:loadEntities'), array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:flatten'), ); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 3f8a56d..001f96f 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1125,7 +1125,6 @@ function system_get_module_admin_tasks($module, array $info) { $tree = $menu_tree->load('system.admin', $parameters); $manipulators = array( array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'), - array('callable' => 'menu.default_tree_manipulators:loadEntities'), array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), array('callable' => 'menu.default_tree_manipulators:flatten'), diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 9087753..0e7a35b 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -211,7 +211,6 @@ function toolbar_prerender_toolbar_administration_tray(array $element) { $tree = $menu_tree->load(NULL, $parameters); $manipulators = array( array('callable' => 'menu.default_tree_manipulators:checkNodeAccess'), - array('callable' => 'menu.default_tree_manipulators:loadEntities'), array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), array('callable' => 'toolbar_menu_navigation_links'), diff --git a/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php b/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php index 6ca00b4..cd1a392 100644 --- a/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/DefaultMenuLinkTreeManipulatorsTest.php @@ -42,13 +42,6 @@ class DefaultMenuLinkTreeManipulatorsTest extends UnitTestCase { protected $queryFactory; /** - * The mocked entity manager. - * - * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $entityManager; - - /** * The default menu link tree manipulators. * * @var \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators @@ -75,14 +68,13 @@ class DefaultMenuLinkTreeManipulatorsTest extends UnitTestCase { protected function setUp() { parent::setUp(); - $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface'); $this->accessManager = $this->getMock('\Drupal\Core\Access\AccessManagerInterface'); $this->currentUser = $this->getMock('Drupal\Core\Session\AccountInterface'); $this->queryFactory = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryFactory') ->disableOriginalConstructor() ->getMock(); - $this->defaultMenuTreeManipulators = new DefaultMenuLinkTreeManipulators($this->accessManager, $this->currentUser, $this->queryFactory, $this->entityManager); + $this->defaultMenuTreeManipulators = new DefaultMenuLinkTreeManipulators($this->accessManager, $this->currentUser, $this->queryFactory); } /**