You are here

public function Role::adminForm in Mass Contact 8

Builds the form for selecting categories for a mass contact.

Parameters

array $form: The form definition array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

Overrides GroupingInterface::adminForm

File

src/Plugin/MassContact/GroupingMethod/Role.php, line 127

Class

Role
Select users by their role.

Namespace

Drupal\mass_contact\Plugin\MassContact\GroupingMethod

Code

public function adminForm(array &$form, FormStateInterface $form_state) {
  $roles = $this->entityTypeManager
    ->getStorage('user_role')
    ->loadMultiple();
  unset($roles[RoleInterface::ANONYMOUS_ID]);
  $options = array_map(function (RoleInterface $role) {
    return $role
      ->label();
  }, $roles);

  // Create a set of checkboxes, including each role.
  $form['categories'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('User roles to include'),
    '#options' => $options,
    '#default_value' => $this->configuration['categories'],
    '#description' => t('These roles will be added to the mailing list. Note: if you check "authenticated user", other roles will not be added, as they will receive the email anyway.'),
  ];
  $form['conjunction'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Selection criteria'),
    '#options' => [
      'OR' => $this
        ->t('Any'),
      'AND' => $this
        ->t('All'),
    ],
    '#description' => $this
      ->t('Choose <em>any</em> to return recipients with any of the roles, choose <em>all</em> to return recipients with all of the roles.'),
    '#default_value' => $this->configuration['conjunction'],
  ];
}