public function MediaDirectoriesUiHelper::termIsAnAnchestorOf in Media Directories 2.x
Checks if a term belongs to the specified anchestor.
Parameters
\Drupal\taxonomy\entity\Term $term: The term to check against.
\Drupal\taxonomy\entity\Term $anchestor: The anchestor to search for.
Return value
boolean Wheater the provided anchestor is an anchestor.
File
- modules/
media_directories_ui/ src/ MediaDirectoriesUiHelper.php, line 127
Class
- MediaDirectoriesUiHelper
- Media directories UI helper service.
Namespace
Drupal\media_directories_uiCode
public function termIsAnAnchestorOf(Term $term, Term $anchestor) {
if ($term === NULL || $anchestor === NULL) {
return FALSE;
}
/** @var \Drupal\taxonomy\Entity\Term[] $types */
$anchestors = $this->entityTypeManager
->getStorage('taxonomy_term')
->loadAllParents($term
->id());
foreach ($anchestors as $one_of_the_anchestors) {
if ($anchestor
->id() == $one_of_the_anchestors
->id()) {
return TRUE;
}
}
return FALSE;
}