You are here

public function FileFieldItemListProcessor::initImportedEntity in Content Synchronizer 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/content_synchronizer/type_processor/FileFieldItemListProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\type_processor\FileFieldItemListProcessor::initImportedEntity()
  2. 3.x src/Plugin/content_synchronizer/type_processor/FileFieldItemListProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\type_processor\FileFieldItemListProcessor::initImportedEntity()

Init the $propertyId value in the entity to import.

Parameters

\Drupal\Core\Entity\EntityInterface $entityToImport: The entity to import.

string $propertyId: The property id.

array $data: The data to import.

Overrides TypeProcessorBase::initImportedEntity

File

src/Plugin/content_synchronizer/type_processor/FileFieldItemListProcessor.php, line 50

Class

FileFieldItemListProcessor
Plugin implementation For the type processor .

Namespace

Drupal\content_synchronizer\Plugin\content_synchronizer\type_processor

Code

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);
      }
    }
  }
}