Skip to content

Commit

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

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

return $valueObject;
}
}
72 changes: 8 additions & 64 deletions lib/Form/Processor/ContentFormProcessor.php
Expand Up @@ -37,11 +37,6 @@ 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 @@ -52,10 +47,7 @@ public function __construct(
$this->router = $router;
}

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

/**
* @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
public function processSaveDraft(FormActionEvent $event)
{
/** @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 @@ -98,24 +78,13 @@ public function processSaveDraft(FormActionEvent $event): void
$event->setResponse(new RedirectResponse($formConfig->getAction() ?: $defaultUrl));
}

/**
* @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
public function processPublish(FormActionEvent $event)
{
/** @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 @@ -127,13 +96,7 @@ public function processPublish(FormActionEvent $event): void
$event->setResponse(new RedirectResponse($redirectUrl));
}

/**
* @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
public function processCancel(FormActionEvent $event)
{
/** @var \EzSystems\RepositoryForms\Data\Content\ContentCreateData|\EzSystems\RepositoryForms\Data\Content\ContentUpdateData $data */
$data = $event->getData();
Expand Down Expand Up @@ -170,13 +133,7 @@ public function processCancel(FormActionEvent $event): void
$event->setResponse(new RedirectResponse($url));
}

/**
* @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
public function processCreateDraft(FormActionEvent $event)
{
/** @var $createContentDraft \EzSystems\RepositoryForms\Data\Content\CreateContentDraftData */
$createContentDraft = $event->getData();
Expand All @@ -201,29 +158,19 @@ public function processCreateDraft(FormActionEvent $event): void
*
* @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): Content
private function saveDraft(ContentStruct $data, $languageCode)
{
$mainLanguageCode = $this->resolveMainLanguageCode($data);
foreach ($data->fieldsData as $fieldDefIdentifier => $fieldData) {
if ($mainLanguageCode != $languageCode && !$fieldData->fieldDefinition->isTranslatable) {
continue;
}

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

if ($data->isNew()) {
$contentDraft = $this->contentService->createContent($data, $data->getLocationStructs());
} else {
Expand Down Expand Up @@ -260,9 +207,6 @@ 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 2c45332

Please sign in to comment.