CoreFieldDiffParser.php in Entity Share 8.3
File
modules/entity_share_diff/src/Plugin/DiffGenerator/CoreFieldDiffParser.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_share_diff\Plugin\DiffGenerator;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\entity_share_diff\DiffGenerator\DiffGeneratorPluginBase;
class CoreFieldDiffParser extends DiffGeneratorPluginBase {
public function build(FieldItemListInterface $field_items, array $remote_field_data = []) {
$result = [];
$definition = $field_items
->getFieldDefinition();
$type = $definition
->getType();
foreach ($field_items as $field_key => $field_item) {
if (!$field_item
->isEmpty()) {
$values = $field_item
->getValue();
if (isset($values['value'])) {
$result[$field_key] = $values['value'];
if ($type == 'boolean') {
$result[$field_key] = $result[$field_key] == 1;
}
elseif (in_array($type, [
'float',
'integer',
'decimal',
'timestamp',
])) {
$result[$field_key] = (string) $result[$field_key];
}
}
}
}
return $result;
}
}