diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index d989912..b9c89ca 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -53,12 +53,6 @@ class LocalTaskManager extends DefaultPluginManager { */ protected $routeProvider; - /** - * Stores the langcode used for the cache key. - * - * @var string - */ - protected $cacheLangcodeSuffix; /** * Constructs a \Drupal\Core\Menu\LocalTaskManager object. @@ -73,10 +67,11 @@ class LocalTaskManager extends DefaultPluginManager { * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider * The route provider to load routes by name. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler.u + * The module handler. * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend. * @param \Drupal\Core\Language\LanguageManager $language_manager + * The language manager. */ public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager) { parent::__construct('Menu\LocalTask', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalTask'); @@ -84,8 +79,6 @@ public function __construct(\Traversable $namespaces, ControllerResolverInterfac $this->request = $request; $this->routeProvider = $route_provider; $this->alterInfo($module_handler, 'local_tasks'); - - $this->cacheLangcodeSuffix = $language_manager->getLanguage(Language::TYPE_INTERFACE)->id; $this->setCacheBackend($cache, $language_manager, 'local_task'); } @@ -135,11 +128,10 @@ public function getLocalTasksForRoute($route_name) { if (!isset($this->instances[$route_name])) { $this->instances[$route_name] = array(); - if ($cache = $this->cacheBackend->get('local_task:' . $route_name . ':' . $this->cacheLangcodeSuffix)) { + if ($cache = $this->cacheBackend->get($this->cacheKey . ':' . $route_name)) { $this->instances[$route_name] = $cache->data; } else { - // @todo - optimize this lookup by compiling or caching. $definitions = $this->getDefinitions(); // We build the hierarchy by finding all tabs that should // appear on the current route. @@ -171,7 +163,7 @@ public function getLocalTasksForRoute($route_name) { } foreach (array_keys($tab_root_ids) as $root_id) { // Convert the tree keyed by plugin IDs into a simple one with - // integer depth. Create instances for each plugin along the way. + // integer depth. Create instances for each plugin along the way. $level = 0; // We used this above as the top-level parent array key. $next_parent = '> ' . $root_id; @@ -198,7 +190,7 @@ public function getLocalTasksForRoute($route_name) { } } - $this->cacheBackend->set('local_task:' . $route_name . ':' . $this->cacheLangcodeSuffix, $this->instances[$route_name], CacheBackendInterface::CACHE_PERMANENT, array('local_task')); + $this->cacheBackend->set($this->cacheKey . ':' . $route_name, $this->instances[$route_name], CacheBackendInterface::CACHE_PERMANENT, array('local_task')); } } return $this->instances[$route_name]; diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index 28a927a..ade40cf 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -90,9 +90,7 @@ protected function setUp() { $this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface'); $this->pluginDiscovery = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface'); $this->factory = $this->getMock('Drupal\Component\Plugin\Factory\FactoryInterface'); - - $this->cacheBackend = $this->getMockBuilder('Drupal\Core\Cache\CacheBackendInterface') - ->getMock(); + $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->setupLocalTaskManager(); } @@ -105,7 +103,7 @@ protected function setUp() { public function testGetLocalTasksForRouteSingleLevelTitle() { $definitions = $this->getLocalTaskFixtures(); - $this->pluginDiscovery->expects($this->any()) + $this->pluginDiscovery->expects($this->once()) ->method('getDefinitions') ->will($this->returnValue($definitions)); @@ -164,7 +162,7 @@ public function testGetLocalTaskForRouteWithEmptyCache() { $this->cacheBackend->expects($this->at(0)) ->method('get') - ->with('local_task:menu_local_task_test_tasks_view:en'); + ->with('local_task:en:menu_local_task_test_tasks_view'); $this->cacheBackend->expects($this->at(1)) ->method('get') @@ -176,7 +174,7 @@ public function testGetLocalTaskForRouteWithEmptyCache() { $this->cacheBackend->expects($this->at(3)) ->method('set') - ->with('local_task:menu_local_task_test_tasks_view:en', $result, CacheBackendInterface::CACHE_PERMANENT, array('local_task')); + ->with('local_task:en:menu_local_task_test_tasks_view', $result, CacheBackendInterface::CACHE_PERMANENT, array('local_task')); $local_tasks = $this->manager->getLocalTasksForRoute('menu_local_task_test_tasks_view'); $this->assertEquals($result, $local_tasks); @@ -213,7 +211,7 @@ public function testGetLocalTaskForRouteWithFilledCache() { $this->cacheBackend->expects($this->at(0)) ->method('get') - ->with('local_task:menu_local_task_test_tasks_view:en') + ->with('local_task:en:menu_local_task_test_tasks_view') ->will($this->returnValue((object) array('data' => $result))); $this->cacheBackend->expects($this->never()) @@ -292,10 +290,6 @@ protected function setupLocalTaskManager() { ->method('getLanguage') ->will($this->returnValue(new Language(array('id' => 'en')))); - $property = new \ReflectionProperty($this->manager, 'cacheLangcodeSuffix'); - $property->setAccessible(TRUE); - $property->setValue($this->manager, 'en'); - $this->manager->setCacheBackend($this->cacheBackend, $language_manager, 'local_task'); }