public function UserSelection::buildConfigurationForm in Drupal 10
Same name and namespace in other branches
- 8 core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::buildConfigurationForm()
- 9 core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::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\EntityReferenceSelectionCode
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;
}