Skip to content

Commit

Permalink
Support using core RelationList value in the field type override
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed May 4, 2020
1 parent c3730b8 commit cfb1fce
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion bundle/Core/FieldType/RelationList/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cfb1fce

Please sign in to comment.