From 5898640626a66d30543ff9101c0a98052c318834 Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Fri, 16 Aug 2024 12:01:19 +0200 Subject: [PATCH 01/12] NGSTACK-816 show frontend urls by siteaccess in urls tab --- bundle/Resources/config/services/tabs.yaml | 12 ++ .../translations/ibexa_content_url.en.yaml | 5 + .../tab/url/siteaccess_urls_table.html.twig | 38 +++++++ .../themes/ngadmin/content/tab/urls.html.twig | 16 +++ bundle/Tab/LocationView/UrlsTab.php | 107 ++++++++++++++++++ 5 files changed, 178 insertions(+) create mode 100644 bundle/Resources/translations/ibexa_content_url.en.yaml create mode 100644 bundle/Resources/views/themes/ngadmin/content/tab/url/siteaccess_urls_table.html.twig create mode 100644 bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig create mode 100644 bundle/Tab/LocationView/UrlsTab.php diff --git a/bundle/Resources/config/services/tabs.yaml b/bundle/Resources/config/services/tabs.yaml index 5721d97..cfc3327 100644 --- a/bundle/Resources/config/services/tabs.yaml +++ b/bundle/Resources/config/services/tabs.yaml @@ -9,3 +9,15 @@ services: - '@twig' - '@translator' - '@event_dispatcher' + + Netgen\Bundle\IbexaAdminUIExtraBundle\Tab\LocationView\UrlsTab: + decorates: Ibexa\AdminUi\Tab\LocationView\UrlsTab + decoration_inner_name: UrlsTab.inner + arguments: + - '@UrlsTab.inner' + - '@router' + - '@ibexa.config.resolver' + - '%ibexa.site_access.list%' + - '@twig' + - '@translator' + - '@event_dispatcher' diff --git a/bundle/Resources/translations/ibexa_content_url.en.yaml b/bundle/Resources/translations/ibexa_content_url.en.yaml new file mode 100644 index 0000000..d072ed2 --- /dev/null +++ b/bundle/Resources/translations/ibexa_content_url.en.yaml @@ -0,0 +1,5 @@ +tab.urls.siteaccess.headline.content_tree: 'Content tree URLs (inside configured Siteaccess Content tree)' +tab.urls.siteaccess.headline.external: 'External URLs (outside configured Siteaccess Content tree)' +tab.urls.siteaccess: 'Siteaccess' +tab.urls.no_siteaccess_urls: 'This item has no Siteacess URLs.' +tab.urls.url: 'URL' diff --git a/bundle/Resources/views/themes/ngadmin/content/tab/url/siteaccess_urls_table.html.twig b/bundle/Resources/views/themes/ngadmin/content/tab/url/siteaccess_urls_table.html.twig new file mode 100644 index 0000000..965b0f5 --- /dev/null +++ b/bundle/Resources/views/themes/ngadmin/content/tab/url/siteaccess_urls_table.html.twig @@ -0,0 +1,38 @@ +{% trans_default_domain 'ibexa_content_url' %} + +{% set body_rows = [] %} +{% if siteaccess_urls|length > 0 %} + {% for siteaccess, siteaccess_url in siteaccess_urls %} + {% set body_row_cols = [] %} + + {% set col_raw %} + {{ siteaccess_url }} + {% endset %} + + {% set body_row_cols = body_row_cols|merge([{ + content: col_raw, + raw: true, + }]) %} + + {% set col_raw %} + {{ siteaccess }} + {% endset %} + + {% set body_row_cols = body_row_cols|merge([{ + content: col_raw, + raw: true, + }]) %} + + {% set body_rows = body_rows|merge([{ cols: body_row_cols }]) %} + {% endfor %} +{% endif %} + +{% include '@ibexadesign/ui/component/table/table.html.twig' with { + headline: headline, + head_cols: [ + { content: 'tab.urls.url'|trans|desc('URL') }, + { content: 'tab.urls.siteaccess'|trans|desc('Siteaccess') }, + ], + body_rows, + empty_table_info_text: 'tab.urls.no_siteaccess_urls'|trans|desc('This item has no siteacess URLs.'), +} %} diff --git a/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig new file mode 100644 index 0000000..1638704 --- /dev/null +++ b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig @@ -0,0 +1,16 @@ +{% trans_default_domain 'ibexa_content_url' %} + +{% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with { + headline:'tab.urls.siteaccess.headline.content_tree'|trans|desc + ('Content tree URLs (inside configured Siteaccess Content tree)'), + siteaccess_urls: content_tree_urls, +} only %} + +{% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with { + headline: + 'tab.urls.siteaccess.headline.external'|trans|desc + ('External URLs (outside configured Siteaccess Content tree)'), + siteaccess_urls: external_urls, +} only %} + +{% include '@admin/content/tab/urls.html.twig' %} diff --git a/bundle/Tab/LocationView/UrlsTab.php b/bundle/Tab/LocationView/UrlsTab.php new file mode 100644 index 0000000..ce5b776 --- /dev/null +++ b/bundle/Tab/LocationView/UrlsTab.php @@ -0,0 +1,107 @@ +inner->getIdentifier(); + } + + public function getName(): string + { + return $this->inner->getName(); + } + + public function getOrder(): int + { + return $this->inner->getOrder(); + } + + public function getTemplate(): string + { + return $this->inner->getTemplate(); + } + + public function getTemplateParameters(array $contextParameters = []): array + { + $contentTreeUrls = []; + $externalUrls = []; + + /** @var Location $location */ + $location = $contextParameters['location']; + + $locationPath = $location->path; + foreach ($this->siteaccessList as $siteaccess) { + $rootLocationId = $this->configResolver->getParameter( + 'content.tree_root.location_id', + null, + $siteaccess, + ); + + $url = $this->router->generate( + 'ibexa.url.alias', + [ + 'locationId' => $location->id, + 'siteaccess' => $siteaccess, + ], + UrlGeneratorInterface::ABSOLUTE_URL, + ); + + // checks if the url matches invalid system url format + if (preg_match(self::SYSTEM_URL_REGEX_PATTERN, $url)) { + continue; + } + + $locationIdIndex = array_search((string) $location->id, $locationPath, true); + $rootLocationIdIndex = array_search((string) $rootLocationId, $locationPath, true); + + // checks if the url is inside configured siteaccess content tree + if ($locationIdIndex !== false && $rootLocationIdIndex !== false && $rootLocationIdIndex <= $locationIdIndex) { + $contentTreeUrls[$siteaccess] = $url; + } else { + $externalUrls[$siteaccess] = $url; + } + } + + $parameters = [ + 'content_tree_urls' => $contentTreeUrls, + 'external_urls' => $externalUrls, + ]; + + $parentParameters = $this->inner->getTemplateParameters($contextParameters); + + return $parentParameters + $parameters; + } +} From fd261864c6e5ed0a1ae2bf0836f9c92c5b991d7e Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Fri, 16 Aug 2024 12:05:26 +0200 Subject: [PATCH 02/12] NGSTACK-816 cs fixes --- bundle/Tab/LocationView/UrlsTab.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/bundle/Tab/LocationView/UrlsTab.php b/bundle/Tab/LocationView/UrlsTab.php index ce5b776..e1f1660 100644 --- a/bundle/Tab/LocationView/UrlsTab.php +++ b/bundle/Tab/LocationView/UrlsTab.php @@ -59,17 +59,11 @@ public function getTemplateParameters(array $contextParameters = []): array $contentTreeUrls = []; $externalUrls = []; - /** @var Location $location */ + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $location */ $location = $contextParameters['location']; $locationPath = $location->path; foreach ($this->siteaccessList as $siteaccess) { - $rootLocationId = $this->configResolver->getParameter( - 'content.tree_root.location_id', - null, - $siteaccess, - ); - $url = $this->router->generate( 'ibexa.url.alias', [ @@ -85,6 +79,11 @@ public function getTemplateParameters(array $contextParameters = []): array } $locationIdIndex = array_search((string) $location->id, $locationPath, true); + $rootLocationId = $this->configResolver->getParameter( + 'content.tree_root.location_id', + null, + $siteaccess, + ); $rootLocationIdIndex = array_search((string) $rootLocationId, $locationPath, true); // checks if the url is inside configured siteaccess content tree From e7be506233ff61c2ad5a4785a8dc3c433e123166 Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Wed, 21 Aug 2024 15:51:59 +0200 Subject: [PATCH 03/12] NGSTACK-816 add bundle configuration for external urls --- bundle/DependencyInjection/Configuration.php | 42 +++++++++++++++++++ .../NetgenIbexaAdminUIExtraExtension.php | 31 ++++++++++++++ bundle/Resources/config/default_settings.yaml | 2 + bundle/Resources/config/services/tabs.yaml | 1 + .../themes/ngadmin/content/tab/urls.html.twig | 15 ++++--- bundle/Tab/LocationView/UrlsTab.php | 2 + 6 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 bundle/DependencyInjection/Configuration.php create mode 100644 bundle/Resources/config/default_settings.yaml diff --git a/bundle/DependencyInjection/Configuration.php b/bundle/DependencyInjection/Configuration.php new file mode 100644 index 0000000..498c248 --- /dev/null +++ b/bundle/DependencyInjection/Configuration.php @@ -0,0 +1,42 @@ +rootNodeName = $rootNodeName; + } + + public function getConfigTreeBuilder(): TreeBuilder + { + $treeBuilder = new TreeBuilder($this->rootNodeName); + $rootNode = $treeBuilder->getRootNode(); + + $this->addShowExternalSiteaccessUrls($rootNode); + + return $treeBuilder; + } + + private function addShowExternalSiteaccessUrls(ArrayNodeDefinition $nodeDefinition): void + { + $nodeDefinition + ->treatFalseLike(['enabled' => false]) + ->treatTrueLike(['enabled' => true]) + ->treatNullLike(['enabled' => false]) + ->children() + ->booleanNode('show_external_siteaccess_urls') + ->defaultFalse() + ->end() + ?->end(); + } +} diff --git a/bundle/DependencyInjection/NetgenIbexaAdminUIExtraExtension.php b/bundle/DependencyInjection/NetgenIbexaAdminUIExtraExtension.php index d3a2393..50fdcd9 100644 --- a/bundle/DependencyInjection/NetgenIbexaAdminUIExtraExtension.php +++ b/bundle/DependencyInjection/NetgenIbexaAdminUIExtraExtension.php @@ -19,6 +19,16 @@ final class NetgenIbexaAdminUIExtraExtension extends Extension implements PrependExtensionInterface { + public function getAlias(): string + { + return 'netgen_ibexa_admin_ui_extra'; + } + + public function getConfiguration(array $config, ContainerBuilder $container): Configuration + { + return new Configuration($this->getAlias()); + } + public function load(array $configs, ContainerBuilder $container): void { $locator = new FileLocator(__DIR__ . '/../Resources/config'); @@ -33,6 +43,9 @@ public function load(array $configs, ContainerBuilder $container): void ); $loader->load('services/*.yaml', 'glob'); + $loader->load('default_settings.yaml'); + + $this->processExtensionConfiguration($configs, $container); } public function prepend(ContainerBuilder $container): void @@ -48,4 +61,22 @@ public function prepend(ContainerBuilder $container): void $container->addResource(new FileResource($configFile)); } } + + private function processExtensionConfiguration(array $configs, ContainerBuilder $container): void + { + $configuration = $this->getConfiguration($configs, $container); + $configuration = $this->processConfiguration($configuration, $configs); + + $this->processShowExternalSiteaccessUrlsConfiguration($configuration, $container); + } + + private function processShowExternalSiteaccessUrlsConfiguration( + array $configuration, + ContainerBuilder $container, + ): void { + $container->setParameter( + 'netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls', + $configuration['show_external_siteaccess_urls'], + ); + } } diff --git a/bundle/Resources/config/default_settings.yaml b/bundle/Resources/config/default_settings.yaml new file mode 100644 index 0000000..258de19 --- /dev/null +++ b/bundle/Resources/config/default_settings.yaml @@ -0,0 +1,2 @@ +parameters: + netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls: false diff --git a/bundle/Resources/config/services/tabs.yaml b/bundle/Resources/config/services/tabs.yaml index cfc3327..8b10cbb 100644 --- a/bundle/Resources/config/services/tabs.yaml +++ b/bundle/Resources/config/services/tabs.yaml @@ -18,6 +18,7 @@ services: - '@router' - '@ibexa.config.resolver' - '%ibexa.site_access.list%' + - '%netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls%' - '@twig' - '@translator' - '@event_dispatcher' diff --git a/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig index 1638704..eb7b662 100644 --- a/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig +++ b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig @@ -6,11 +6,14 @@ siteaccess_urls: content_tree_urls, } only %} -{% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with { - headline: - 'tab.urls.siteaccess.headline.external'|trans|desc - ('External URLs (outside configured Siteaccess Content tree)'), - siteaccess_urls: external_urls, -} only %} +{% if show_external_urls %} + {% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with { + headline: + 'tab.urls.siteaccess.headline.external'|trans|desc + ('External URLs (outside configured Siteaccess Content tree)'), + siteaccess_urls: external_urls, + } only %} +{% endif %} + {% include '@admin/content/tab/urls.html.twig' %} diff --git a/bundle/Tab/LocationView/UrlsTab.php b/bundle/Tab/LocationView/UrlsTab.php index e1f1660..6109bb6 100644 --- a/bundle/Tab/LocationView/UrlsTab.php +++ b/bundle/Tab/LocationView/UrlsTab.php @@ -27,6 +27,7 @@ public function __construct( private readonly RouterInterface $router, private readonly ConfigResolverInterface $configResolver, private readonly array $siteaccessList, + private readonly bool $showExternalSiteaccessUrls, Environment $twig, TranslatorInterface $translator, EventDispatcherInterface $eventDispatcher, @@ -97,6 +98,7 @@ public function getTemplateParameters(array $contextParameters = []): array $parameters = [ 'content_tree_urls' => $contentTreeUrls, 'external_urls' => $externalUrls, + 'show_external_urls' => $this->showExternalSiteaccessUrls, ]; $parentParameters = $this->inner->getTemplateParameters($contextParameters); From 41ae780829f376e5d0e97a5d5acdc4692fc1b908 Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Wed, 21 Aug 2024 15:52:30 +0200 Subject: [PATCH 04/12] NGSTACK-816 add tests for configuration --- composer.json | 12 ++- phpunit.xml | 8 ++ .../NetgenIbexaAdminUIExtraTest.php | 83 +++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 phpunit.xml create mode 100644 tests/bundle/DependencyInjection/NetgenIbexaAdminUIExtraTest.php diff --git a/composer.json b/composer.json index 6e44e3b..fc90821 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,20 @@ }, "require-dev": { "netgen/ibexa-site-api": "^6.1", - "ibexa/graphql": "^4.5" + "ibexa/graphql": "^4.5", + "phpunit/phpunit": "^10", + "matthiasnoback/symfony-dependency-injection-test": "^4.1" }, "autoload": { "psr-4": { "Netgen\\Bundle\\IbexaAdminUIExtraBundle\\": "bundle" } }, + "autoload-dev": { + "psr-4": { + "Netgen\\IbexaAdminUIExtra\\Tests\\": "tests/bundle" + } + }, "extra": { "branch-alias": { "dev-master": "1.x-dev" @@ -29,5 +36,8 @@ }, "config": { "allow-plugins": false + }, + "scripts": { + "test": "@php vendor/bin/phpunit --colors=always" } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..4925c13 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,8 @@ + + + + + ./tests/bundle/DependencyInjection + + + diff --git a/tests/bundle/DependencyInjection/NetgenIbexaAdminUIExtraTest.php b/tests/bundle/DependencyInjection/NetgenIbexaAdminUIExtraTest.php new file mode 100644 index 0000000..15ee1ff --- /dev/null +++ b/tests/bundle/DependencyInjection/NetgenIbexaAdminUIExtraTest.php @@ -0,0 +1,83 @@ +setParameter('kernel.bundles', []); + } + + public static function provideDefaultConfigurationCases(): iterable + { + return [ + [ + [], + ], + [ + [ + 'show_external_siteaccess_urls' => false, + ], + ], + ]; + } + + public static function provideShowExternalSiteaccessUrlsConfigurationCases(): iterable + { + return [ + [ + [ + 'show_external_siteaccess_urls' => false, + ], + false, + ], + [ + [ + 'show_external_siteaccess_urls' => true, + ], + true, + ], + ]; + } + + /** + * @dataProvider provideDefaultConfigurationCases + */ + public function testDefaultConfiguration(array $configuration): void + { + $this->load($configuration); + + $this->assertContainerBuilderHasParameter( + 'netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls', + false, + ); + } + + /** + * @dataProvider provideShowExternalSiteaccessUrlsConfigurationCases + */ + public function testShowExternalSiteaccessUrlsConfiguration(array $configuration, bool $expectedParameterValue): void + { + $this->load($configuration); + + $this->assertContainerBuilderHasParameter( + 'netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls', + $expectedParameterValue, + ); + } + + protected function getContainerExtensions(): array + { + return [ + new NetgenIbexaAdminUIExtraExtension(), + ]; + } +} From 6ec37137f86c1ba7dd2faacce5ec7ff322d738fa Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Wed, 21 Aug 2024 15:56:38 +0200 Subject: [PATCH 05/12] NGSTACK-816 add testing workflow --- .github/workflows/tests.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..83439ef --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,33 @@ +name: Tests + +on: + push: + branches: + - 'master' + - '[0-9].[0-9]+' + pull_request: ~ + +jobs: + tests: + name: ${{ matrix.php }} / ${{ matrix.phpunit }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php: ['8.1'] + phpunit: ['phpunit.xml'] + + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - run: composer --version + - run: composer validate --strict + + - run: composer update --prefer-dist + + - run: vendor/bin/phpunit -c ${{ matrix.phpunit }} --colors=always From 39b5074b8bcf3325df39ba68431c207099cba325 Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Wed, 21 Aug 2024 16:25:57 +0200 Subject: [PATCH 06/12] NGSTACK-816 add new changes to readme --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 04fdfc3..6c08ab5 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,21 @@ netgen_ibexa_admin_ui_extra: resource: '@NetgenIbexaAdminUIExtraBundle/Resources/config/routing.yaml' ``` +Content URLs by Siteaccess +-------------------------- + +This package enhances the visibility of Content URLs by Siteaccess. URLs can be viewed in the administration interface under the **URL** tab within the Content view. + +The package distinguishes between two types of URLs: + +1. **Content Tree URLs**: URLs that reside within the configured Siteaccess Content tree. +2. **External URLs**: URLs that exist outside of the configured Siteaccess Content tree. + +By default, the overview of External URLs is hidden. To enable the display of these URLs, set the following parameter in your configuration: + +```yaml +netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls: true + + + Licensed under [GPLv2](LICENSE) From 6a95ba2d8894141ae45c5d86b1c95ce8986daf8e Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Wed, 21 Aug 2024 16:27:31 +0200 Subject: [PATCH 07/12] NGSTACK-816 fix readme bug --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c08ab5..cb2c5d0 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ By default, the overview of External URLs is hidden. To enable the display of th ```yaml netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls: true - +``` Licensed under [GPLv2](LICENSE) From b70c2e558415c9e07aa8afefed34860e84a49905 Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Tue, 27 Aug 2024 10:28:10 +0200 Subject: [PATCH 08/12] NGSTACK-816 refactor translations to make more sense --- README.md | 7 ++++--- bundle/Resources/translations/ibexa_content_url.en.yaml | 4 ++-- .../views/themes/ngadmin/content/tab/urls.html.twig | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cb2c5d0..d058d9b 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,11 @@ This package enhances the visibility of Content URLs by Siteaccess. URLs can be The package distinguishes between two types of URLs: -1. **Content Tree URLs**: URLs that reside within the configured Siteaccess Content tree. -2. **External URLs**: URLs that exist outside of the configured Siteaccess Content tree. +1. **Siteaccess URLs** that reside within the configured Siteaccess Content tree. +2. **Siteaccess URLs** that exist outside of the configured Siteaccess Content tree. -By default, the overview of External URLs is hidden. To enable the display of these URLs, set the following parameter in your configuration: +By default, the overview of URLs outside of the configured Content tree is hidden. +To enable the display of these URLs, set the following parameter in your configuration: ```yaml netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls: true diff --git a/bundle/Resources/translations/ibexa_content_url.en.yaml b/bundle/Resources/translations/ibexa_content_url.en.yaml index d072ed2..d6765d9 100644 --- a/bundle/Resources/translations/ibexa_content_url.en.yaml +++ b/bundle/Resources/translations/ibexa_content_url.en.yaml @@ -1,5 +1,5 @@ -tab.urls.siteaccess.headline.content_tree: 'Content tree URLs (inside configured Siteaccess Content tree)' -tab.urls.siteaccess.headline.external: 'External URLs (outside configured Siteaccess Content tree)' +tab.urls.siteaccess.headline.siteaccess_urls: 'Siteaccess URLs' +tab.urls.siteaccess.headline.siteaccess_urls.outside_configured_content_tree_root: 'Siteaccess URLs outside of the configured Content tree root' tab.urls.siteaccess: 'Siteaccess' tab.urls.no_siteaccess_urls: 'This item has no Siteacess URLs.' tab.urls.url: 'URL' diff --git a/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig index eb7b662..ebb7403 100644 --- a/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig +++ b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig @@ -1,16 +1,16 @@ {% trans_default_domain 'ibexa_content_url' %} {% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with { - headline:'tab.urls.siteaccess.headline.content_tree'|trans|desc - ('Content tree URLs (inside configured Siteaccess Content tree)'), + headline:'tab.urls.siteaccess.headline.siteaccess_urls'|trans|desc + ('Siteaccess URLs'), siteaccess_urls: content_tree_urls, } only %} {% if show_external_urls %} {% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with { headline: - 'tab.urls.siteaccess.headline.external'|trans|desc - ('External URLs (outside configured Siteaccess Content tree)'), + 'tab.urls.siteaccess.headline.siteaccess_urls.outside_configured_content_tree_root'|trans|desc + ('Siteaccess URLs outside of the configured Content tree root'), siteaccess_urls: external_urls, } only %} {% endif %} From 9f950749374566c7e43cde1df1b72c3351ce5e50 Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Tue, 27 Aug 2024 10:52:56 +0200 Subject: [PATCH 09/12] NGSTACK-816 rename setting for showing urls outside configured content tree root --- bundle/DependencyInjection/Configuration.php | 3 ++- .../NetgenIbexaAdminUIExtraExtension.php | 8 ++++---- bundle/Resources/config/default_settings.yaml | 2 +- bundle/Resources/config/services/tabs.yaml | 2 +- .../themes/ngadmin/content/tab/urls.html.twig | 7 +++---- bundle/Tab/LocationView/UrlsTab.php | 16 ++++++++-------- .../NetgenIbexaAdminUIExtraTest.php | 10 +++++----- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/bundle/DependencyInjection/Configuration.php b/bundle/DependencyInjection/Configuration.php index 498c248..7941920 100644 --- a/bundle/DependencyInjection/Configuration.php +++ b/bundle/DependencyInjection/Configuration.php @@ -34,8 +34,9 @@ private function addShowExternalSiteaccessUrls(ArrayNodeDefinition $nodeDefiniti ->treatTrueLike(['enabled' => true]) ->treatNullLike(['enabled' => false]) ->children() - ->booleanNode('show_external_siteaccess_urls') + ->booleanNode('show_siteaccess_urls_outside_configured_content_tree_root') ->defaultFalse() + ->info("Show Siteaccess URLs outside of the configured Content tree root in administration's URL tab") ->end() ?->end(); } diff --git a/bundle/DependencyInjection/NetgenIbexaAdminUIExtraExtension.php b/bundle/DependencyInjection/NetgenIbexaAdminUIExtraExtension.php index 50fdcd9..4cf1657 100644 --- a/bundle/DependencyInjection/NetgenIbexaAdminUIExtraExtension.php +++ b/bundle/DependencyInjection/NetgenIbexaAdminUIExtraExtension.php @@ -67,16 +67,16 @@ private function processExtensionConfiguration(array $configs, ContainerBuilder $configuration = $this->getConfiguration($configs, $container); $configuration = $this->processConfiguration($configuration, $configs); - $this->processShowExternalSiteaccessUrlsConfiguration($configuration, $container); + $this->processShowSiteaccessOutsideConfiguredContentTreeRootConfiguration($configuration, $container); } - private function processShowExternalSiteaccessUrlsConfiguration( + private function processShowSiteaccessOutsideConfiguredContentTreeRootConfiguration( array $configuration, ContainerBuilder $container, ): void { $container->setParameter( - 'netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls', - $configuration['show_external_siteaccess_urls'], + 'netgen_ibexa_admin_ui_extra.show_siteaccess_urls_outside_configured_content_tree_root', + $configuration['show_siteaccess_urls_outside_configured_content_tree_root'], ); } } diff --git a/bundle/Resources/config/default_settings.yaml b/bundle/Resources/config/default_settings.yaml index 258de19..6ebf6a0 100644 --- a/bundle/Resources/config/default_settings.yaml +++ b/bundle/Resources/config/default_settings.yaml @@ -1,2 +1,2 @@ parameters: - netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls: false + netgen_ibexa_admin_ui_extra.show_siteaccess_urls_outside_configured_content_tree_root: false diff --git a/bundle/Resources/config/services/tabs.yaml b/bundle/Resources/config/services/tabs.yaml index 8b10cbb..373c614 100644 --- a/bundle/Resources/config/services/tabs.yaml +++ b/bundle/Resources/config/services/tabs.yaml @@ -18,7 +18,7 @@ services: - '@router' - '@ibexa.config.resolver' - '%ibexa.site_access.list%' - - '%netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls%' + - '%netgen_ibexa_admin_ui_extra.show_siteaccess_urls_outside_configured_content_tree_root%' - '@twig' - '@translator' - '@event_dispatcher' diff --git a/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig index ebb7403..fa9cb18 100644 --- a/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig +++ b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig @@ -3,17 +3,16 @@ {% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with { headline:'tab.urls.siteaccess.headline.siteaccess_urls'|trans|desc ('Siteaccess URLs'), - siteaccess_urls: content_tree_urls, + siteaccess_urls: siteaccess_urls, } only %} -{% if show_external_urls %} +{% if show_siteaccess_urls_outside_configured_content_tree_root %} {% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with { headline: 'tab.urls.siteaccess.headline.siteaccess_urls.outside_configured_content_tree_root'|trans|desc ('Siteaccess URLs outside of the configured Content tree root'), - siteaccess_urls: external_urls, + siteaccess_urls: siteaccess_urls_outside_configured_content_tree_root, } only %} {% endif %} - {% include '@admin/content/tab/urls.html.twig' %} diff --git a/bundle/Tab/LocationView/UrlsTab.php b/bundle/Tab/LocationView/UrlsTab.php index 6109bb6..819ec6a 100644 --- a/bundle/Tab/LocationView/UrlsTab.php +++ b/bundle/Tab/LocationView/UrlsTab.php @@ -27,7 +27,7 @@ public function __construct( private readonly RouterInterface $router, private readonly ConfigResolverInterface $configResolver, private readonly array $siteaccessList, - private readonly bool $showExternalSiteaccessUrls, + private readonly bool $showSiteaccessUrlsOutsideConfiguredContentTreeRoot, Environment $twig, TranslatorInterface $translator, EventDispatcherInterface $eventDispatcher, @@ -57,8 +57,8 @@ public function getTemplate(): string public function getTemplateParameters(array $contextParameters = []): array { - $contentTreeUrls = []; - $externalUrls = []; + $siteaccessUrls = []; + $siteaccessUrlsOutsideConfiguredContentTreeRoot = []; /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $location */ $location = $contextParameters['location']; @@ -89,16 +89,16 @@ public function getTemplateParameters(array $contextParameters = []): array // checks if the url is inside configured siteaccess content tree if ($locationIdIndex !== false && $rootLocationIdIndex !== false && $rootLocationIdIndex <= $locationIdIndex) { - $contentTreeUrls[$siteaccess] = $url; + $siteaccessUrls[$siteaccess] = $url; } else { - $externalUrls[$siteaccess] = $url; + $siteaccessUrlsOutsideConfiguredContentTreeRoot[$siteaccess] = $url; } } $parameters = [ - 'content_tree_urls' => $contentTreeUrls, - 'external_urls' => $externalUrls, - 'show_external_urls' => $this->showExternalSiteaccessUrls, + 'siteaccess_urls' => $siteaccessUrls, + 'siteaccess_urls_outside_configured_content_tree_root' => $siteaccessUrlsOutsideConfiguredContentTreeRoot, + 'show_siteaccess_urls_outside_configured_content_tree_root' => $this->showSiteaccessUrlsOutsideConfiguredContentTreeRoot, ]; $parentParameters = $this->inner->getTemplateParameters($contextParameters); diff --git a/tests/bundle/DependencyInjection/NetgenIbexaAdminUIExtraTest.php b/tests/bundle/DependencyInjection/NetgenIbexaAdminUIExtraTest.php index 15ee1ff..7b3a64e 100644 --- a/tests/bundle/DependencyInjection/NetgenIbexaAdminUIExtraTest.php +++ b/tests/bundle/DependencyInjection/NetgenIbexaAdminUIExtraTest.php @@ -24,7 +24,7 @@ public static function provideDefaultConfigurationCases(): iterable ], [ [ - 'show_external_siteaccess_urls' => false, + 'show_siteaccess_urls_outside_configured_content_tree_root' => false, ], ], ]; @@ -35,13 +35,13 @@ public static function provideShowExternalSiteaccessUrlsConfigurationCases(): it return [ [ [ - 'show_external_siteaccess_urls' => false, + 'show_siteaccess_urls_outside_configured_content_tree_root' => false, ], false, ], [ [ - 'show_external_siteaccess_urls' => true, + 'show_siteaccess_urls_outside_configured_content_tree_root' => true, ], true, ], @@ -56,7 +56,7 @@ public function testDefaultConfiguration(array $configuration): void $this->load($configuration); $this->assertContainerBuilderHasParameter( - 'netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls', + 'netgen_ibexa_admin_ui_extra.show_siteaccess_urls_outside_configured_content_tree_root', false, ); } @@ -69,7 +69,7 @@ public function testShowExternalSiteaccessUrlsConfiguration(array $configuration $this->load($configuration); $this->assertContainerBuilderHasParameter( - 'netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls', + 'netgen_ibexa_admin_ui_extra.show_siteaccess_urls_outside_configured_content_tree_root', $expectedParameterValue, ); } From a3b8b53a2be9b78bab0c21415f54dd6809393da0 Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Tue, 27 Aug 2024 10:58:23 +0200 Subject: [PATCH 10/12] NGSTACK-816 fix incorrect documentation in readme --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d058d9b..6189cc9 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,12 @@ The package distinguishes between two types of URLs: 1. **Siteaccess URLs** that reside within the configured Siteaccess Content tree. 2. **Siteaccess URLs** that exist outside of the configured Siteaccess Content tree. -By default, the overview of URLs outside of the configured Content tree is hidden. -To enable the display of these URLs, set the following parameter in your configuration: +By default, the overview of URLs outside the configured Content tree is disabled. +To display these URLs, you need to enable this option in your configuration: ```yaml -netgen_ibexa_admin_ui_extra.show_external_siteaccess_urls: true +netgen_ibexa_admin_ui_extra: + show_siteaccess_urls_outside_configured_content_tree_root: true ``` From 2bda698d028983f48de002ec44ed073acc5a83de Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Tue, 27 Aug 2024 11:00:28 +0200 Subject: [PATCH 11/12] NGSTACK-816 remove redundant of in translations --- README.md | 2 +- bundle/DependencyInjection/Configuration.php | 2 +- bundle/Resources/translations/ibexa_content_url.en.yaml | 2 +- .../Resources/views/themes/ngadmin/content/tab/urls.html.twig | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6189cc9..86c791e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ This package enhances the visibility of Content URLs by Siteaccess. URLs can be The package distinguishes between two types of URLs: 1. **Siteaccess URLs** that reside within the configured Siteaccess Content tree. -2. **Siteaccess URLs** that exist outside of the configured Siteaccess Content tree. +2. **Siteaccess URLs** that exist outside the configured Siteaccess Content tree. By default, the overview of URLs outside the configured Content tree is disabled. To display these URLs, you need to enable this option in your configuration: diff --git a/bundle/DependencyInjection/Configuration.php b/bundle/DependencyInjection/Configuration.php index 7941920..723c429 100644 --- a/bundle/DependencyInjection/Configuration.php +++ b/bundle/DependencyInjection/Configuration.php @@ -36,7 +36,7 @@ private function addShowExternalSiteaccessUrls(ArrayNodeDefinition $nodeDefiniti ->children() ->booleanNode('show_siteaccess_urls_outside_configured_content_tree_root') ->defaultFalse() - ->info("Show Siteaccess URLs outside of the configured Content tree root in administration's URL tab") + ->info("Show Siteaccess URLs outside the configured Content tree root in administration's URL tab") ->end() ?->end(); } diff --git a/bundle/Resources/translations/ibexa_content_url.en.yaml b/bundle/Resources/translations/ibexa_content_url.en.yaml index d6765d9..6152ec0 100644 --- a/bundle/Resources/translations/ibexa_content_url.en.yaml +++ b/bundle/Resources/translations/ibexa_content_url.en.yaml @@ -1,5 +1,5 @@ tab.urls.siteaccess.headline.siteaccess_urls: 'Siteaccess URLs' -tab.urls.siteaccess.headline.siteaccess_urls.outside_configured_content_tree_root: 'Siteaccess URLs outside of the configured Content tree root' +tab.urls.siteaccess.headline.siteaccess_urls.outside_configured_content_tree_root: 'Siteaccess URLs outside the configured Content tree root' tab.urls.siteaccess: 'Siteaccess' tab.urls.no_siteaccess_urls: 'This item has no Siteacess URLs.' tab.urls.url: 'URL' diff --git a/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig index fa9cb18..a8f9557 100644 --- a/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig +++ b/bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig @@ -10,7 +10,7 @@ {% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with { headline: 'tab.urls.siteaccess.headline.siteaccess_urls.outside_configured_content_tree_root'|trans|desc - ('Siteaccess URLs outside of the configured Content tree root'), + ('Siteaccess URLs outside the configured Content tree root'), siteaccess_urls: siteaccess_urls_outside_configured_content_tree_root, } only %} {% endif %} From 122f36ae539cf712acf7a6013ccc8a7673edf842 Mon Sep 17 00:00:00 2001 From: Petar Jakopec Date: Tue, 27 Aug 2024 11:08:32 +0200 Subject: [PATCH 12/12] NGSTACK-816 remove redundant checks in UrlsTab --- bundle/Tab/LocationView/UrlsTab.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/bundle/Tab/LocationView/UrlsTab.php b/bundle/Tab/LocationView/UrlsTab.php index 819ec6a..c71c962 100644 --- a/bundle/Tab/LocationView/UrlsTab.php +++ b/bundle/Tab/LocationView/UrlsTab.php @@ -15,7 +15,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Environment; -use function array_search; +use function in_array; use function preg_match; final class UrlsTab extends AbstractEventDispatchingTab implements OrderedTabInterface @@ -63,7 +63,6 @@ public function getTemplateParameters(array $contextParameters = []): array /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $location */ $location = $contextParameters['location']; - $locationPath = $location->path; foreach ($this->siteaccessList as $siteaccess) { $url = $this->router->generate( 'ibexa.url.alias', @@ -79,16 +78,7 @@ public function getTemplateParameters(array $contextParameters = []): array continue; } - $locationIdIndex = array_search((string) $location->id, $locationPath, true); - $rootLocationId = $this->configResolver->getParameter( - 'content.tree_root.location_id', - null, - $siteaccess, - ); - $rootLocationIdIndex = array_search((string) $rootLocationId, $locationPath, true); - - // checks if the url is inside configured siteaccess content tree - if ($locationIdIndex !== false && $rootLocationIdIndex !== false && $rootLocationIdIndex <= $locationIdIndex) { + if ($this->isUnderConfiguredContentTreeRoot($location, $siteaccess)) { $siteaccessUrls[$siteaccess] = $url; } else { $siteaccessUrlsOutsideConfiguredContentTreeRoot[$siteaccess] = $url; @@ -105,4 +95,15 @@ public function getTemplateParameters(array $contextParameters = []): array return $parentParameters + $parameters; } + + private function isUnderConfiguredContentTreeRoot(Location $location, string $siteaccess): bool + { + $rootLocationId = $this->configResolver->getParameter( + 'content.tree_root.location_id', + null, + $siteaccess, + ); + + return in_array((string) $rootLocationId, $location->path, true); + } }