Skip to content

Commit

Permalink
EZP-29012: Invalid initial language code set after saving content dra…
Browse files Browse the repository at this point in the history
…ft (#228)
  • Loading branch information
webhdx authored Mar 26, 2018
1 parent 01560f2 commit beb382f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/Data/Mapper/ContentUpdateMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace EzSystems\RepositoryForms\Data\Mapper;

use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use eZ\Publish\API\Repository\Values\ValueObject;
use EzSystems\RepositoryForms\Data\Content\ContentUpdateData;
use EzSystems\RepositoryForms\Data\Content\FieldData;
Expand All @@ -17,19 +18,23 @@ class ContentUpdateMapper implements FormDataMapperInterface
/**
* Maps a ValueObject from eZ content repository to a data usable as underlying form data (e.g. create/update struct).
*
* @param ValueObject|\eZ\Publish\API\Repository\Values\Content\Content $contentDraft
* @param \eZ\Publish\API\Repository\Values\ValueObject|\eZ\Publish\API\Repository\Values\Content\Content $contentDraft
* @param array $params
*
* @return ContentUpdateData
* @return \EzSystems\RepositoryForms\Data\Content\ContentUpdateData
*/
public function mapToFormData(ValueObject $contentDraft, array $params = [])
{
$optionsResolver = new OptionsResolver();
$this->configureOptions($optionsResolver);

$params = $optionsResolver->resolve($params);
$languageCode = $params['languageCode'];

$data = new ContentUpdateData(['contentDraft' => $contentDraft]);
$fields = $contentDraft->getFieldsByLanguage($params['languageCode']);
$data->initialLanguageCode = $languageCode;

$fields = $contentDraft->getFieldsByLanguage($languageCode);
foreach ($params['contentType']->fieldDefinitions as $fieldDef) {
$field = $fields[$fieldDef->identifier];
$data->addFieldData(new FieldData([
Expand All @@ -46,6 +51,6 @@ private function configureOptions(OptionsResolver $optionsResolver)
{
$optionsResolver
->setRequired(['languageCode', 'contentType'])
->setAllowedTypes('contentType', '\eZ\Publish\API\Repository\Values\ContentType\ContentType');
->setAllowedTypes('contentType', ContentType::class);
}
}

0 comments on commit beb382f

Please sign in to comment.