public static function WorkbenchAccessManager::checkTree in Workbench Access 8
Checks that an entity belongs to a user section or its children.
Parameters
\Drupal\workbench_access\Entity\AccessSchemeInterface $scheme: Access scheme.
array $entity_sections: The section assignments for the entity. An array of section ids.
array $user_sections: The section assignments for the user. An array of section ids.
return boolean.
Overrides WorkbenchAccessManagerInterface::checkTree
4 calls to WorkbenchAccessManager::checkTree()
- AccessControlHierarchyBase::checkEntityAccess in src/
AccessControlHierarchyBase.php - Responds to request for node access.
- Menu::alterForm in src/
Plugin/ AccessControlHierarchy/ Menu.php - Alters the selection options provided for an access control field.
- Taxonomy::alterForm in src/
Plugin/ AccessControlHierarchy/ Taxonomy.php - Alters the selection options provided for an access control field.
- TaxonomyHierarchySelection::getReferenceableEntities in src/
Plugin/ EntityReferenceSelection/ TaxonomyHierarchySelection.php - Gets the list of referenceable entities.
File
- src/
WorkbenchAccessManager.php, line 90
Class
- WorkbenchAccessManager
- Defines a class for interacting with content and fields.
Namespace
Drupal\workbench_accessCode
public static function checkTree(AccessSchemeInterface $scheme, array $entity_sections, array $user_sections) {
$list = array_flip($user_sections);
foreach ($entity_sections as $section) {
// Simple check first: is there an exact match?
if (isset($list[$section])) {
return TRUE;
}
// Check for section on the tree.
// Static cache to prevent looping on each request.
if (!isset(self::$tree[$scheme
->id()])) {
self::$tree[$scheme
->id()] = $scheme
->getAccessScheme()
->getTree();
}
foreach (self::$tree[$scheme
->id()] as $id => $info) {
if (isset($list[$section]) && isset($info[$section])) {
return TRUE;
}
// Recursive check for parents.
if (!empty($info[$section]['parents'])) {
$parents = array_flip($info[$section]['parents']);
// Check for parents.
foreach ($list as $uid => $data) {
if (isset($parents[$uid])) {
return TRUE;
}
}
}
}
}
return FALSE;
}