You are here

public function RoleSectionStorage::getRoleSections in Workbench Access 8

Gets the sections assigned to a user by way of their roles.

Parameters

\Drupal\workbench_access\Entity\AccessSchemeInterface $scheme: Access scheme.

\Drupal\Core\Session\AccountInterface $account: The account to retrieve sections for by way of their roles.

Return value

array Array of section IDs.

Overrides RoleSectionStorageInterface::getRoleSections

File

src/RoleSectionStorage.php, line 111

Class

RoleSectionStorage
Defines a role-section storage that uses the State API.

Namespace

Drupal\workbench_access

Code

public function getRoleSections(AccessSchemeInterface $scheme, AccountInterface $account = NULL) {
  $sections = [];
  if ($account) {
    $results = $this
      ->sectionStorage()
      ->loadByProperties([
      'role_id' => $account
        ->getRoles(),
      'access_scheme' => $scheme
        ->id(),
    ]);
    foreach ($results as $result) {
      $sections[] = $result
        ->get('section_id')->value;
    }
  }
  return $sections;
}