You are here

public function ReferenceMigrator::migrateReference in Term reference change 8

Updates the term reference on all entities from the source to the target.

Parameters

\Drupal\taxonomy\TermInterface $sourceTerm: The term to migrate away from.

\Drupal\taxonomy\TermInterface $targetTerm: The term to migrate to.

array[] $limit: List of entity ids keyed by their entity type to limit the migration to.

Throws

\Drupal\Core\Entity\EntityStorageException

File

src/ReferenceMigrator.php, line 43

Class

ReferenceMigrator
Migrates references from one taxonomy term to the other.

Namespace

Drupal\term_reference_change

Code

public function migrateReference(TermInterface $sourceTerm, TermInterface $targetTerm, array $limit = []) {
  $referenceFieldNames = $this
    ->findTermReferenceFieldNames(array_keys($limit));
  $referencingEntities = $this->referenceFinder
    ->findReferencesFor($sourceTerm);
  foreach ($referencingEntities as $entityType => $entities) {
    if ($this
      ->entityTypeShouldBeSkipped($entityType, $limit)) {
      continue;
    }
    foreach ($entities as $entity) {
      if ($this
        ->entityShouldBeSkipped($entity, $limit)) {
        continue;
      }
      $this
        ->updateReferencingEntity($sourceTerm, $targetTerm, $referenceFieldNames, $entity);
    }
  }
}