public function NodeOrderManager::canBeOrdered in Node Order 8
Determine if a given node can be ordered in any vocabularies.
Parameters
\Drupal\node\NodeInterface $node: The node object.
Return value
bool Returns TRUE if the node has terms in any orderable vocabulary.
Overrides NodeOrderManagerInterface::canBeOrdered
File
- src/
NodeOrderManager.php, line 223
Class
- NodeOrderManager
- Defines a service that creates & manages node ordering within taxonomy terms.
Namespace
Drupal\nodeorderCode
public function canBeOrdered(NodeInterface $node) {
$cid = 'nodeorder:can_be_ordered:' . $node
->getType();
if (($cache = $this->cache
->get($cid)) && !empty($cache->data)) {
return $cache->data;
}
else {
$can_be_ordered = FALSE;
$nodeorder_vocabularies = [];
foreach ($node
->getFieldDefinitions() as $field) {
if ($field
->getType() != 'entity_reference' || $field
->getSetting('target_type') != 'taxonomy_term') {
continue;
}
foreach ($field
->getSetting('handler_settings')['target_bundles'] as $vocabulary) {
$nodeorder_vocabularies[] = $vocabulary;
}
}
foreach ($nodeorder_vocabularies as $vid) {
if (Vocabulary::load($vid)) {
$can_be_ordered = TRUE;
}
}
// Permanently cache the value for easy reuse.
$this->cache
->set($cid, $can_be_ordered, Cache::PERMANENT, [
'nodeorder',
]);
return $can_be_ordered;
}
}