diff --git a/bundle/Helper/PathHelper.php b/bundle/Helper/PathHelper.php index 7fe024d6..112883dd 100644 --- a/bundle/Helper/PathHelper.php +++ b/bundle/Helper/PathHelper.php @@ -5,6 +5,7 @@ use eZ\Publish\API\Repository\Exceptions\UnauthorizedException; use eZ\Publish\API\Repository\LocationService; use eZ\Publish\Core\Helper\TranslationHelper; +use eZ\Publish\Core\MVC\ConfigResolverInterface; use Symfony\Component\Routing\RouterInterface; class PathHelper @@ -20,42 +21,35 @@ class PathHelper protected $translationHelper; /** - * @var \Symfony\Component\Routing\RouterInterface + * @var \eZ\Publish\Core\MVC\ConfigResolverInterface */ - protected $router; + protected $configResolver; /** - * @var int|string + * @var \Symfony\Component\Routing\RouterInterface */ - protected $rootLocationId; + protected $router; /** * Constructor. * * @param \eZ\Publish\API\Repository\LocationService $locationService * @param \eZ\Publish\Core\Helper\TranslationHelper $translationHelper + * @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver * @param \Symfony\Component\Routing\RouterInterface $router */ public function __construct( LocationService $locationService, TranslationHelper $translationHelper, + ConfigResolverInterface $configResolver, RouterInterface $router ) { $this->locationService = $locationService; $this->translationHelper = $translationHelper; + $this->configResolver = $configResolver; $this->router = $router; } - /** - * Sets the root location ID. - * - * @param int|string $rootLocationId - */ - public function setRootLocationId($rootLocationId) - { - $this->rootLocationId = (int) $rootLocationId; - } - /** * Returns the path array for location ID. * @@ -75,8 +69,10 @@ public function getPath($locationId) array_shift($path); $rootLocationFound = false; + $rootLocationId = (int) $this->configResolver->getParameter('content.tree_root.location_id'); + foreach ($path as $index => $pathItem) { - if ((int) $pathItem === $this->rootLocationId) { + if ((int) $pathItem === $rootLocationId) { $rootLocationFound = true; } diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index f364dd5c..1cb11ee6 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -43,6 +43,5 @@ services: arguments: - "@ezpublish.api.service.location" - "@ezpublish.translation_helper" + - "@ezpublish.config.resolver" - "@router" - calls: - - [setRootLocationId, ["$content.tree_root.location_id$"]] diff --git a/tests/Helper/PathHelperTest.php b/tests/Helper/PathHelperTest.php index 81452be5..1fab0e29 100644 --- a/tests/Helper/PathHelperTest.php +++ b/tests/Helper/PathHelperTest.php @@ -6,6 +6,7 @@ use eZ\Publish\Core\Base\Exceptions\UnauthorizedException; use eZ\Publish\Core\Repository\Values\Content\Location; use Netgen\Bundle\AdminUIBundle\Helper\PathHelper; +use Netgen\Bundle\AdminUIBundle\Tests\Stubs\ConfigResolverStub; use PHPUnit\Framework\TestCase; class PathHelperTest extends TestCase @@ -56,8 +57,20 @@ public function setUp() )), )); - $this->helper = new PathHelper($this->locationService, $this->translationHelper, $this->router); - $this->helper->setRootLocationId($this->rootLocation->id); + $this->helper = new PathHelper( + $this->locationService, + $this->translationHelper, + new ConfigResolverStub( + array( + 'ezsettings' => array( + 'content.tree_root.location_id' => array( + 'default' => $this->rootLocation->id, + ), + ), + ) + ), + $this->router + ); } public function testGetPath() diff --git a/tests/Stubs/ConfigResolverStub.php b/tests/Stubs/ConfigResolverStub.php new file mode 100644 index 00000000..3ffe1f81 --- /dev/null +++ b/tests/Stubs/ConfigResolverStub.php @@ -0,0 +1,43 @@ +parameters = $parameters; + } + + public function getParameter($paramName, $namespace = null, $scope = null) + { + return $this->parameters[$namespace ?: $this->defaultNamespace][$paramName]; + } + + public function hasParameter($paramName, $namespace = null, $scope = null) + { + return isset($this->parameters[$namespace ?: $this->defaultNamespace][$paramName]); + } + + public function setDefaultNamespace($defaultNamespace) + { + $this->defaultNamespace = $defaultNamespace; + } + + public function getDefaultNamespace() + { + return $this->defaultNamespace; + } +}