You are here

public function FileFieldItemListProcessor::getExportedData 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::getExportedData()
  2. 3.x src/Plugin/content_synchronizer/type_processor/FileFieldItemListProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\type_processor\FileFieldItemListProcessor::getExportedData()

Get the data to export.

Parameters

\Drupal\Core\TypedData\TypedData $propertyData: The property data to export.

Return value

array The exported data.

Overrides TypeProcessorBase::getExportedData

File

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

Class

FileFieldItemListProcessor
Plugin implementation For the type processor .

Namespace

Drupal\content_synchronizer\Plugin\content_synchronizer\type_processor

Code

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