Skip to content

Commit

Permalink
Merge branch '2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikadamczyk committed Jul 25, 2018
2 parents 330aa04 + 2535397 commit 4042d97
Show file tree
Hide file tree
Showing 3 changed files with 336 additions and 16 deletions.
9 changes: 1 addition & 8 deletions lib/FieldType/DataTransformer/BinaryFileValueTransformer.php
Expand Up @@ -43,13 +43,6 @@ public function transform($value)
*/
public function reverseTransform($value)
{
/** @var Value $valueObject */
$valueObject = $this->getReverseTransformedValue($value);

if ($this->fieldType->isEmptyValue($valueObject)) {
return $valueObject;
}

return $valueObject;
return $this->getReverseTransformedValue($value);
}
}
72 changes: 64 additions & 8 deletions lib/Form/Processor/ContentFormProcessor.php
Expand Up @@ -37,6 +37,11 @@ class ContentFormProcessor implements EventSubscriberInterface
/** @var \Symfony\Component\Routing\RouterInterface */
private $router;

/**
* @param \eZ\Publish\API\Repository\ContentService $contentService
* @param \eZ\Publish\API\Repository\LocationService $locationService
* @param \Symfony\Component\Routing\RouterInterface $router
*/
public function __construct(
ContentService $contentService,
LocationService $locationService,
Expand All @@ -47,7 +52,10 @@ public function __construct(
$this->router = $router;
}

public static function getSubscribedEvents()
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
RepositoryFormEvents::CONTENT_PUBLISH => ['processPublish', 10],
Expand All @@ -57,14 +65,26 @@ public static function getSubscribedEvents()
];
}

public function processSaveDraft(FormActionEvent $event)
/**
* @param \EzSystems\RepositoryForms\Event\FormActionEvent $event
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
*/
public function processSaveDraft(FormActionEvent $event): void
{
/** @var \EzSystems\RepositoryForms\Data\Content\ContentCreateData|\EzSystems\RepositoryForms\Data\Content\ContentUpdateData $data */
$data = $event->getData();
$form = $event->getForm();

$formConfig = $form->getConfig();
$languageCode = $formConfig->getOption('languageCode');

$draft = $this->saveDraft($data, $languageCode);
$referrerLocation = $event->getOption('referrerLocation');
$contentLocation = $this->resolveLocation($draft, $referrerLocation, $data);
Expand All @@ -78,13 +98,24 @@ public function processSaveDraft(FormActionEvent $event)
$event->setResponse(new RedirectResponse($formConfig->getAction() ?: $defaultUrl));
}

public function processPublish(FormActionEvent $event)
/**
* @param \EzSystems\RepositoryForms\Event\FormActionEvent $event
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
*/
public function processPublish(FormActionEvent $event): void
{
/** @var \EzSystems\RepositoryForms\Data\Content\ContentCreateData|\EzSystems\RepositoryForms\Data\Content\ContentUpdateData $data */
$data = $event->getData();
$form = $event->getForm();

$draft = $this->saveDraft($data, $form->getConfig()->getOption('languageCode'));

$content = $this->contentService->publishVersion($draft->versionInfo);

// Redirect to the provided URL. Defaults to URLAlias of the published content.
Expand All @@ -96,7 +127,13 @@ public function processPublish(FormActionEvent $event)
$event->setResponse(new RedirectResponse($redirectUrl));
}

public function processCancel(FormActionEvent $event)
/**
* @param \EzSystems\RepositoryForms\Event\FormActionEvent $event
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function processCancel(FormActionEvent $event): void
{
/** @var \EzSystems\RepositoryForms\Data\Content\ContentCreateData|\EzSystems\RepositoryForms\Data\Content\ContentUpdateData $data */
$data = $event->getData();
Expand Down Expand Up @@ -133,7 +170,13 @@ public function processCancel(FormActionEvent $event)
$event->setResponse(new RedirectResponse($url));
}

public function processCreateDraft(FormActionEvent $event)
/**
* @param \EzSystems\RepositoryForms\Event\FormActionEvent $event
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function processCreateDraft(FormActionEvent $event): void
{
/** @var $createContentDraft \EzSystems\RepositoryForms\Data\Content\CreateContentDraftData */
$createContentDraft = $event->getData();
Expand All @@ -158,19 +201,29 @@ public function processCreateDraft(FormActionEvent $event)
*
* @param ContentStruct|\EzSystems\RepositoryForms\Data\Content\ContentCreateData|\EzSystems\RepositoryForms\Data\Content\ContentUpdateData $data
* @param $languageCode
*
* @return \eZ\Publish\API\Repository\Values\Content\Content
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
*/
private function saveDraft(ContentStruct $data, $languageCode)
private function saveDraft(ContentStruct $data, $languageCode): Content
{
$mainLanguageCode = $this->resolveMainLanguageCode($data);
foreach ($data->fieldsData as $fieldDefIdentifier => $fieldData) {
if ($mainLanguageCode != $languageCode && !$fieldData->fieldDefinition->isTranslatable) {
continue;
}

$data->setField($fieldDefIdentifier, $fieldData->value, $languageCode);
/* comparing value, not references */
if ($fieldData->value != $fieldData->field->value) {
$data->setField($fieldDefIdentifier, $fieldData->value, $languageCode);
}
}

if ($data->isNew()) {
$contentDraft = $this->contentService->createContent($data, $data->getLocationStructs());
} else {
Expand Down Expand Up @@ -207,6 +260,9 @@ private function resolveMainLanguageCode($data): string
* @param \EzSystems\RepositoryForms\Data\NewnessCheckable $data
*
* @return \eZ\Publish\API\Repository\Values\Content\Location|null
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
private function resolveLocation(Content $content, ?Location $referrerLocation, NewnessCheckable $data): ?Location
{
Expand Down

0 comments on commit 4042d97

Please sign in to comment.