diff --git a/src/EventSubscriber/CustomLayoutSubscriber.php b/src/EventSubscriber/CustomLayoutSubscriber.php new file mode 100644 index 0000000..2323b21 --- /dev/null +++ b/src/EventSubscriber/CustomLayoutSubscriber.php @@ -0,0 +1,46 @@ + '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