public function AccessStorage::getTidsByNid in Permissions by Term 8
Same name and namespace in other branches
- 8.2 src/Service/AccessStorage.php \Drupal\permissions_by_term\Service\AccessStorage::getTidsByNid()
Parameters
$nid:
Return value
array
File
- src/
Service/ AccessStorage.php, line 555
Class
- AccessStorage
- Class AccessStorage.
Namespace
Drupal\permissions_by_term\ServiceCode
public function getTidsByNid($nid) {
$node = \Drupal::entityTypeManager()
->getStorage('node')
->load($nid);
$tids = [];
foreach ($node
->getFields() as $field) {
if ($field
->getFieldDefinition()
->getType() == 'entity_reference' && $field
->getFieldDefinition()
->getSetting('target_type') == 'taxonomy_term') {
$aReferencedTaxonomyTerms = $field
->getValue();
if (!empty($aReferencedTaxonomyTerms)) {
foreach ($aReferencedTaxonomyTerms as $aReferencedTerm) {
if (isset($aReferencedTerm['target_id'])) {
$tids[] = $aReferencedTerm['target_id'];
}
}
}
}
}
return $tids;
}