class FileFieldItemListProcessor in Content Synchronizer 8.2
Same name and namespace in other branches
- 8 src/Plugin/content_synchronizer/type_processor/FileFieldItemListProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\type_processor\FileFieldItemListProcessor
- 3.x src/Plugin/content_synchronizer/type_processor/FileFieldItemListProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\type_processor\FileFieldItemListProcessor
Plugin implementation For the type processor .
Plugin annotation
@TypeProcessor(
id = "content_synchronzer_file_field_item_list",
fieldType = "Drupal\file\Plugin\Field\FieldType\FileFieldItemList"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\content_synchronizer\Processors\Type\TypeProcessorBase implements TypeProcessorInterface
- class \Drupal\content_synchronizer\Plugin\content_synchronizer\type_processor\FileFieldItemListProcessor
- class \Drupal\content_synchronizer\Processors\Type\TypeProcessorBase implements TypeProcessorInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of FileFieldItemListProcessor
File
- src/
Plugin/ content_synchronizer/ type_processor/ FileFieldItemListProcessor.php, line 20
Namespace
Drupal\content_synchronizer\Plugin\content_synchronizer\type_processorView source
class FileFieldItemListProcessor extends TypeProcessorBase {
/**
* {@inheritdoc}
*/
public function getExportedData(TypedData $propertyData) {
$dataToExport = [];
// Get list of data :
/** @var \Drupal\file\Entity\FileItem $data */
foreach ($propertyData as $data) {
/** @var \Drupal\file\Entity\File $file */
$file = File::load($data->target_id);
$plugin = $this->pluginManager
->getInstanceByEntityType($file
->getEntityTypeId());
if ($fileGid = $plugin
->export($file)) {
$values = $data
->toArray();
unset($values['target_id']);
$values[ExportEntityWriter::FIELD_GID] = $fileGid;
$dataToExport[] = $values;
}
}
return $dataToExport;
}
/**
* {@inheritdoc}
*/
public function initImportedEntity(EntityInterface $entityToImport, $propertyId, array $data) {
/** @var \Drupal\Core\Entity\EntityReferenceFieldItemList $referenceField */
$referenceField = $entityToImport
->get($propertyId);
// Empty previous references.
while ($referenceField
->count() > 0) {
$referenceField
->removeItem(0);
}
foreach ($data[$propertyId] as $fileItem) {
$fileGID = $fileItem[ExportEntityWriter::FIELD_GID];
if ($entityData = ImportProcessor::getCurrentImportProcessor()
->getImport()
->getEntityDataFromGid($fileGID)) {
$plugin = $this->pluginManager
->getInstanceByEntityType($this->referenceManager
->getEntityTypeFromGid($fileGID));
if ($referencedEntity = $plugin
->import($entityData + $fileItem)) {
$fileItem['target_id'] = $referencedEntity
->id();
unset($fileItem[ExportEntityWriter::FIELD_GID]);
$referenceField
->appendItem($fileItem);
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FileFieldItemListProcessor:: |
public | function |
Get the data to export. Overrides TypeProcessorBase:: |
|
FileFieldItemListProcessor:: |
public | function |
Init the $propertyId value in the entity to import. Overrides TypeProcessorBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TypeProcessorBase:: |
protected | property | The entity processor plugin manager. | |
TypeProcessorBase:: |
protected | property | The global reference manager service. | |
TypeProcessorBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |