From 3aa25d518d992dfaa44f75f9ce2157140fe72a2b Mon Sep 17 00:00:00 2001 From: lukmzig <30526586+lukmzig@users.noreply.github.com> Date: Wed, 6 Nov 2024 13:31:23 +0100 Subject: [PATCH] [Task] Add listener to enable options like in Classic UI (#542) * add listener to enable options like in classic ui * Apply php-cs-fixer changes * remove unused service --------- Co-authored-by: lukmzig --- config/event_subscribers.yaml | 4 ++ .../Adapter/ReverseObjectRelationAdapter.php | 5 -- src/EventSubscriber/ApiContextSubscriber.php | 63 +++++++++++++++++++ 3 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 src/EventSubscriber/ApiContextSubscriber.php diff --git a/config/event_subscribers.yaml b/config/event_subscribers.yaml index 0693e57d..cbfc3dcd 100644 --- a/config/event_subscribers.yaml +++ b/config/event_subscribers.yaml @@ -9,6 +9,10 @@ services: tags: [ 'kernel.event_subscriber' ] arguments: ['%pimcore_studio_backend.url_prefix%'] + Pimcore\Bundle\StudioBackendBundle\EventSubscriber\ApiContextSubscriber: + tags: [ 'kernel.event_subscriber' ] + arguments: ['%pimcore_studio_backend.url_prefix%'] + Pimcore\Bundle\StudioBackendBundle\EventSubscriber\ApiExceptionSubscriber: tags: [ 'kernel.event_subscriber' ] arguments: ["%kernel.environment%", '%pimcore_studio_backend.url_prefix%'] \ No newline at end of file diff --git a/src/DataObject/Data/Adapter/ReverseObjectRelationAdapter.php b/src/DataObject/Data/Adapter/ReverseObjectRelationAdapter.php index d4acbdfc..a0cd40e1 100644 --- a/src/DataObject/Data/Adapter/ReverseObjectRelationAdapter.php +++ b/src/DataObject/Data/Adapter/ReverseObjectRelationAdapter.php @@ -23,7 +23,6 @@ use Pimcore\Bundle\StudioBackendBundle\DataObject\Data\SetterDataInterface; use Pimcore\Bundle\StudioBackendBundle\DataObject\Service\DataAdapterLoaderInterface; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; -use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\ClassDefinition\Data; use Pimcore\Model\DataObject\ClassDefinition\Data\ReverseObjectRelation; use Pimcore\Model\DataObject\Concrete; @@ -66,13 +65,9 @@ public function getDataForSetter( return null; } - //TODO: Remove the unpublished settings once the context is defined - $doUnpublished = DataObject::doHideUnpublished(); - DataObject::setHideUnpublished(false); $ownerFieldName = $fieldDefinition->getOwnerFieldName(); $relations = $element->getRelationData($ownerFieldName, false, $remoteClass->getId()); $this->processRemoteOwnerRelations($element, $relations, $relationData, $ownerFieldName); - DataObject::setHideUnpublished($doUnpublished); return null; } diff --git a/src/EventSubscriber/ApiContextSubscriber.php b/src/EventSubscriber/ApiContextSubscriber.php new file mode 100644 index 00000000..bf4510e1 --- /dev/null +++ b/src/EventSubscriber/ApiContextSubscriber.php @@ -0,0 +1,63 @@ + 'onKernelRequest', + ]; + } + + public function onKernelRequest(RequestEvent $event): void + { + $request = $event->getRequest(); + if (!$event->isMainRequest() || !$this->isStudioBackendPath($request->getPathInfo(), $this->urlPrefix)) { + return; + } + + $this->pimcoreResolver->setAdminMode(); + $this->dataObjectResolver->setHideUnpublished(false); + $this->documentResolver->setHideUnpublished(false); + $this->localizedFieldResolver->setGetFallbackValues(false); + } +}