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 f2f7c88
Show file tree
Hide file tree
Showing 2 changed files with 75 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;
}
}
14 changes: 14 additions & 0 deletions lib/Form/Processor/ContentFormProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public function processPublish(FormActionEvent $event)
$draft = $this->saveDraft($data, $form->getConfig()->getOption('languageCode'));
$content = $this->contentService->publishVersion($draft->versionInfo);

$event->setPayload('contentDraft', $draft);
$event->setPayload('versionInfo', $draft->getVersionInfo());
$event->setPayload('contentInfo', $draft->getVersionInfo()->getContentInfo());

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

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

// 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];
$redirectionLocationId = $parentLocation->id;
$this->contentService->deleteContent($contentInfo);

$event->setPayload('parentLocation', $parentLocation);
} else {
$redirectionLocationId = $contentInfo->mainLocationId;
$this->contentService->deleteVersion($versionInfo);
Expand Down Expand Up @@ -186,6 +196,10 @@ public function processCreateDraft(FormActionEvent $event)
$contentDraft = $this->contentService->createContentDraft($contentInfo, $versionInfo);
$referrerLocation = $event->getOption('referrerLocation');

$event->setPayload('contentDraft', $contentDraft);
$event->setPayload('contentInfo', $contentInfo);
$event->setPayload('versionInfo', $versionInfo);

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

0 comments on commit f2f7c88

Please sign in to comment.