You are here

public function FileProcessor::getEntityToImport in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/content_synchronizer/entity_processor/FileProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor\FileProcessor::getEntityToImport()
  2. 3.x src/Plugin/content_synchronizer/entity_processor/FileProcessor.php \Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor\FileProcessor::getEntityToImport()

Return the entity to import.

Parameters

array $data: The data to import.

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

Return value

\Drupal\Core\Entity\Entity|\Drupal\Core\Entity\Entity\null|\Drupal\Core\Entity\EntityInterface The entity to import.

Overrides EntityProcessorBase::getEntityToImport

File

src/Plugin/content_synchronizer/entity_processor/FileProcessor.php, line 83

Class

FileProcessor
Plugin implementation of the 'accordion' formatter.

Namespace

Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor

Code

public function getEntityToImport(array $data, Entity $entityToImport = NULL) {
  if ($file = parent::getEntityToImport($data, $entityToImport)) {
    $assetsFile = $this
      ->getImportAssetsDir() . '/' . str_replace('://', '/', $file
      ->getFileUri());
    if (file_exists($assetsFile)) {
      if (strpos($file
        ->getFileUri(), '://')) {
        list($root, $destination) = explode('://', $file
          ->getFileUri());
        $root .= '://';
      }
      else {
        list($root, $destination) = [
          $file
            ->getFileUri(),
          '/',
        ];
      }
      $destination = $this
        ->createDirTreeForFileDest($destination, $root);
      if ($result = copy($assetsFile, $file
        ->getFileUri())) {
        return $file;
      }
    }
  }
  return NULL;
}