function User::buildOptionsForm

Same name in this branch
  1. 10 core/modules/user/src/Plugin/views/argument_default/User.php \Drupal\user\Plugin\views\argument_default\User::buildOptionsForm()
Same name in other branches
  1. 9 core/modules/user/src/Plugin/views/argument_validator/User.php \Drupal\user\Plugin\views\argument_validator\User::buildOptionsForm()
  2. 9 core/modules/user/src/Plugin/views/argument_default/User.php \Drupal\user\Plugin\views\argument_default\User::buildOptionsForm()
  3. 8.9.x core/modules/user/src/Plugin/views/argument_validator/User.php \Drupal\user\Plugin\views\argument_validator\User::buildOptionsForm()
  4. 8.9.x core/modules/user/src/Plugin/views/argument_default/User.php \Drupal\user\Plugin\views\argument_default\User::buildOptionsForm()
  5. 11.x core/modules/user/src/Plugin/views/argument_validator/User.php \Drupal\user\Plugin\views\argument_validator\User::buildOptionsForm()
  6. 11.x core/modules/user/src/Plugin/views/argument_default/User.php \Drupal\user\Plugin\views\argument_default\User::buildOptionsForm()

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 54

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'],
    ];
    $roles = Role::loadMultiple();
    unset($roles[RoleInterface::ANONYMOUS_ID]);
    $roles = array_map(fn(RoleInterface $role) => Html::escape($role->label()), $roles);
    $form['roles'] = [
        '#type' => 'checkboxes',
        '#title' => $this->t('Restrict to the selected roles'),
        '#options' => $roles,
        '#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,
                ],
            ],
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.