diff -u b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php --- b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php @@ -149,30 +149,30 @@ * {@inheritdoc} */ public function getCacheTags() { - if (!isset($this->pluginDefinition['cacheability_metadata'])) { + if (!isset($this->pluginDefinition['cache_tags'])) { return []; } - return $this->pluginDefinition['cacheability_metadata']->getCacheTags(); + return $this->pluginDefinition['cache_tags']; } /** * {@inheritdoc} */ public function getCacheContexts() { - if (!isset($this->pluginDefinition['cacheability_metadata'])) { + if (!isset($this->pluginDefinition['cache_contexts'])) { return []; } - return $this->pluginDefinition['cacheability_metadata']->getCacheContexts(); + return $this->pluginDefinition['cache_contexts']; } /** * {@inheritdoc} */ public function getCacheMaxAge() { - if (!isset($this->pluginDefinition['cacheability_metadata'])) { + if (!isset($this->pluginDefinition['cache_max_age'])) { return Cache::PERMANENT; } - return $this->pluginDefinition['cacheability_metadata']->getCacheMaxAge(); + return $this->pluginDefinition['cache_max_age']; } } diff -u b/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php --- b/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -290,7 +290,7 @@ /** * {@inheritdoc} */ - public function getTasksBuild($current_route_name, RefinableCacheableDependencyInterface &$cacheable_metadata) { + public function getTasksBuild($current_route_name, RefinableCacheableDependencyInterface &$cacheability) { $tree = $this->getLocalTasksForRoute($current_route_name); $build = array(); @@ -313,7 +313,7 @@ // Given that the active flag depends on the route we have to add the // route cache context. - $cacheable_metadata->addCacheContexts(['route']); + $cacheability->addCacheContexts(['route']); $active = $this->isRouteActive($current_route_name, $route_name, $route_parameters); // The plugin may have been set active in getLocalTasksForRoute() if @@ -334,8 +334,8 @@ '#weight' => $child->getWeight(), '#access' => $access, ]; - $cacheable_metadata->addCacheableDependency($access); - $cacheable_metadata->addCacheableDependency($child); + $cacheability->addCacheableDependency($access); + $cacheability->addCacheableDependency($child); } } @@ -347,25 +347,25 @@ */ public function getLocalTasks($route_name, $level = 0) { if (!isset($this->taskData[$route_name])) { - $cacheability_metadata = new CacheableMetadata(); - $cacheability_metadata->addCacheContexts(['route']); + $cacheability = new CacheableMetadata(); + $cacheability->addCacheContexts(['route']); // Look for route-based tabs. $this->taskData[$route_name] = [ 'tabs' => [], - 'cacheable_metadata' => $cacheability_metadata, + 'cacheability' => $cacheability, ]; if (!$this->requestStack->getCurrentRequest()->attributes->has('exception')) { // Safe to build tasks only when no exceptions raised. $data = []; - $local_tasks = $this->getTasksBuild($route_name, $cacheability_metadata); + $local_tasks = $this->getTasksBuild($route_name, $cacheability); foreach ($local_tasks as $tab_level => $items) { $data[$tab_level] = empty($data[$tab_level]) ? $items : array_merge($data[$tab_level], $items); } $this->taskData[$route_name]['tabs'] = $data; // Allow modules to alter local tasks. - $this->moduleHandler->alter('menu_local_tasks', $this->taskData[$route_name], $route_name, $cacheability_metadata); - $this->taskData[$route_name]['cacheable_metadata'] = $cacheability_metadata; + $this->moduleHandler->alter('menu_local_tasks', $this->taskData[$route_name], $route_name, $cacheability); + $this->taskData[$route_name]['cacheability'] = $cacheability; } } @@ -373,14 +373,14 @@ return [ 'tabs' => $this->taskData[$route_name]['tabs'][$level], 'route_name' => $route_name, - 'cacheable_metadata' => $this->taskData[$route_name]['cacheable_metadata'], + 'cacheability' => $this->taskData[$route_name]['cacheability'], ]; } return [ 'tabs' => [], 'route_name' => $route_name, - 'cacheable_metadata' => $this->taskData[$route_name]['cacheable_metadata'], + 'cacheability' => $this->taskData[$route_name]['cacheability'], ]; } diff -u b/core/lib/Drupal/Core/Menu/LocalTaskManagerInterface.php b/core/lib/Drupal/Core/Menu/LocalTaskManagerInterface.php --- b/core/lib/Drupal/Core/Menu/LocalTaskManagerInterface.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManagerInterface.php @@ -48,11 +48,13 @@ * * @param string $current_route_name * The route for which to make renderable local tasks. + * @param \Drupal\Core\Cache\RefinableCacheableDependencyInterface $cacheability + * The cacheability metadata for the local tasks. * * @return array * A render array as expected by menu-local-tasks.html.twig. */ - public function getTasksBuild($current_route_name, RefinableCacheableDependencyInterface &$cacheable_metadata); + public function getTasksBuild($current_route_name, RefinableCacheableDependencyInterface &$cacheability); /** * Collects the local tasks (tabs) for the current route. diff -u b/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php b/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php --- b/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php +++ b/core/lib/Drupal/Core/Menu/Plugin/Block/LocalTasksBlock.php @@ -89,7 +89,7 @@ */ public function build() { $config = $this->configuration; - $cacheable_metadata = new CacheableMetadata(); + $cacheability = new CacheableMetadata(); $tabs = [ '#theme' => 'menu_local_tasks', ]; @@ -97,7 +97,7 @@ // Add only selected levels for the printed output. if ($config['primary']) { $links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 0); - $cacheable_metadata = $cacheable_metadata->merge($links['cacheable_metadata']); + $cacheability = $cacheability->merge($links['cacheability']); // Do not display single tabs. $tabs += [ '#primary' => count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : [], @@ -105,7 +105,7 @@ } if ($config['secondary']) { $links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 1); - $cacheable_metadata = $cacheable_metadata->merge($links['cacheable_metadata']); + $cacheability = $cacheability->merge($links['cacheability']); // Do not display single tabs. $tabs += [ '#secondary' => count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : [], @@ -113,7 +113,7 @@ } $build = []; - $cacheable_metadata->applyTo($build); + $cacheability->applyTo($build); if (empty($tabs['#primary']) && empty($tabs['#secondary'])) { return $build; } diff -u b/core/modules/comment/src/Plugin/Menu/LocalTask/UnapprovedComments.php b/core/modules/comment/src/Plugin/Menu/LocalTask/UnapprovedComments.php --- b/core/modules/comment/src/Plugin/Menu/LocalTask/UnapprovedComments.php +++ b/core/modules/comment/src/Plugin/Menu/LocalTask/UnapprovedComments.php @@ -29,11 +29,6 @@ protected $commentStorage; /** - * The entity manager. - */ - protected $entityManager; - - /** * Construct the UnapprovedComments object. * * @param array $configuration @@ -44,13 +39,10 @@ * The plugin implementation definition. * @param \Drupal\comment\CommentStorageInterface $comment_storage * The comment storage service. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, CommentStorageInterface $comment_storage, EntityManagerInterface $entity_manager) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, CommentStorageInterface $comment_storage) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->commentStorage = $comment_storage; - $this->entityManager = $entity_manager; } /** @@ -61,8 +53,7 @@ $configuration, $plugin_id, $plugin_definition, - $container->get('entity.manager')->getStorage('comment'), - $container->get('entity.manager') + $container->get('entity.manager')->getStorage('comment') ); } @@ -75,9 +66,2 @@ - /** - * {@inheritdoc} - */ - public function getCacheTags() { - return Cache::mergeTags(parent::getCacheTags(), $this->entityManager->getDefinition('comment')->getListCacheTags()); - } - } diff -u b/core/modules/system/tests/modules/menu_test/menu_test.module b/core/modules/system/tests/modules/menu_test/menu_test.module --- b/core/modules/system/tests/modules/menu_test/menu_test.module +++ b/core/modules/system/tests/modules/menu_test/menu_test.module @@ -29,7 +29,7 @@ /** * Implements hook_menu_local_tasks_alter(). */ -function menu_test_menu_local_tasks_alter(&$data, $route_name, \Drupal\Core\Cache\CacheableMetadata &$cacheable_metadata) { +function menu_test_menu_local_tasks_alter(&$data, $route_name, \Drupal\Core\Cache\RefinableCacheableDependencyInterface &$cacheability) { if (in_array($route_name, array('menu_test.tasks_default'))) { $data['tabs'][0]['foo'] = array( '#theme' => 'menu_local_task', @@ -48,7 +48,7 @@ '#weight' => 20, ); } - $cacheable_metadata->addCacheTags(['kittens:dwarf-cat']); + $cacheability->addCacheTags(['kittens:dwarf-cat']); } /** diff -u b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php --- b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php @@ -308,11 +308,9 @@ * @covers ::getCacheMaxAge */ public function testCacheabilityMetadata() { - $cacheability = new CacheableMetadata(); - $cacheability->setCacheContexts(['route']); - $cacheability->setCacheTags(['kitten']); - $cacheability->setCacheMaxAge(3600); - $this->pluginDefinition['cacheability_metadata'] = $cacheability; + $this->pluginDefinition['cache_contexts'] = ['route']; + $this->pluginDefinition['cache_tags'] = ['kitten']; + $this->pluginDefinition['cache_max_age'] = 3600; $this->setupLocalTaskDefault(); diff -u b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php --- b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -418,8 +418,10 @@ ->will($this->returnValue($definitions)); // Setup some cacheablity metadata and ensure its merged together. - $definitions['menu_local_task_test_tasks_settings']['cacheability_metadata'] = (new CacheableMetadata())->setCacheTags(['tag.example1'])->setCacheContexts(['context.example1']); - $definitions['menu_local_task_test_tasks_edit']['cacheability_metadata'] = (new CacheableMetadata())->setCacheTags(['tag.example2'])->setCacheContexts(['context.example2']); + $definitions['menu_local_task_test_tasks_settings']['cache_tags'] = ['tag.example1']; + $definitions['menu_local_task_test_tasks_settings']['cache_contexts'] = ['context.example1']; + $definitions['menu_local_task_test_tasks_edit']['cache_tags'] = ['tag.example2']; + $definitions['menu_local_task_test_tasks_edit']['cache_contexts'] = ['context.example2']; // Test the cacheable metadata of access checking. $definitions['menu_local_task_test_tasks_view_child1']['access'] = AccessResult::allowed()->addCacheContexts(['user.permissions']); @@ -460,9 +462,9 @@ $mock->getOptions(Argument::cetera())->willReturn([]); $mock->getActive()->willReturn($plugin_id === $active_plugin_id); $mock->getWeight()->willReturn(isset($info['weight']) ? $info['weight'] : 0); - $mock->getCacheContexts()->willReturn(isset($info['cacheability_metadata']) ? $info['cacheability_metadata']->getCacheContexts() : []); - $mock->getCacheTags()->willReturn(isset($info['cacheability_metadata']) ? $info['cacheability_metadata']->getCacheTags() : []); - $mock->getCacheMaxAge()->willReturn(isset($info['cacheability_metadata']) ? $info['cacheability_metadata']->getCacheMaxAge() : Cache::PERMANENT); + $mock->getCacheContexts()->willReturn(isset($info['cache_contexts']) ? $info['cache_contexts'] : []); + $mock->getCacheTags()->willReturn(isset($info['cache_tags']) ? $info['cache_tags'] : []); + $mock->getCacheMaxAge()->willReturn(isset($info['cache_max_age']) ? $info['cache_max_age'] : Cache::PERMANENT); $access_manager_map[] = [$info['route_name'], [], $this->account, TRUE, $info['access']]; diff -u b/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php --- b/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -13,7 +13,6 @@ use Drupal\Core\Cache\CacheTagsInvalidatorInterface; use Drupal\Core\Cache\Context\CacheContextsManager; use Drupal\Core\DependencyInjection\ContainerBuilder; -use Prophecy\Argument; /** * Provides a base class and helpers for Drupal unit tests. only in patch2: unchanged: --- a/core/modules/comment/comment.links.task.yml +++ b/core/modules/comment/comment.links.task.yml @@ -29,6 +29,8 @@ comment.admin_approval: class: Drupal\comment\Plugin\Menu\LocalTask\UnapprovedComments parent_id: comment.admin weight: 1 + cache_tags: + - comment_list # Default tab for comment type editing. entity.comment_type.edit_form: