-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not persist dynamic permission resources in layout definitions as …
…then the permission resources are not refreshed when the layout opens
- Loading branch information
1 parent
3091979
commit 1320f1f
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace FrontendPermissionToolkitBundle\EventSubscriber; | ||
|
||
use FrontendPermissionToolkitBundle\CoreExtensions\ClassDefinitions\DynamicPermissionResource; | ||
use Pimcore\Event\DataObjectCustomLayoutEvents; | ||
use Pimcore\Event\Model\DataObject\CustomLayoutEvent; | ||
use Pimcore\Model\DataObject\ClassDefinition; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CustomLayoutSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
DataObjectCustomLayoutEvents::PRE_ADD => '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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters