public function NodeOrderManager::getOrderableTids in Node Order 8
Get a list of term IDs on a node that can be ordered.
This method uses the `taxonomy_index` table to determine which terms on a node are orderable.
Parameters
\Drupal\node\NodeInterface $node: The node to check for orderable term IDs.
bool $reset: Flag to reset cached data.
Return value
int[] Returns an array of the node's tids that are in orderable vocabularies.
Overrides NodeOrderManagerInterface::getOrderableTids
See also
self::getOrderableTidsFromNode()
File
- src/
NodeOrderManager.php, line 259
Class
- NodeOrderManager
- Defines a service that creates & manages node ordering within taxonomy terms.
Namespace
Drupal\nodeorderCode
public function getOrderableTids(NodeInterface $node, $reset = FALSE) {
$cid = 'nodeorder:orderable_tids:' . $node
->getType();
if (!$reset && ($cache = $this->cache
->get($cid)) && !empty($cache->data)) {
$tids = $cache->data;
}
else {
$vocabularies = [];
foreach ($this->configFactory
->get('nodeorder.settings')
->get('vocabularies') as $vid => $orderable) {
if ($orderable) {
$vocabularies[] = $vid;
}
}
if (!empty($vocabularies)) {
$query = \Drupal::database()
->select('taxonomy_index', 'i');
$query
->join('taxonomy_term_data', 'd', 'd.tid = i.tid');
$query
->condition('i.nid', $node
->id())
->condition('d.vid', $vocabularies, 'IN')
->fields('i', [
'tid',
]);
$tids = $query
->execute()
->fetchCol('tid');
}
else {
$tids = [];
}
// Permanently cache the value for easy reuse.
// @todo this needs to properly clear when node is edited.
$this->cache
->set($cid, $tids, Cache::PERMANENT, [
'nodeorder',
]);
}
return $tids;
}