Skip to content

Commit

Permalink
Override debug layout URL generator, in order to use admin siteaccess
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Dec 7, 2023
1 parent 44b4649 commit ab8ca63
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
36 changes: 36 additions & 0 deletions bundle/Debug/DataCollector/LayoutUrlGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Netgen\Bundle\LayoutsEzPlatformBundle\Debug\DataCollector;

use Netgen\Bundle\LayoutsDebugBundle\DataCollector\LayoutUrlGeneratorInterface;
use Ramsey\Uuid\UuidInterface;

final class LayoutUrlGenerator implements LayoutUrlGeneratorInterface
{
private LayoutUrlGeneratorInterface $innerGenerator;

/**
* @var array<string, string[]>
*/
private array $siteAccessGroups;

/**
* @param array<string, string[]> $siteAccessGroups
*/
public function __construct(
LayoutUrlGeneratorInterface $innerGenerator,
array $siteAccessGroups,
) {
$this->innerGenerator = $innerGenerator;
$this->siteAccessGroups = $siteAccessGroups;
}

public function generateLayoutUrl(UuidInterface $layoutId, array $parameters = []): string
{
$adminSiteAccess = $this->siteAccessGroups['admin_group'][0] ?? 'admin';

return $this->innerGenerator->generateLayoutUrl($layoutId, ['siteaccess' => $adminSiteAccess]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('eztags/services.yaml');
}

if (array_key_exists('NetgenLayoutsDebugBundle', $activatedBundles)) {
$loader->load('debug/services.yaml');
}

$loader->load(
// Nameable interface for field types does not exist in eZ Platform v3
interface_exists(Nameable::class) ?
Expand Down
7 changes: 7 additions & 0 deletions bundle/Resources/config/debug/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
netgen_layouts.ezplatform.debug.data_collector.layout_url_generator:
class: Netgen\Bundle\LayoutsEzPlatformBundle\Debug\DataCollector\LayoutUrlGenerator
decorates: netgen_layouts.debug.data_collector.layout_url_generator
arguments:
- "@.inner"
- "%ezpublish.siteaccess.groups%"
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"netgen/layouts-core": "~1.4.6",
"netgen/layouts-core": "~1.4.9",
"netgen/content-browser-ezplatform": "^1.4",
"ezsystems/ezplatform-admin-ui": "^1.5 || ^2.3",
"ezsystems/ezplatform-http-cache": "^1.0 || ^2.3"
Expand Down

0 comments on commit ab8ca63

Please sign in to comment.