vendor/ibexa/admin-ui/src/lib/Form/Processor/Content/AutosaveProcessor.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\AdminUi\Form\Processor\Content;
  8. use Ibexa\ContentForms\Event\FormActionEvent;
  9. use Ibexa\ContentForms\Form\Processor\ContentFormProcessor;
  10. use Ibexa\Contracts\AdminUi\Autosave\AutosaveServiceInterface;
  11. use Ibexa\Contracts\AdminUi\Event\AutosaveEvents;
  12. use Ibexa\Contracts\Core\Repository\Exceptions\Exception as APIException;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\HttpFoundation\Response;
  15. class AutosaveProcessor implements EventSubscriberInterface
  16. {
  17. private AutosaveServiceInterface $autosaveService;
  18. private ContentFormProcessor $innerContentFormProcessor;
  19. public function __construct(
  20. AutosaveServiceInterface $autosaveService,
  21. ContentFormProcessor $innerContentFormProcessor
  22. ) {
  23. $this->autosaveService = $autosaveService;
  24. $this->innerContentFormProcessor = $innerContentFormProcessor;
  25. }
  26. public static function getSubscribedEvents(): array
  27. {
  28. return [
  29. AutosaveEvents::CONTENT_AUTOSAVE => ['processAutosave', 10],
  30. ];
  31. }
  32. public function processAutosave(FormActionEvent $event): void
  33. {
  34. try {
  35. $this->autosaveService->setInProgress(true);
  36. $this->innerContentFormProcessor->processSaveDraft($event);
  37. $statusCode = Response::HTTP_OK;
  38. } catch (APIException $exception) {
  39. $statusCode = Response::HTTP_BAD_REQUEST;
  40. } finally {
  41. $this->autosaveService->setInProgress(false);
  42. }
  43. $event->setResponse(
  44. // Response content is irrelevant as it will be overwritten by ViewRenderer anyway
  45. new Response(null, $statusCode)
  46. );
  47. }
  48. }
  49. class_alias(AutosaveProcessor::class, 'EzSystems\EzPlatformAdminUi\Form\Processor\Content\AutosaveProcessor');