Skip to content

Commit

Permalink
IBX-4486: Disabled Autosave feature for nodraft requests (#66)
Browse files Browse the repository at this point in the history
* IBX-4486: Disabled Autosave feature for `nodraft` requests

* IBX-4486: Removed unnecessary ternary operator

* IBX-4486: Changed option to `autosave_enabled`
  • Loading branch information
barw4 authored Feb 9, 2023
1 parent 4b00231 commit 39a1226
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
7 changes: 5 additions & 2 deletions src/lib/Content/View/Filter/ContentCreateViewFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
Expand Down Expand Up @@ -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,
]);
}
}
45 changes: 26 additions & 19 deletions src/lib/Form/Type/Content/ContentEditType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand Down

0 comments on commit 39a1226

Please sign in to comment.