public static function UserSelection::settingsForm

Overrides SelectionBase::settingsForm().

Overrides SelectionBase::settingsForm

File

drupal/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php, line 33
Contains \Drupal\user\Plugin\entity_reference\selection\UserSelection.

Class

UserSelection
Provides specific access control for the user entity type.

Namespace

Drupal\user\Plugin\entity_reference\selection

Code

public static function settingsForm(&$field, &$instance) {

  // Merge in default values.
  $instance['settings']['handler_settings'] += array(
    'filter' => array(
      'type' => '_none',
    ),
  );

  // Add user specific filter options.
  $form['filter']['type'] = array(
    '#type' => 'select',
    '#title' => t('Filter by'),
    '#options' => array(
      '_none' => t('- None -'),
      'role' => t('User role'),
    ),
    '#ajax' => TRUE,
    '#limit_validation_errors' => array(),
    '#default_value' => $instance['settings']['handler_settings']['filter']['type'],
  );
  $form['filter']['settings'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'entity_reference-settings',
      ),
    ),
    '#process' => array(
      '_entity_reference_form_process_merge_parent',
    ),
  );
  if ($instance['settings']['handler_settings']['filter']['type'] == 'role') {

    // Merge in default values.
    $instance['settings']['handler_settings']['filter'] += array(
      'role' => NULL,
    );
    $form['filter']['settings']['role'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Restrict to the selected roles'),
      '#required' => TRUE,
      '#options' => array_diff_key(user_role_names(TRUE), drupal_map_assoc(array(
        DRUPAL_AUTHENTICATED_RID,
      ))),
      '#default_value' => $instance['settings']['handler_settings']['filter']['role'],
    );
  }
  $form += parent::settingsForm($field, $instance);
  return $form;
}