protected function EntityParser::parseField in Entity Share 8.3
Parses a field or property of entity.
Parameters
string $item_key: The field key (machine name).
\Drupal\Core\Field\FieldItemListInterface $field_items: Field items.
array $remote_field_data: Used for remote entity: field data coming from JSON:API.
Return value
array Parsed data of a field, suitable for YAML parsing.
1 call to EntityParser::parseField()
- EntityParser::parseEntity in modules/
entity_share_diff/ src/ Service/ EntityParser.php - Parses an entity.
File
- modules/
entity_share_diff/ src/ Service/ EntityParser.php, line 290
Class
- EntityParser
- Entity parser.
Namespace
Drupal\entity_share_diff\ServiceCode
protected function parseField(string $item_key, FieldItemListInterface $field_items, array $remote_field_data = []) {
$build = [];
$field_type = $field_items
->getFieldDefinition()
->getType();
$plugin = $this->diffGeneratorManager
->createInstanceForFieldDefinition($field_type);
if ($plugin) {
// Pass the Remote config entity to the plugin.
$remote = $this
->getRemote();
if ($remote) {
$plugin
->setRemote($remote);
}
// Let the plugin build the value.
$build = $plugin
->build($field_items, $remote_field_data);
if (!empty($build)) {
// In case of a single field, flatten the array.
$cardinality = $field_items
->getFieldDefinition()
->getFieldStorageDefinition()
->getCardinality();
if ($cardinality == 1 && is_array($build)) {
$build = current($build);
}
}
}
return $build;
}