You are here

public function RoleSectionStorage::removeRole in Workbench Access 8

Removes a set of sections from a role.

Parameters

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

string $role_id: A role id.

array $sections: An array of section ids to remove from this role.

Overrides RoleSectionStorageInterface::removeRole

1 call to RoleSectionStorage::removeRole()
RoleSectionStorage::deleteRoleSections in src/RoleSectionStorage.php
Delete the saved sections for this role.

File

src/RoleSectionStorage.php, line 90

Class

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

Namespace

Drupal\workbench_access

Code

public function removeRole(AccessSchemeInterface $scheme, $role_id, array $sections = []) {
  foreach ($sections as $id) {
    $new_values = [];
    if ($section_association = $this
      ->sectionStorage()
      ->loadSection($scheme
      ->id(), $id)) {
      if ($values = $section_association
        ->getCurrentRoleIds()) {
        foreach ($values as $delta => $value) {
          if ($value != $role_id) {
            $new_values[] = $value;
          }
        }
        $section_association
          ->set('role_id', array_unique($new_values));
      }
      $section_association
        ->save();
    }
    \Drupal::service('workbench_access.user_section_storage')
      ->resetCache($scheme);
  }
}