public function TaxonomyTermMatch::onLoadLocalEntity in Acquia Content Hub 8.2
Load local terms with the same name, vocabulary and relative parent.
Parameters
\Drupal\acquia_contenthub\Event\LoadLocalEntityEvent $event: Data tamper event.
Throws
\Exception
File
- modules/
acquia_contenthub_subscriber/ src/ EventSubscriber/ LoadLocalEntity/ TaxonomyTermMatch.php, line 42
Class
- TaxonomyTermMatch
- Class TaxonomyTermMatch.
Namespace
Drupal\acquia_contenthub_subscriber\EventSubscriber\LoadLocalEntityCode
public function onLoadLocalEntity(LoadLocalEntityEvent $event) {
$object = $event
->getCdf();
if (!$this
->isSupported($object)) {
return;
}
if ($event
->getStack()
->hasDependency($object
->getUuid())) {
return;
}
$vocabulary_name = $this
->getVocabularyName($object);
$storage = $this
->getVocabularyStorage();
// If the vocabulary doesn't exist, the term couldn't possibly exist.
if (!($vocabulary = $storage
->load($vocabulary_name))) {
return;
}
$parents = $this
->extractParentAttribute($object);
$label = $this
->getTermLabel($object);
foreach ($parents as $parent) {
$term = $this
->findTaxonomyTerm($label, $vocabulary_name, $parent, $event
->getStack());
if (empty($term)) {
continue;
}
$this
->addDependency($event, $object, $term);
$event
->setEntity($term);
}
}