diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5e5e8b9b..acaf318b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1494,6 +1494,12 @@ parameters: count: 1 path: src/lib/FieldType/Mapper/AuthorFormMapper.php + - + message: '#^Property Ibexa\\ContentForms\\Data\\Content\\ContentUpdateData\:\:\$contentDraft \(Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Content\) in isset\(\) is not nullable\.$#' + identifier: isset.property + count: 1 + path: src/lib/FieldType/Mapper/AuthorFormMapper.php + - message: '#^Method Ibexa\\ContentForms\\FieldType\\Mapper\\BinaryFileFormMapper\:\:mapFieldValueForm\(\) has no return type specified\.$#' identifier: missingType.return diff --git a/src/contracts/Event/AutosaveEnabled.php b/src/contracts/Event/AutosaveEnabled.php new file mode 100644 index 00000000..ea26f3d9 --- /dev/null +++ b/src/contracts/Event/AutosaveEnabled.php @@ -0,0 +1,44 @@ +versionInfo = $versionInfo; + } + + public function getVersionInfo(): VersionInfo + { + return $this->versionInfo; + } + + public function isAutosaveEnabled(): bool + { + return $this->autosaveEnabled; + } + + public function enableAutosave(): void + { + $this->autosaveEnabled = true; + } + + public function disableAutosave(): void + { + $this->autosaveEnabled = false; + } +} diff --git a/src/lib/Content/View/Filter/ContentEditViewFilter.php b/src/lib/Content/View/Filter/ContentEditViewFilter.php index ab009b0a..d171ad7f 100644 --- a/src/lib/Content/View/Filter/ContentEditViewFilter.php +++ b/src/lib/Content/View/Filter/ContentEditViewFilter.php @@ -11,6 +11,7 @@ use Ibexa\ContentForms\Data\Content\ContentUpdateData; use Ibexa\ContentForms\Data\Mapper\ContentUpdateMapper; use Ibexa\ContentForms\Form\Type\Content\ContentEditType; +use Ibexa\Contracts\ContentForms\Event\AutosaveEnabled; use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\ContentTypeService; use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; @@ -24,41 +25,36 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; class ContentEditViewFilter implements EventSubscriberInterface { - /** @var \Ibexa\Contracts\Core\Repository\ContentService */ - private $contentService; + private ContentService $contentService; - /** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */ - private $contentTypeService; + private ContentTypeService $contentTypeService; - /** @var \Symfony\Component\Form\FormFactoryInterface */ - private $formFactory; + private FormFactoryInterface $formFactory; - /** @var \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface */ - private $languagePreferenceProvider; + private UserLanguagePreferenceProviderInterface $languagePreferenceProvider; private LocationService $locationService; - /** - * @param \Ibexa\Contracts\Core\Repository\ContentService $contentService - * @param \Ibexa\Contracts\Core\Repository\ContentTypeService $contentTypeService - * @param \Symfony\Component\Form\FormFactoryInterface $formFactory - * @param \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface $languagePreferenceProvider - */ + private EventDispatcherInterface $eventDispatcher; + public function __construct( ContentService $contentService, LocationService $locationService, ContentTypeService $contentTypeService, FormFactoryInterface $formFactory, - UserLanguagePreferenceProviderInterface $languagePreferenceProvider + UserLanguagePreferenceProviderInterface $languagePreferenceProvider, + EventDispatcherInterface $eventDispatcher ) { $this->contentService = $contentService; $this->contentTypeService = $contentTypeService; $this->formFactory = $formFactory; $this->languagePreferenceProvider = $languagePreferenceProvider; $this->locationService = $locationService; + $this->eventDispatcher = $eventDispatcher; } public static function getSubscribedEvents() @@ -111,11 +107,14 @@ public function handleContentEditForm(FilterViewBuilderParametersEvent $event) $contentType, $currentFields ); + + $autosaveEnabled = $this->eventDispatcher->dispatch(new AutosaveEnabled($contentDraft->getVersionInfo()))->isAutosaveEnabled(); $form = $this->resolveContentEditForm( $contentUpdate, $languageCode, $contentDraft, - $location ?? null + $location ?? null, + $autosaveEnabled ); $event->getParameters()->add([ @@ -153,7 +152,8 @@ private function resolveContentEditForm( ContentUpdateData $contentUpdate, string $languageCode, Content $content, - ?Location $location = null + ?Location $location = null, + bool $autosaveEnabled = true ): FormInterface { return $this->formFactory->create( ContentEditType::class, @@ -165,6 +165,7 @@ private function resolveContentEditForm( 'content' => $content, 'contentUpdateStruct' => $contentUpdate, 'drafts_enabled' => true, + 'autosave_enabled' => $autosaveEnabled, ] ); }