Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NGSTACK-816 show frontent urls by siteaccess #2

Merged
merged 12 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,23 @@ 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. **Siteaccess URLs** that reside within 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:

```yaml
netgen_ibexa_admin_ui_extra:
show_siteaccess_urls_outside_configured_content_tree_root: true
```


Licensed under [GPLv2](LICENSE)
43 changes: 43 additions & 0 deletions bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Netgen\Bundle\IbexaAdminUIExtraBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

final class Configuration implements ConfigurationInterface
{
private string $rootNodeName;

public function __construct(string $rootNodeName)
{
$this->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_siteaccess_urls_outside_configured_content_tree_root')
->defaultFalse()
->info("Show Siteaccess URLs outside the configured Content tree root in administration's URL tab")
->end()
?->end();
}
}
31 changes: 31 additions & 0 deletions bundle/DependencyInjection/NetgenIbexaAdminUIExtraExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -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->processShowSiteaccessOutsideConfiguredContentTreeRootConfiguration($configuration, $container);
}

private function processShowSiteaccessOutsideConfiguredContentTreeRootConfiguration(
array $configuration,
ContainerBuilder $container,
): void {
$container->setParameter(
'netgen_ibexa_admin_ui_extra.show_siteaccess_urls_outside_configured_content_tree_root',
$configuration['show_siteaccess_urls_outside_configured_content_tree_root'],
);
}
}
2 changes: 2 additions & 0 deletions bundle/Resources/config/default_settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
netgen_ibexa_admin_ui_extra.show_siteaccess_urls_outside_configured_content_tree_root: false
13 changes: 13 additions & 0 deletions bundle/Resources/config/services/tabs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ 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%'
- '%netgen_ibexa_admin_ui_extra.show_siteaccess_urls_outside_configured_content_tree_root%'
- '@twig'
- '@translator'
- '@event_dispatcher'
5 changes: 5 additions & 0 deletions bundle/Resources/translations/ibexa_content_url.en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tab.urls.siteaccess.headline.siteaccess_urls: 'Siteaccess URLs'
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'
Original file line number Diff line number Diff line change
@@ -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 %}
<a href="{{ siteaccess_url }}">{{ siteaccess_url }}</a>
{% 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.'),
} %}
18 changes: 18 additions & 0 deletions bundle/Resources/views/themes/ngadmin/content/tab/urls.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% trans_default_domain 'ibexa_content_url' %}

{% include '@ibexadesign/content/tab/url/siteaccess_urls_table.html.twig' with {
headline:'tab.urls.siteaccess.headline.siteaccess_urls'|trans|desc
('Siteaccess URLs'),
siteaccess_urls: siteaccess_urls,
} only %}

{% 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 the configured Content tree root'),
siteaccess_urls: siteaccess_urls_outside_configured_content_tree_root,
} only %}
{% endif %}

{% include '@admin/content/tab/urls.html.twig' %}
109 changes: 109 additions & 0 deletions bundle/Tab/LocationView/UrlsTab.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

declare(strict_types=1);

namespace Netgen\Bundle\IbexaAdminUIExtraBundle\Tab\LocationView;

use Ibexa\AdminUi\Tab\LocationView\UrlsTab as IbexaUrlsTab;
use Ibexa\Contracts\AdminUi\Tab\AbstractEventDispatchingTab;
use Ibexa\Contracts\AdminUi\Tab\OrderedTabInterface;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

use function in_array;
use function preg_match;

final class UrlsTab extends AbstractEventDispatchingTab implements OrderedTabInterface
{
private const SYSTEM_URL_REGEX_PATTERN = '#/view/content/\d+/full/\d+/\d+$#';

public function __construct(
private readonly IbexaUrlsTab $inner,
private readonly RouterInterface $router,
private readonly ConfigResolverInterface $configResolver,
private readonly array $siteaccessList,
private readonly bool $showSiteaccessUrlsOutsideConfiguredContentTreeRoot,
Environment $twig,
TranslatorInterface $translator,
EventDispatcherInterface $eventDispatcher,
) {
parent::__construct($twig, $translator, $eventDispatcher);
}

public function getIdentifier(): string
{
return $this->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
{
$siteaccessUrls = [];
$siteaccessUrlsOutsideConfiguredContentTreeRoot = [];

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location $location */
$location = $contextParameters['location'];

foreach ($this->siteaccessList as $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;
}

if ($this->isUnderConfiguredContentTreeRoot($location, $siteaccess)) {
$siteaccessUrls[$siteaccess] = $url;
} else {
$siteaccessUrlsOutsideConfiguredContentTreeRoot[$siteaccess] = $url;
}
}

$parameters = [
'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);

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);
}
}
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,29 @@
},
"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"
}
},
"config": {
"allow-plugins": false
},
"scripts": {
"test": "@php vendor/bin/phpunit --colors=always"
}
}
8 changes: 8 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Dependency injection unit tests">
<directory suffix="Test.php">./tests/bundle/DependencyInjection</directory>
</testsuite>
</testsuites>
</phpunit>
Loading
Loading