Skip to content

Commit

Permalink
EZEE-2132: User should be redirected to created Landing Page instead …
Browse files Browse the repository at this point in the history
…of it's parent
  • Loading branch information
Nattfarinn committed Dec 20, 2018
1 parent 4441b63 commit e16c9b9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
62 changes: 61 additions & 1 deletion lib/Event/FormActionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,26 @@ class FormActionEvent extends FormEvent
*/
private $response;

public function __construct(FormInterface $form, $data, $clickedButton, array $options = [])
/**
* Additional payload populated for event listeners next in priority.
*
* @var array
*/
private $payloads;

/**
* @param \Symfony\Component\Form\FormInterface $form
* @param $data
* @param $clickedButton
* @param array $options
* @param array $payloads
*/
public function __construct(FormInterface $form, $data, $clickedButton, array $options = [], array $payloads = [])
{
parent::__construct($form, $data);
$this->clickedButton = $clickedButton;
$this->options = $options;
$this->payloads = $payloads;
}

/**
Expand Down Expand Up @@ -103,4 +118,49 @@ public function hasResponse()
{
return $this->response !== null;
}

/**
* @return array
*/
public function getPayloads(): array
{
return $this->payloads;
}

/**
* @param array $payloads
*/
public function setPayloads(array $payloads): void
{
$this->payloads = $payloads;
}

/**
* @param string $name
*
* @return bool
*/
public function hasPayload(string $name): bool
{
return isset($this->payloads[$name]);
}

/**
* @param string $name
*
* @return mixed
*/
public function getPayload(string $name)
{
return $this->payloads[$name];
}

/**
* @param string $name
* @param mixed $payload
*/
public function setPayload(string $name, $payload): void
{
$this->payloads[$name] = $payload;
}
}
11 changes: 11 additions & 0 deletions lib/Form/Processor/ContentFormProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public function processSaveDraft(FormActionEvent $event)
$referrerLocation = $event->getOption('referrerLocation');
$contentLocation = $this->resolveLocation($draft, $referrerLocation, $data);

$event->setPayload('content', $draft);
$event->setPayload('is_new', $draft->contentInfo->isDraft());

$defaultUrl = $this->router->generate('ez_content_draft_edit', [
'contentId' => $draft->id,
'versionNo' => $draft->getVersionInfo()->versionNo,
Expand Down Expand Up @@ -117,6 +120,9 @@ public function processPublish(FormActionEvent $event)
$draft = $this->saveDraft($data, $form->getConfig()->getOption('languageCode'));
$content = $this->contentService->publishVersion($draft->versionInfo);

$event->setPayload('content', $content);
$event->setPayload('is_new', $draft->contentInfo->isDraft());

$redirectUrl = $form['redirectUrlAfterPublish']->getData() ?: $this->router->generate(
'_ezpublishLocation', [
'locationId' => $content->contentInfo->mainLocationId,
Expand Down Expand Up @@ -151,6 +157,8 @@ public function processCancel(FormActionEvent $event)
$contentInfo = $content->contentInfo;
$versionInfo = $data->contentDraft->getVersionInfo();

$event->setPayload('content', $content);

// if there is only one version you have to remove whole content instead of a version itself
if (1 === count($this->contentService->loadVersions($contentInfo))) {
$parentLocation = $this->locationService->loadParentLocationsForDraftContent($versionInfo)[0];
Expand Down Expand Up @@ -186,6 +194,9 @@ public function processCreateDraft(FormActionEvent $event)
$contentDraft = $this->contentService->createContentDraft($contentInfo, $versionInfo);
$referrerLocation = $event->getOption('referrerLocation');

$event->setPayload('content', $contentDraft);
$event->setPayload('is_new', $contentDraft->contentInfo->isDraft());

$contentEditUrl = $this->router->generate('ez_content_draft_edit', [
'contentId' => $contentDraft->id,
'versionNo' => $contentDraft->getVersionInfo()->versionNo,
Expand Down

0 comments on commit e16c9b9

Please sign in to comment.