You are here

private function WorkbenchAccessTokens::getUserSectionNames in Workbench Access 8

Generates an array of section names for a given account.

Parameters

\Drupal\user\UserInterface $user: The user account.

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

Return value

array An array of section names.

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

File

src/WorkbenchAccessTokens.php, line 177

Class

WorkbenchAccessTokens
Token handler for Workbench Access.

Namespace

Drupal\workbench_access

Code

private function getUserSectionNames(UserInterface $user, BubbleableMetadata $bubbleable_metadata) {
  $schemes = $this->entityTypeManager
    ->getStorage('access_scheme')
    ->loadMultiple();
  return array_reduce($schemes, function (array $carry, AccessSchemeInterface $scheme) use ($user, $bubbleable_metadata) {
    if (!($sections = $this->userSectionStorage
      ->getUserSections($scheme, $user))) {
      return $carry;
    }
    $bubbleable_metadata
      ->addCacheableDependency($scheme);
    return array_merge($carry, array_reduce($scheme
      ->getAccessScheme()
      ->getTree(), function ($inner, $info) use ($sections) {
      $user_in_sections = array_intersect_key($info, array_combine($sections, $sections));
      return array_merge($inner, array_column($user_in_sections, 'label'));
    }, []));
  }, []);
}