From 8df3f91785f759ffe65c638ab2927024a5739217 Mon Sep 17 00:00:00 2001 From: markus-moser Date: Tue, 13 Feb 2024 13:59:33 +0100 Subject: [PATCH] Do not persist dynamic permission resources in layout definitions (#62) --- .../CustomLayoutSubscriber.php | 59 +++++++++++++++++++ src/Resources/config/services.yml | 4 ++ 2 files changed, 63 insertions(+) create mode 100644 src/EventSubscriber/CustomLayoutSubscriber.php diff --git a/src/EventSubscriber/CustomLayoutSubscriber.php b/src/EventSubscriber/CustomLayoutSubscriber.php new file mode 100644 index 0000000..1072aa6 --- /dev/null +++ b/src/EventSubscriber/CustomLayoutSubscriber.php @@ -0,0 +1,59 @@ + 'onUpdate', + DataObjectCustomLayoutEvents::PRE_UPDATE => 'onUpdate', + ]; + } + + public function onUpdate(CustomLayoutEvent $event): void + { + $customLayout = $event->getCustomLayout(); + $this->resetPermissionResources($customLayout->getLayoutDefinitions()); + } + + private function resetPermissionResources(ClassDefinition\Data | ClassDefinition\Layout | null $layout): void + { + if ($layout === null) { + return; + } + + if ($layout instanceof DynamicPermissionResource) { + $layout->setPermissionResources([]); + } + if (method_exists($layout, 'getChildren')) { + foreach ($layout->getChildren() ?? [] as $child) { + $this->resetPermissionResources($child); + } + } + } +} diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 0b08772..6d3c762 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -7,3 +7,7 @@ services: bundle.frontendpermissiontoolkit.service: alias: FrontendPermissionToolkitBundle\Service + + FrontendPermissionToolkitBundle\EventSubscriber\CustomLayoutSubscriber: + tags: + - { name: kernel.event_subscriber } \ No newline at end of file