vendor/ibexa/admin-ui/src/lib/Form/Processor/ContentEditNotificationFormProcessor.php line 61

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\AdminUi\Form\Processor;
  8. use Ibexa\AdminUi\Specification\SiteAccess\IsAdmin;
  9. use Ibexa\ContentForms\Event\ContentFormEvents;
  10. use Ibexa\ContentForms\Event\FormActionEvent;
  11. use Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. class ContentEditNotificationFormProcessor implements EventSubscriberInterface
  16. {
  17.     /** @var \Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface */
  18.     private $notificationHandler;
  19.     /** @var \Symfony\Component\HttpFoundation\RequestStack */
  20.     private $requestStack;
  21.     /** @var array */
  22.     private $siteAccessGroups;
  23.     /**
  24.      * @param \Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface $notificationHandler
  25.      * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
  26.      * @param array $siteAccessGroups
  27.      */
  28.     public function __construct(
  29.         TranslatableNotificationHandlerInterface $notificationHandler,
  30.         RequestStack $requestStack,
  31.         array $siteAccessGroups
  32.     ) {
  33.         $this->notificationHandler $notificationHandler;
  34.         $this->requestStack $requestStack;
  35.         $this->siteAccessGroups $siteAccessGroups;
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public static function getSubscribedEvents()
  41.     {
  42.         return [
  43.             ContentFormEvents::CONTENT_PUBLISH => ['addPublishMessage'5],
  44.             ContentFormEvents::CONTENT_SAVE_DRAFT => ['addSaveDraftMessage'5],
  45.         ];
  46.     }
  47.     /**
  48.      * @param \Ibexa\ContentForms\Event\FormActionEvent $event
  49.      *
  50.      * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
  51.      */
  52.     public function addPublishMessage(FormActionEvent $event)
  53.     {
  54.         if (!$this->isAdminSiteAccess($this->requestStack->getCurrentRequest())) {
  55.             return;
  56.         }
  57.         $this->notificationHandler->success(
  58.             /** @Desc("Content published.") */
  59.             'content.published.success',
  60.             [],
  61.             'content_edit'
  62.         );
  63.     }
  64.     /**
  65.      * @param \Ibexa\ContentForms\Event\FormActionEvent $event
  66.      *
  67.      * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
  68.      */
  69.     public function addSaveDraftMessage(FormActionEvent $event)
  70.     {
  71.         if (!$this->isAdminSiteAccess($this->requestStack->getCurrentRequest())) {
  72.             return;
  73.         }
  74.         $this->notificationHandler->success(
  75.             /** @Desc("Content draft saved.") */
  76.             'content.draft_saved.success',
  77.             [],
  78.             'content_edit'
  79.         );
  80.     }
  81.     /**
  82.      * @param \Symfony\Component\HttpFoundation\Request $request
  83.      *
  84.      * @return bool
  85.      *
  86.      * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
  87.      */
  88.     protected function isAdminSiteAccess(Request $request): bool
  89.     {
  90.         return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy($request->attributes->get('siteaccess'));
  91.     }
  92. }
  93. class_alias(ContentEditNotificationFormProcessor::class, 'EzSystems\EzPlatformAdminUi\Form\Processor\ContentEditNotificationFormProcessor');