DynamicEntityReferenceFieldBuilder.php in Dynamic Entity Reference 8.2
File
src/Plugin/diff/Field/DynamicEntityReferenceFieldBuilder.php
View source
<?php
namespace Drupal\dynamic_entity_reference\Plugin\diff\Field;
use Drupal\Core\Field\FieldItemListInterface;
use const Drupal\diff\Plugin\diff\Field\COMPARE_ENTITY_REFERENCE_LABEL;
use Drupal\diff\Plugin\diff\Field\EntityReferenceFieldBuilder;
class DynamicEntityReferenceFieldBuilder extends EntityReferenceFieldBuilder {
public function build(FieldItemListInterface $field_items) {
$result = [];
foreach ($field_items as $field_key => $field_item) {
if (!$field_item
->isEmpty()) {
if ($field_item->entity) {
$entity = $field_item->entity;
if ($this->configuration['compare_entity_reference'] == COMPARE_ENTITY_REFERENCE_LABEL) {
$result[$field_key][] = $this
->t('@id (@type)', [
'@id' => $entity
->label(),
'@type' => $entity
->getEntityType()
->getLabel(),
]);
}
else {
$result[$field_key][] = $this
->t('Entity ID: @id (@type)', [
'@id' => $entity
->id(),
'@type' => $entity
->getEntityType()
->getLabel(),
]);
}
}
}
}
return $result;
}
}