diff --git a/core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php b/core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php index b14ab55199dba68aa0c00605e976cfa9a8ff82f7..b93a4a9c1d9971dd8cdb3a209aaef9884bdea99e 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php @@ -331,6 +331,15 @@ public function testGroupByWithEmptyRelationships() { // Fourth result has no reference from EntityTestMul hence the output for // should be empty. $this->assertEqual('', $view->getStyle()->getField(3, 'name_2')); + + $fields = $view->field; + // Check getValue for reference with a value. The first 3 rows reference + // EntityTestMul, so have value 'name1'. + $this->assertEquals('name1', $fields['name_2']->getValue($view->result[0])); + $this->assertEquals('name1', $fields['name_2']->getValue($view->result[1])); + $this->assertEquals('name1', $fields['name_2']->getValue($view->result[2])); + // Ensure getValue works on empty references. + $this->assertNull($fields['name_2']->getValue($view->result[3])); } } diff --git a/core/modules/views/src/Plugin/views/field/EntityField.php b/core/modules/views/src/Plugin/views/field/EntityField.php index faf8da14b11f65e859c64b3ceccb45908f56919e..f26c188d3ba69abeb9c57dcf5bb28e922de6baad 100644 --- a/core/modules/views/src/Plugin/views/field/EntityField.php +++ b/core/modules/views/src/Plugin/views/field/EntityField.php @@ -1052,6 +1052,12 @@ protected function getTableMapping() { */ public function getValue(ResultRow $values, $field = NULL) { $entity = $this->getEntity($values); + + // Ensure the object is not NULL before attempting to translate it. + if ($entity === NULL) { + return NULL; + } + // Retrieve the translated object. $translated_entity = $this->getEntityFieldRenderer()->getEntityTranslation($entity, $values);