diff --git a/src/lib/Content/View/Filter/ContentCreateViewFilter.php b/src/lib/Content/View/Filter/ContentCreateViewFilter.php index c2370069..99b2c94f 100644 --- a/src/lib/Content/View/Filter/ContentCreateViewFilter.php +++ b/src/lib/Content/View/Filter/ContentCreateViewFilter.php @@ -86,7 +86,8 @@ public function handleContentCreateForm(FilterViewBuilderParametersEvent $event) $contentCreateData = $this->resolveContentCreateData($contentType, $location, $languageCode); $form = $this->resolveContentCreateForm( $contentCreateData, - $languageCode + $languageCode, + false ); $event->getParameters()->add(['form' => $form->handleRequest($request)]); @@ -123,13 +124,15 @@ private function resolveContentCreateData( */ private function resolveContentCreateForm( ContentCreateData $contentCreateData, - string $languageCode + string $languageCode, + bool $autosaveEnabled = true ): FormInterface { return $this->formFactory->create(ContentEditType::class, $contentCreateData, [ 'languageCode' => $languageCode, 'mainLanguageCode' => $languageCode, 'contentCreateStruct' => $contentCreateData, 'drafts_enabled' => true, + 'autosave_enabled' => $autosaveEnabled, ]); } } diff --git a/src/lib/Form/Type/Content/ContentEditType.php b/src/lib/Form/Type/Content/ContentEditType.php index a5950cf9..5431e5f3 100644 --- a/src/lib/Form/Type/Content/ContentEditType.php +++ b/src/lib/Form/Type/Content/ContentEditType.php @@ -43,26 +43,32 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('publish', SubmitType::class, ['label' => 'Publish']); - if ($options['drafts_enabled']) { - $builder - ->add('saveDraft', SubmitType::class, [ - 'label' => /** @Desc("Save draft") */ 'save_draft', - 'attr' => ['formnovalidate' => 'formnovalidate'], - ]) - ->add('cancel', SubmitType::class, [ - 'label' => /** @Desc("Cancel") */ 'cancel', - 'attr' => ['formnovalidate' => 'formnovalidate'], - ]) - ->add('autosave', SubmitType::class, [ - 'label' => /** @Desc("Autosave") */ 'autosave', - 'attr' => [ - 'hidden' => true, - 'formnovalidate' => 'formnovalidate', - ], - 'translation_domain' => 'content_edit', - ]); - $builder->addEventSubscriber(new SuppressValidationSubscriber()); + if (!$options['drafts_enabled']) { + return; } + + $builder + ->add('saveDraft', SubmitType::class, [ + 'label' => /** @Desc("Save draft") */ 'save_draft', + 'attr' => ['formnovalidate' => 'formnovalidate'], + ]) + ->add('cancel', SubmitType::class, [ + 'label' => /** @Desc("Cancel") */ 'cancel', + 'attr' => ['formnovalidate' => 'formnovalidate'], + ]); + + if ($options['autosave_enabled']) { + $builder->add('autosave', SubmitType::class, [ + 'label' => /** @Desc("Autosave") */ 'autosave', + 'attr' => [ + 'hidden' => true, + 'formnovalidate' => 'formnovalidate', + ], + 'translation_domain' => 'content_edit', + ]); + } + + $builder->addEventSubscriber(new SuppressValidationSubscriber()); } public function configureOptions(OptionsResolver $resolver) @@ -73,6 +79,7 @@ public function configureOptions(OptionsResolver $resolver) 'contentCreateStruct' => null, 'contentUpdateStruct' => null, 'drafts_enabled' => false, + 'autosave_enabled' => true, 'data_class' => ContentStruct::class, 'translation_domain' => 'ezplatform_content_forms_content', 'intent' => 'update',