vendor/ibexa/dashboard/src/bundle/Form/Processor/DashboardPublishFormProcessor.php line 44

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\Bundle\Dashboard\Form\Processor;
  8. use Ibexa\ContentForms\Data\Content\ContentUpdateData;
  9. use Ibexa\ContentForms\Event\ContentFormEvents;
  10. use Ibexa\ContentForms\Event\FormActionEvent;
  11. use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface;
  12. use Ibexa\Dashboard\Specification\IsDashboardContentType;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\HttpFoundation\RedirectResponse;
  15. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  16. final class DashboardPublishFormProcessor implements EventSubscriberInterface
  17. {
  18.     private ConfigResolverInterface $configResolver;
  19.     /**
  20.      * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface
  21.      */
  22.     private UrlGeneratorInterface $urlGenerator;
  23.     public function __construct(
  24.         UrlGeneratorInterface $urlGenerator,
  25.         ConfigResolverInterface $configResolver
  26.     ) {
  27.         $this->configResolver $configResolver;
  28.         $this->urlGenerator $urlGenerator;
  29.     }
  30.     public static function getSubscribedEvents()
  31.     {
  32.         return [
  33.             ContentFormEvents::CONTENT_PUBLISH => ['processPublish', -255],
  34.         ];
  35.     }
  36.     public function processPublish(FormActionEvent $event): void
  37.     {
  38.         $data $event->getData();
  39.         if (!$data instanceof ContentUpdateData) {
  40.             return;
  41.         }
  42.         /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */
  43.         $content $event->getPayload('content');
  44.         if (!(new IsDashboardContentType($this->configResolver))->isSatisfiedBy($content->getContentType())) {
  45.             return;
  46.         }
  47.         $redirectUrl $this->urlGenerator->generate(
  48.             'ibexa.dashboard'
  49.         );
  50.         $event->setResponse(new RedirectResponse($redirectUrl));
  51.     }
  52. }