Same name in this branch
- 10 core/lib/Drupal/Core/Render/Element/Select.php \Drupal\Core\Render\Element\Select
- 10 core/lib/Drupal/Core/Database/Driver/pgsql/Select.php \Drupal\Core\Database\Driver\pgsql\Select
- 10 core/lib/Drupal/Core/Database/Driver/sqlite/Select.php \Drupal\Core\Database\Driver\sqlite\Select
- 10 core/modules/mysql/src/Driver/Database/mysql/Select.php \Drupal\mysql\Driver\Database\mysql\Select
- 10 core/modules/pgsql/src/Driver/Database/pgsql/Select.php \Drupal\pgsql\Driver\Database\pgsql\Select
- 10 core/modules/sqlite/src/Driver/Database/sqlite/Select.php \Drupal\sqlite\Driver\Database\sqlite\Select
- 10 core/tests/Drupal/Tests/Core/Database/Stub/Select.php \Drupal\Tests\Core\Database\Stub\Select
Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Render/Element/Select.php \Drupal\Core\Render\Element\Select
- 9 core/lib/Drupal/Core/Render/Element/Select.php \Drupal\Core\Render\Element\Select
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElementBase implements ElementInterface
- class \Drupal\Core\Render\Element\FormElementBase implements FormElementInterface
- class \Drupal\Core\Render\Element\Select
- class \Drupal\Core\Render\Element\FormElementBase implements FormElementInterface
- class \Drupal\Core\Render\Element\RenderElementBase implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Select
1 file declares its use of Select
- WeightTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Render/ Element/ WeightTest.php
3 string references to 'Select'
- ContentModerationConfigureForm::buildConfigurationForm in core/
modules/ content_moderation/ src/ Form/ ContentModerationConfigureForm.php - Form constructor.
- FormTestValidateRequiredForm::buildForm in core/
modules/ system/ tests/ modules/ form_test/ src/ Form/ FormTestValidateRequiredForm.php - Form constructor.
- form_test.routing.yml in core/
modules/ system/ tests/ modules/ form_test/ form_test.routing.yml - core/modules/system/tests/modules/form_test/form_test.routing.yml
File
- core/
lib/ Drupal/ Core/ Render/ Element/ Select.php, line 82
Namespace
Drupal\Core\Render\ElementView source
class Select extends FormElementBase {
/**
* {@inheritdoc}
*/
public function getInfo() {
$class = static::class;
return [
'#input' => TRUE,
'#multiple' => FALSE,
'#sort_options' => FALSE,
'#sort_start' => NULL,
'#process' => [
[
$class,
'processSelect',
],
[
$class,
'processAjaxForm',
],
],
'#pre_render' => [
[
$class,
'preRenderSelect',
],
],
'#theme' => 'select',
'#theme_wrappers' => [
'form_element',
],
'#options' => [],
];
}
/**
* Processes a select list form element.
*
* This process callback is mandatory for select fields, since all user agents
* automatically preselect the first available option of single (non-multiple)
* select lists.
*
* @param array $element
* The form element to process.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param array $complete_form
* The complete form structure.
*
* @return array
* The processed element.
*
* @see _form_validate()
*/
public static function processSelect(&$element, FormStateInterface $form_state, &$complete_form) {
// #multiple select fields need a special #name.
if ($element['#multiple']) {
$element['#attributes']['multiple'] = 'multiple';
$element['#attributes']['name'] = $element['#name'] . '[]';
}
else {
// If the element is set to #required through #states, override the
// element's #required setting.
$required = isset($element['#states']['required']) ? TRUE : $element['#required'];
// If the element is required and there is no #default_value, then add an
// empty option that will fail validation, so that the user is required to
// make a choice. Also, if there's a value for #empty_value or
// #empty_option, then add an option that represents emptiness.
if ($required && !isset($element['#default_value']) || isset($element['#empty_value']) || isset($element['#empty_option'])) {
$element += [
'#empty_value' => '',
'#empty_option' => $required ? t('- Select -') : t('- None -'),
];
// The empty option is prepended to #options and purposively not merged
// to prevent another option in #options mistakenly using the same value
// as #empty_value.
$empty_option = [
$element['#empty_value'] => $element['#empty_option'],
];
$element['#options'] = $empty_option + $element['#options'];
}
}
// Provide the correct default value for #sort_start.
$element['#sort_start'] = $element['#sort_start'] ?? (isset($element['#empty_value']) ? 1 : 0);
return $element;
}
/**
* {@inheritdoc}
*/
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
if ($input !== FALSE) {
if (isset($element['#multiple']) && $element['#multiple']) {
// If an enabled multi-select submits NULL, it means all items are
// unselected. A disabled multi-select always submits NULL, and the
// default value should be used.
if (empty($element['#disabled'])) {
return is_array($input) ? array_combine($input, $input) : [];
}
else {
return isset($element['#default_value']) && is_array($element['#default_value']) ? $element['#default_value'] : [];
}
}
elseif (isset($element['#empty_value']) && $input === (string) $element['#empty_value']) {
return $element['#empty_value'];
}
else {
return $input;
}
}
}
/**
* Prepares a select render element.
*/
public static function preRenderSelect($element) {
Element::setAttributes($element, [
'id',
'name',
'size',
]);
static::setAttributes($element, [
'form-select',
]);
return $element;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormElementBase:: |
public static | function | Adds autocomplete functionality to elements. | 1 |
FormElementBase:: |
public static | function | #process callback for #pattern form element property. | 1 |
FormElementBase:: |
public static | function | #element_validate callback for #pattern form element property. | 1 |
MessengerTrait:: |
protected | property | The messenger. | 8 |
MessengerTrait:: |
public | function | Gets the messenger. | 8 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
1 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 40 |
RenderElementBase:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | 2 |
RenderElementBase:: |
public static | function | Adds members of this group as actual elements for rendering. | 2 |
RenderElementBase:: |
public static | function | Form element processing handler for the #ajax form property. | 3 |
RenderElementBase:: |
public static | function | Arranges elements into groups. | 2 |
RenderElementBase:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
2 |
Select:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
Select:: |
public static | function | Prepares a select render element. | |
Select:: |
public static | function | Processes a select list form element. | |
Select:: |
public static | function |
Determines how user input is mapped to an element's #value property. Overrides FormElementBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 3 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 1 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |