From cfb1fce8338cc1bfa61cb3109c3a0fa28ae76cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edi=20Modri=C4=87?= Date: Mon, 4 May 2020 10:08:08 +0200 Subject: [PATCH] Support using core RelationList value in the field type override --- bundle/Core/FieldType/RelationList/Type.php | 30 ++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/bundle/Core/FieldType/RelationList/Type.php b/bundle/Core/FieldType/RelationList/Type.php index f9aafb90..1a7d8e14 100644 --- a/bundle/Core/FieldType/RelationList/Type.php +++ b/bundle/Core/FieldType/RelationList/Type.php @@ -6,6 +6,7 @@ use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType; use eZ\Publish\Core\FieldType\RelationList\Type as BaseRelationListType; +use eZ\Publish\Core\FieldType\RelationList\Value as BaseRelationListValue; use eZ\Publish\Core\FieldType\Value as BaseValue; use eZ\Publish\SPI\FieldType\Value as SPIValue; @@ -63,7 +64,34 @@ protected function createValueFromInput($inputValue) return new Value($destinationContentIds, $destinationLocationIds); } - return parent::createValueFromInput($inputValue); + $parentValue = parent::createValueFromInput($inputValue); + + if ( + $parentValue instanceof BaseRelationListValue && + !$parentValue instanceof Value + ) { + return new Value($parentValue->destinationContentIds); + } + + return $parentValue; + } + + protected static function checkValueType($value): void + { + if ($value instanceof BaseRelationListValue) { + // Includes overridden type too + return; + } + + throw new InvalidArgumentType( + '$value', + sprintf( + '"%s" or "%s"', + BaseRelationListValue::class, + Value::class + ), + $value + ); } protected function checkValueStructure(BaseValue $value): void