vendor/ibexa/admin-ui/src/lib/Form/Processor/ContentType/ContentTypeDiscardChangesFormProcessor.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\AdminUi\Form\Processor\ContentType;
  8. use Ibexa\ContentForms\Event\FormActionEvent;
  9. use Ibexa\Contracts\AdminUi\Event\FormEvents;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  13. /**
  14. * Listens for and processes RepositoryForm events.
  15. */
  16. class ContentTypeDiscardChangesFormProcessor implements EventSubscriberInterface
  17. {
  18. /** @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface */
  19. private $urlGenerator;
  20. /**
  21. * @param \Symfony\Component\Routing\Generator\UrlGeneratorInterface $urlGenerator
  22. */
  23. public function __construct(
  24. UrlGeneratorInterface $urlGenerator
  25. ) {
  26. $this->urlGenerator = $urlGenerator;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function getSubscribedEvents(): array
  32. {
  33. return [
  34. FormEvents::CONTENT_TYPE_REMOVE_DRAFT => ['processDiscardChanges', 10],
  35. ];
  36. }
  37. public function processDiscardChanges(FormActionEvent $event)
  38. {
  39. /** @var \Ibexa\AdminUi\Form\Data\ContentTypeData $data */
  40. $data = $event->getData();
  41. $contentTypeDraft = $data->contentTypeDraft;
  42. if (null === $contentTypeDraft || empty($contentTypeDraft->getContentTypeGroups())) {
  43. return;
  44. }
  45. /** @var $contentTypeGroup */
  46. $contentTypeGroup = $contentTypeDraft->getContentTypeGroups()[0];
  47. $event->setResponse(
  48. new RedirectResponse($this->urlGenerator->generate('ibexa.content_type_group.view', [
  49. 'contentTypeGroupId' => $contentTypeGroup->id,
  50. ]))
  51. );
  52. }
  53. }
  54. class_alias(ContentTypeDiscardChangesFormProcessor::class, 'EzSystems\EzPlatformAdminUi\Form\Processor\ContentType\ContentTypeDiscardChangesFormProcessor');