function Exporter::exportFieldItem
Exports a single field item generically.
Any properties of the item that are explicitly marked non-exportable (which includes computed properties by default) will not be exported.
Field types that need special handling should provide a custom callback function to the exporter by subscribing to \Drupal\Core\DefaultContent\PreExportEvent.
Parameters
\Drupal\Core\Field\FieldItemInterface $item: The field item to export.
Return value
array The exported field values.
See also
\Drupal\Core\DefaultContent\PreExportEvent::setCallback()
2 calls to Exporter::exportFieldItem()
- Exporter::exportReference in core/
lib/ Drupal/ Core/ DefaultContent/ Exporter.php - Exports an entity reference field item.
- Exporter::exportTranslation in core/
lib/ Drupal/ Core/ DefaultContent/ Exporter.php - Exports a single translation of a content entity.
File
-
core/
lib/ Drupal/ Core/ DefaultContent/ Exporter.php, line 163
Class
- Exporter
- Handles exporting content entities.
Namespace
Drupal\Core\DefaultContentCode
private function exportFieldItem(FieldItemInterface $item) : array {
$custom_serialized = Importer::getCustomSerializedPropertyNames($item);
$values = [];
foreach ($item->getProperties() as $name => $property) {
$value = $property instanceof PrimitiveInterface ? $property->getCastedValue() : $property->getValue();
if (is_string($value) && in_array($name, $custom_serialized, TRUE)) {
$value = unserialize($value);
}
$values[$name] = $value;
}
return $values;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.