Skip to content

Commit

Permalink
EZP-31574: Added posibility to save and preview incomplete draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattfarinn committed May 18, 2020
1 parent 4bfac53 commit d645963
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/lib/Form/Processor/PreviewFormProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function processPreview(FormActionEvent $event): void
$referrerLocation = $event->getOption('referrerLocation');

try {
$contentDraft = $this->saveDraft($data, $languageCode);
$contentDraft = $this->saveDraft($data, $languageCode, false);
$contentLocation = $this->resolveLocation($contentDraft, $referrerLocation, $data);
$url = $this->urlGenerator->generate('ezplatform.content.preview', [
'locationId' => null !== $contentLocation ? $contentLocation->id : null,
Expand Down Expand Up @@ -130,7 +130,7 @@ public function processPreview(FormActionEvent $event): void
* @throws ContentValidationException
* @throws ContentFieldValidationException
*/
private function saveDraft(ContentStruct $data, string $languageCode): Content
private function saveDraft(ContentStruct $data, string $languageCode, bool $validate): Content
{
$mainLanguageCode = $this->resolveMainLanguageCode($data);
foreach ($data->fieldsData as $fieldDefIdentifier => $fieldData) {
Expand All @@ -142,9 +142,9 @@ private function saveDraft(ContentStruct $data, string $languageCode): Content
}

if ($data->isNew()) {
$contentDraft = $this->contentService->createContent($data, $data->getLocationStructs());
$contentDraft = $this->contentService->createContent($data, $data->getLocationStructs(), $validate);
} else {
$contentDraft = $this->contentService->updateContent($data->contentDraft->getVersionInfo(), $data);
$contentDraft = $this->contentService->updateContent($data->contentDraft->getVersionInfo(), $data, $validate);
}

return $contentDraft;
Expand Down
15 changes: 14 additions & 1 deletion src/lib/Form/Type/Extension/Content/ContentEditTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

use EzSystems\EzPlatformContentForms\Form\Type\Content\ContentEditType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Event\PostSubmitEvent;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvents;

/**
* Extends Content Edit form with additional fields.
Expand All @@ -26,9 +28,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('preview', SubmitType::class, [
'label' => /** @Desc("Preview") */ 'preview',
'attr' => ['hidden' => true],
'attr' => [
'hidden' => true,
'formnovalidate' => 'formnovalidate',
],
'translation_domain' => 'content_preview',
]);

$builder->addEventListener(FormEvents::POST_SUBMIT, static function (PostSubmitEvent $event): void {
$form = $event->getForm();

if ($form->get('preview')->isClicked()) {
$event->stopPropagation();
}
}, 900);
}

public static function getExtendedTypes(): iterable
Expand Down

0 comments on commit d645963

Please sign in to comment.