public function AccessStorage::getTidsByNid in Permissions by Term 8.2
Same name and namespace in other branches
- 8 src/Service/AccessStorage.php \Drupal\permissions_by_term\Service\AccessStorage::getTidsByNid()
Returns an array of term ids attached to the passed node id.
Parameters
$nid: Node id.
Return value
array Array of term ids
File
- src/
Service/ AccessStorage.php, line 561
Class
- AccessStorage
- Class AccessStorage.
Namespace
Drupal\permissions_by_term\ServiceCode
public function getTidsByNid($nid) : array {
$nidsToTidsPairs = [];
if ($this->keyValueCache
->has()) {
$nidsToTidsPairs = $this->keyValueCache
->get();
if (!empty($nidsToTidsPairs[$nid])) {
return $nidsToTidsPairs[$nid];
}
}
$tidsForNid = $this->database
->select('taxonomy_index')
->fields('taxonomy_index', [
'tid',
])
->condition('nid', $nid)
->execute()
->fetchCol();
if (!empty($tidsForNid)) {
$nidsToTidsPairs[$nid] = $tidsForNid;
$this->keyValueCache
->set($nidsToTidsPairs);
return $tidsForNid;
}
return [];
}