You are here

public function User::buildOptionsForm in Drupal 8

Same name in this branch
  1. 8 core/modules/user/src/Plugin/views/argument_default/User.php \Drupal\user\Plugin\views\argument_default\User::buildOptionsForm()
  2. 8 core/modules/user/src/Plugin/views/argument_validator/User.php \Drupal\user\Plugin\views\argument_validator\User::buildOptionsForm()
Same name and namespace in other branches
  1. 9 core/modules/user/src/Plugin/views/argument_validator/User.php \Drupal\user\Plugin\views\argument_validator\User::buildOptionsForm()

Provides the default form for setting options.

Overrides Entity::buildOptionsForm

1 call to User::buildOptionsForm()
UserName::buildOptionsForm in core/modules/user/src/Plugin/views/argument_validator/UserName.php
Provides the default form for setting options.
1 method overrides User::buildOptionsForm()
UserName::buildOptionsForm in core/modules/user/src/Plugin/views/argument_validator/UserName.php
Provides the default form for setting options.

File

core/modules/user/src/Plugin/views/argument_validator/User.php, line 51

Class

User
Validate whether an argument is a valid user.

Namespace

Drupal\user\Plugin\views\argument_validator

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $sanitized_id = ArgumentPluginBase::encodeValidatorId($this->definition['id']);
  $form['restrict_roles'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Restrict user based on role'),
    '#default_value' => $this->options['restrict_roles'],
  ];
  $form['roles'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Restrict to the selected roles'),
    '#options' => array_map([
      '\\Drupal\\Component\\Utility\\Html',
      'escape',
    ], user_role_names(TRUE)),
    '#default_value' => $this->options['roles'],
    '#description' => $this
      ->t('If no roles are selected, users from any role will be allowed.'),
    '#states' => [
      'visible' => [
        ':input[name="options[validate][options][' . $sanitized_id . '][restrict_roles]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
}