vendor/ibexa/workflow/src/lib/Event/Subscriber/VersionLockedExceptionListener.php line 40

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\Workflow\Event\Subscriber;
  8. use Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface;
  9. use Ibexa\Contracts\Core\Repository\ContentService;
  10. use Ibexa\Workflow\Exception\VersionLockedException;
  11. use JMS\TranslationBundle\Annotation\Desc;
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  14. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  15. final class VersionLockedExceptionListener
  16. {
  17.     /** @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface */
  18.     private $urlGenerator;
  19.     /** @var \Ibexa\Contracts\Core\Repository\ContentService */
  20.     private $contentService;
  21.     /** @var \Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface */
  22.     private $notificationHandler;
  23.     public function __construct(
  24.         UrlGeneratorInterface $urlGenerator,
  25.         ContentService $contentService,
  26.         TranslatableNotificationHandlerInterface $notificationHandler
  27.     ) {
  28.         $this->urlGenerator $urlGenerator;
  29.         $this->contentService $contentService;
  30.         $this->notificationHandler $notificationHandler;
  31.     }
  32.     public function onVersionLocked(ExceptionEvent $event): void
  33.     {
  34.         $exception $event->getThrowable();
  35.         if ($exception instanceof VersionLockedException) {
  36.             $user $exception->getUser();
  37.             $versionLock $exception->getVersionLock();
  38.             $this->notificationHandler->warning(
  39.                 /** @Desc("Version is assigned to another user (%name%).") */
  40.                 'draft.edit.locked.notification',
  41.                 ['%name%' => $user->getName()],
  42.                 'ibexa_workflow'
  43.             );
  44.             $content $this->contentService->loadContent($versionLock->contentId);
  45.             $route $content->contentInfo->isDraft()
  46.                 ? $this->urlGenerator->generate('ibexa.dashboard')
  47.                 : $this->urlGenerator->generate('ibexa.content.view', [
  48.                     'contentId' => $versionLock->contentId,
  49.                 ]);
  50.             $event->setResponse(new RedirectResponse($route));
  51.         }
  52.     }
  53. }