You are here

protected function WorkbenchAccessByUserForm::addEditors in Workbench Access 8

Add editors to the section.

Parameters

array $uids: User ids to add.

int $section_id: Workbench access section id.

array $existing_editors: Existing editors uids.

1 call to WorkbenchAccessByUserForm::addEditors()
WorkbenchAccessByUserForm::submitForm in src/Form/WorkbenchAccessByUserForm.php
Form submission handler.

File

src/Form/WorkbenchAccessByUserForm.php, line 279

Class

WorkbenchAccessByUserForm
Configure Workbench Access per user.

Namespace

Drupal\workbench_access\Form

Code

protected function addEditors(array $uids, $section_id, array $existing_editors = []) {

  /** @var \Drupal\user\UserInterface[] $users */
  $users = User::loadMultiple($uids);
  $editors_added = [];
  foreach ($users as $uid => $user) {

    // Add user to section.
    if (!isset($existing_editors[$uid])) {
      $this->userSectionStorage
        ->addUser($this->scheme, $user, [
        $section_id,
      ]);
      $editors_added[] = $user
        ->getDisplayName();
    }
  }
  if (count($editors_added)) {
    $text = $this
      ->formatPlural(count($editors_added), 'User @user added.', 'Users added: @user', [
      '@user' => implode(', ', $editors_added),
    ]);
    \Drupal::messenger()
      ->addMessage($text);
  }
}