DynamicEntityReferenceFieldDiffParser.php in Entity Share 8.3
File
modules/entity_share_diff/src/Plugin/DiffGenerator/DynamicEntityReferenceFieldDiffParser.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_share_diff\Plugin\DiffGenerator;
use Drupal\Core\Field\FieldItemListInterface;
class DynamicEntityReferenceFieldDiffParser extends EntityReferenceFieldDiffParser {
public function build(FieldItemListInterface $field_items, array $remote_field_data = []) {
$result = [];
if (!$this
->getRemote()) {
foreach ($field_items as $field_key => $field_item) {
if (!$field_item
->isEmpty()) {
if ($field_item->entity) {
$entity = $field_item->entity;
$entity_type_id = $entity
->getEntityTypeId();
$result[$field_key] = $entity_type_id . ': ' . $entity
->uuid();
}
}
}
}
elseif (!empty($remote_field_data['data'])) {
foreach ($remote_field_data['data'] as $field_key => $remote_item_data) {
list($entity_type_id, ) = explode('--', $remote_item_data['type']);
$result[$field_key] = $entity_type_id . ': ' . $remote_item_data['id'];
}
}
return $result;
}
}