You are here

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

Action on Entity import end.

Parameters

\Drupal\content_synchronizer\Events\ImportEvent $event: The event.

File

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

Class

TaxonomyTermProcessor
Plugin implementation of the 'accordion' formatter.

Namespace

Drupal\content_synchronizer\Plugin\content_synchronizer\entity_processor

Code

public function onImportedEntity(ImportEvent $event) {
  $gid = $event
    ->getGid();
  $entity = $event
    ->getEntity();

  // Add parent dependencies.
  if (array_key_exists($gid, static::$dependenciesBuffer)) {
    foreach (static::$dependenciesBuffer[$gid] as $childData) {
      $child = $this
        ->getGlobalReferenceManager()
        ->getEntityByGid($childData[ExportEntityWriter::FIELD_GID]);
      $alreadyAddedParents = $this
        ->getParentsTerms($child);
      $alreadyAddedParents[] = $entity
        ->id();
      $child
        ->set('parent', $alreadyAddedParents);
      $child
        ->save();
    }
  }

  // Save data.
  if (array_key_exists($gid, static::$treeBuffer)) {
    $entity
      ->set('parent', static::$treeBuffer[$gid]);
    $entity
      ->save();
  }
}