function UserSelection::buildConfigurationForm

Same name in other branches
  1. 8.9.x core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::buildConfigurationForm()
  2. 10 core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::buildConfigurationForm()
  3. 11.x core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::buildConfigurationForm()

Overrides DefaultSelection::buildConfigurationForm

File

core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php, line 102

Class

UserSelection
Provides specific access control for the user entity type.

Namespace

Drupal\user\Plugin\EntityReferenceSelection

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $configuration = $this->getConfiguration();
    $form['include_anonymous'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Include the anonymous user.'),
        '#default_value' => $configuration['include_anonymous'],
    ];
    // Add user specific filter options.
    $form['filter']['type'] = [
        '#type' => 'select',
        '#title' => $this->t('Filter by'),
        '#options' => [
            '_none' => $this->t('- None -'),
            'role' => $this->t('User role'),
        ],
        '#ajax' => TRUE,
        '#limit_validation_errors' => [],
        '#default_value' => $configuration['filter']['type'],
    ];
    $form['filter']['settings'] = [
        '#type' => 'container',
        '#attributes' => [
            'class' => [
                'entity_reference-settings',
            ],
        ],
        '#process' => [
            [
                '\\Drupal\\Core\\Field\\Plugin\\Field\\FieldType\\EntityReferenceItem',
                'formProcessMergeParent',
            ],
        ],
    ];
    if ($configuration['filter']['type'] == 'role') {
        $form['filter']['settings']['role'] = [
            '#type' => 'checkboxes',
            '#title' => $this->t('Restrict to the selected roles'),
            '#required' => TRUE,
            '#options' => array_diff_key(user_role_names(TRUE), [
                RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID,
            ]),
            '#default_value' => $configuration['filter']['role'],
        ];
    }
    $form += parent::buildConfigurationForm($form, $form_state);
    return $form;
}

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