Skip to content

Commit

Permalink
[Task] Add listener to enable options like in Classic UI (#542)
Browse files Browse the repository at this point in the history
* add listener to enable options like in classic ui

* Apply php-cs-fixer changes

* remove unused service

---------

Co-authored-by: lukmzig <[email protected]>
  • Loading branch information
lukmzig and lukmzig authored Nov 6, 2024
1 parent c02221c commit 3aa25d5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
4 changes: 4 additions & 0 deletions config/event_subscribers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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%']
5 changes: 0 additions & 5 deletions src/DataObject/Data/Adapter/ReverseObjectRelationAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
63 changes: 63 additions & 0 deletions src/EventSubscriber/ApiContextSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\EventSubscriber;

use Pimcore\Bundle\StaticResolverBundle\Lib\PimcoreResolverInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\DataObjectResolverInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\LocalizedFieldResolverInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\Document\DocumentResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\StudioBackendPathTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* @internal
*/
final readonly class ApiContextSubscriber implements EventSubscriberInterface
{
use StudioBackendPathTrait;

public function __construct(
private string $urlPrefix,
private DataObjectResolverInterface $dataObjectResolver,
private DocumentResolverInterface $documentResolver,
private LocalizedFieldResolverInterface $localizedFieldResolver,
private PimcoreResolverInterface $pimcoreResolver,
) {
}

public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => '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);
}
}

0 comments on commit 3aa25d5

Please sign in to comment.