You are here

public function TaxonomyTermProcessor::getEntityToImport in Content Synchronizer 8

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

Return the entity to import.

Parameters

array $data: The data to import.

\Drupal\Core\Entity\Entity $entityToImport: The existing entity to update.

Overrides EntityProcessorBase::getEntityToImport

File

src/Plugin/content_synchronizer/entity_processor/TaxonomyTermProcessor.php, line 55

Class

TaxonomyTermProcessor
Plugin implementation of the 'accordion' formatter.

Namespace

Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor

Code

public function getEntityToImport(array $data, Entity $existingEntity = NULL) {

  // Init tree process.
  $currentGid = $data[ExportEntityWriter::FIELD_GID];
  $defaultLanguageData = $this
    ->getDefaultLanguageData($data, FALSE);
  if (array_key_exists('parents', $defaultLanguageData)) {

    /** @var \Drupal\content_synchronizer\Processors\ImportProcessor $importProcessor */
    $importProcessor = ImportProcessor::getCurrentImportProcessor();

    /** @var \Drupal\content_synchronizer\Entity\ImportEntity $import */
    $import = $importProcessor
      ->getImport();
    foreach ($defaultLanguageData['parents'] as $parentGid) {

      // If the entity to reference is currently importing, then we cannot add it to the reference because it probably do not have an id yet.
      if ($import
        ->gidIsCurrentlyImporting($parentGid)) {
        $this
          ->addParentDependencie($data, $parentGid);
      }
      elseif ($import
        ->gidHasAlreadyBeenImported($parentGid)) {
        static::$treeBuffer[$currentGid][] = $this
          ->getGlobalReferenceManager()
          ->getEntityByGid($parentGid)
          ->id();
      }
      else {

        // Get the plugin of the entity :

        /** @var \Drupal\content_synchronizer\Processors\Entity\EntityProcessorBase $plugin */
        $plugin = $this
          ->getEntityProcessorManager()
          ->getInstanceByEntityType($this
          ->getGlobalReferenceManager()
          ->getEntityTypeFromGid($parentGid));
        if ($entityData = $import
          ->getEntityDataFromGid($parentGid)) {
          $parent = $plugin
            ->import($entityData);
          static::$treeBuffer[$currentGid][] = $parent
            ->id();
        }
      }
    }
  }
  return parent::getEntityToImport($data, $existingEntity);
}