diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index e4c5f6c..7e28c8d 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -251,19 +251,12 @@ public function getTasksBuild($current_route_name) { foreach ($tree as $level => $instances) { foreach ($instances as $child) { // In order to get the Drupal path the base URL has to be stripped off. - $route_information = $child->getRouteInformation(); - list($route_name, $route_parameters, $options) = $route_information; + list($route_name, $route_parameters) = $child->getRouteInformation(); $route_parameters = isset($route_parameters) ? (array) $route_parameters : array(); // @todo On the longrun we should be able to use #type link instead. // so there would be no need for the URL generator here. - $path = $this->urlGenerator->generateFromRoute($route_name, $route_parameters, $options); - // In order to get the Drupal path the base URL has to be stripped off. - $base_url = $this->urlGenerator->getContext()->getBaseUrl(); - if (!empty($base_url) && strpos($path, $base_url) === 0) { - $path = substr($path, strlen($base_url)); - } - $path = trim($path, '/'); + $path = $this->urlGenerator->getPathFromRoute($route_name, $route_parameters); // Find out whether the user has access to the task. $access = $this->accessManager->checkNamedRoute($route_name, $route_parameters); diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index 4b8c32f..78a666f 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -78,6 +78,13 @@ class LocalTaskManagerTest extends UnitTestCase { */ protected $urlGenerator; + /** + * The mocked access manager. + * + * @var \Drupal\Core\Access\AccessManager|\PHPUnit_Framework_MockObject_MockObject + */ + protected $accessManager; + public static function getInfo() { return array( 'name' => 'Local tasks manager.', @@ -99,6 +106,9 @@ protected function setUp() { $this->factory = $this->getMock('Drupal\Component\Plugin\Factory\FactoryInterface'); $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); + $this->accessManager = $this->getMockBuilder('Drupal\Core\Access\AccessManager') + ->disableOriginalConstructor() + ->getMock(); $this->setupLocalTaskManager(); } @@ -257,6 +267,10 @@ protected function setupLocalTaskManager() { $property->setAccessible(TRUE); $property->setValue($this->manager, $this->urlGenerator); + $property = new \ReflectionProperty('Drupal\Core\Menu\LocalTaskManager', 'accessManager'); + $property->setAccessible(TRUE); + $property->setValue($this->manager, $this->accessManager); + $property = new \ReflectionProperty('Drupal\Core\Menu\LocalTaskManager', 'discovery'); $property->setAccessible(TRUE); $property->setValue($this->manager, $this->pluginDiscovery);