You are here

private function WorkbenchAccessTokens::getNodeSectionNames in Workbench Access 8

Generates an array of section names for a given node.

Parameters

\Drupal\node\NodeInterface $node: The user account.

\Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata: The cache metadata.

Return value

array An array of section names.

1 call to WorkbenchAccessTokens::getNodeSectionNames()
WorkbenchAccessTokens::getTokens in src/WorkbenchAccessTokens.php
Implements hook_tokens().

File

src/WorkbenchAccessTokens.php, line 203

Class

WorkbenchAccessTokens
Token handler for Workbench Access.

Namespace

Drupal\workbench_access

Code

private function getNodeSectionNames(NodeInterface $node, BubbleableMetadata $bubbleable_metadata) {
  $schemes = $this->entityTypeManager
    ->getStorage('access_scheme')
    ->loadMultiple();
  return array_reduce($schemes, function (array $carry, AccessSchemeInterface $scheme) use ($node, $bubbleable_metadata) {
    if (!($sections = $scheme
      ->getAccessScheme()
      ->getEntityValues($node))) {
      return $carry;
    }
    $bubbleable_metadata
      ->addCacheableDependency($scheme);
    return array_merge($carry, array_reduce($scheme
      ->getAccessScheme()
      ->getTree(), function ($inner, $info) use ($sections) {
      $node_in_sections = array_intersect_key($info, array_combine($sections, $sections));
      return array_merge($inner, array_column($node_in_sections, 'label'));
    }, []));
  }, []);
}