vendor/ibexa/admin-ui/src/lib/Form/Processor/Content/ContentOnTheFlyProcessor.php line 79

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\Content;
  8. use Ibexa\ContentForms\Event\FormActionEvent;
  9. use Ibexa\ContentForms\Form\Processor\ContentFormProcessor;
  10. use Ibexa\Contracts\AdminUi\Event\ContentOnTheFlyEvents;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Twig\Environment;
  14. class ContentOnTheFlyProcessor implements EventSubscriberInterface
  15. {
  16. /** @var \Twig\Environment */
  17. private $twig;
  18. /** @var \Ibexa\ContentForms\Form\Processor\ContentFormProcessor */
  19. private $innerContentFormProcessor;
  20. public function __construct(
  21. Environment $twig,
  22. ContentFormProcessor $innerContentFormProcessor
  23. ) {
  24. $this->twig = $twig;
  25. $this->innerContentFormProcessor = $innerContentFormProcessor;
  26. }
  27. /**
  28. * Returns an array of event names this subscriber wants to listen to.
  29. *
  30. * @return array The event names to listen to
  31. */
  32. public static function getSubscribedEvents()
  33. {
  34. return [
  35. ContentOnTheFlyEvents::CONTENT_CREATE_PUBLISH => ['processCreatePublish', 10],
  36. ContentOnTheFlyEvents::CONTENT_EDIT_PUBLISH => ['processEditPublish', 10],
  37. ];
  38. }
  39. /**
  40. * @param \Ibexa\ContentForms\Event\FormActionEvent $event
  41. *
  42. * @throws \Twig\Error\LoaderError
  43. * @throws \Twig\Error\RuntimeError
  44. * @throws \Twig\Error\SyntaxError
  45. * @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
  46. * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException
  47. * @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException
  48. * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
  49. * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
  50. */
  51. public function processCreatePublish(FormActionEvent $event)
  52. {
  53. // Rely on Content Form Processor from ContentForms to avoid unncessary code duplication
  54. $this->innerContentFormProcessor->processPublish($event);
  55. /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */
  56. $content = $event->getPayload('content');
  57. $referrerLocation = $event->getOption('referrerLocation');
  58. $locationId = $referrerLocation ? $referrerLocation->id : $content->contentInfo->mainLocationId;
  59. // We only need to change the response so it's compatible with UDW
  60. $event->setResponse(
  61. new Response(
  62. $this->twig->render('@ibexadesign/ui/on_the_fly/content_create_response.html.twig', [
  63. 'locationId' => $locationId,
  64. ])
  65. )
  66. );
  67. }
  68. public function processEditPublish(FormActionEvent $event): void
  69. {
  70. // Rely on Content Form Processor from ContentForms to avoid unncessary code duplication
  71. $this->innerContentFormProcessor->processPublish($event);
  72. /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */
  73. $content = $event->getPayload('content');
  74. $referrerLocation = $event->getOption('referrerLocation');
  75. $locationId = $referrerLocation ? $referrerLocation->id : $content->contentInfo->mainLocationId;
  76. // We only need to change the response so it's compatible with UDW
  77. $event->setResponse(
  78. new Response(
  79. $this->twig->render('@ibexadesign/ui/on_the_fly/content_edit_response.html.twig', [
  80. 'locationId' => $locationId,
  81. ])
  82. )
  83. );
  84. }
  85. }
  86. class_alias(ContentOnTheFlyProcessor::class, 'EzSystems\EzPlatformAdminUi\Form\Processor\Content\ContentOnTheFlyProcessor');