Commit adb97dad authored by alexpott's avatar alexpott
Browse files

Issue #2327935 by Arla, Anushka-mp: Allow empty entity IDs in EntityResolvers

parent c791cc2d
......@@ -103,7 +103,8 @@ protected function constructValue($data, $context) {
$field_item = $context['target_instance'];
$field_definition = $field_item->getFieldDefinition();
$target_type = $field_definition->getSetting('target_type');
if ($id = $this->entityResolver->resolve($this, $data, $target_type)) {
$id = $this->entityResolver->resolve($this, $data, $target_type);
if (isset($id)) {
return array('target_id' => $id);
}
return NULL;
......
......@@ -43,7 +43,8 @@ public function addResolver(EntityResolverInterface $resolver) {
*/
public function resolve(NormalizerInterface $normalizer, $data, $entity_type) {
foreach ($this->resolvers as $resolver) {
if ($resolved = $resolver->resolve($normalizer, $data, $entity_type)) {
$resolved = $resolver->resolve($normalizer, $data, $entity_type);
if (isset($resolved)) {
return $resolved;
}
}
......
......@@ -110,6 +110,23 @@ public function testResolverWithLastResolved() {
$this->assertSame(10, $resolver->resolve($this->testNormalizer, $this->testData, $this->testEntityType));
}
/**
* Test the resolve method where one resolver returns 0.
*
* @covers ::__construct
* @covers ::resolve
*/
public function testResolverWithResolvedToZero() {
$resolvers = array(
$this->createEntityResolverMock(0),
$this->createEntityResolverMock(NULL, FALSE),
);
$resolver = new ChainEntityResolver($resolvers);
$this->assertSame(0, $resolver->resolve($this->testNormalizer, $this->testData, $this->testEntityType));
}
/**
* Creates a mock entity resolver.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment