class OptionsButtonsWidget
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsButtonsWidget
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsButtonsWidget
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsButtonsWidget
Plugin implementation of the 'options_buttons' widget.
Plugin annotation
@FieldWidget(
id = "options_buttons",
label = @Translation("Check boxes/radio buttons"),
field_types = {
"boolean",
"entity_reference",
"list_integer",
"list_float",
"list_string",
},
multiple_values = TRUE
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Field\WidgetBase implements \Drupal\Core\Field\WidgetInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface uses \Drupal\Core\Field\AllowedTagsXssTrait extends \Drupal\Core\Field\PluginSettingsBase
- class \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase extends \Drupal\Core\Field\WidgetBase
- class \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsButtonsWidget extends \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase
- class \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase extends \Drupal\Core\Field\WidgetBase
- class \Drupal\Core\Field\WidgetBase implements \Drupal\Core\Field\WidgetInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface uses \Drupal\Core\Field\AllowedTagsXssTrait extends \Drupal\Core\Field\PluginSettingsBase
- class \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of OptionsButtonsWidget
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldWidget/ OptionsButtonsWidget.php, line 24
Namespace
Drupal\Core\Field\Plugin\Field\FieldWidgetView source
class OptionsButtonsWidget extends OptionsWidgetBase {
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$options = $this->getOptions($items->getEntity());
$selected = $this->getSelectedOptions($items);
// If required and there is one single option, preselect it.
if ($this->required && count($options) == 1) {
reset($options);
$selected = [
key($options),
];
}
if ($this->multiple) {
$element += [
'#type' => 'checkboxes',
'#default_value' => $selected,
'#options' => $options,
];
}
else {
$element += [
'#type' => 'radios',
// Radio buttons need a scalar value. Take the first default value, or
// default to NULL so that the form element is properly recognized as
// not having a default value.
'#default_value' => $selected ? reset($selected) : NULL,
'#options' => $options,
];
}
return $element;
}
/**
* {@inheritdoc}
*/
protected function getEmptyLabel() {
if (!$this->required && !$this->multiple) {
return t('N/A');
}
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|
| AllowedTagsXssTrait::allowedTags | public | function | Returns a list of tags allowed by AllowedTagsXssTrait::fieldFilterXss(). | ||
| AllowedTagsXssTrait::displayAllowedTags | public | function | Returns a human-readable list of allowed tags for display in help texts. | ||
| AllowedTagsXssTrait::fieldFilterXss | public | function | Filters an HTML string to prevent XSS vulnerabilities. | ||
| DependencySerializationTrait::$_entityStorages | protected | property | An array of entity type IDs keyed by the property name of their storages. | ||
| DependencySerializationTrait::$_serviceIds | protected | property | An array of service IDs keyed by property name used for serialization. | ||
| DependencySerializationTrait::__sleep | public | function | 1 | ||
| DependencySerializationTrait::__wakeup | public | function | 2 | ||
| MessengerTrait::$messenger | protected | property | The messenger. | 29 | |
| MessengerTrait::messenger | public | function | Gets the messenger. | 29 | |
| MessengerTrait::setMessenger | public | function | Sets the messenger. | ||
| OptionsButtonsWidget::formElement | public | function | Overrides OptionsWidgetBase::formElement | ||
| OptionsButtonsWidget::getEmptyLabel | protected | function | Overrides OptionsWidgetBase::getEmptyLabel | ||
| OptionsWidgetBase::$column | protected | property | Abstract over the actual field columns, to allow different field types to reuse those widgets. |
||
| OptionsWidgetBase::getOptions | protected | function | Returns the array of options for the widget. | ||
| OptionsWidgetBase::getSelectedOptions | protected | function | Determines selected options from the incoming field values. | ||
| OptionsWidgetBase::sanitizeLabel | protected | function | Sanitizes a string label to display as an option. | 1 | |
| OptionsWidgetBase::supportsGroups | protected | function | Indicates whether the widgets support optgroups. | 1 | |
| OptionsWidgetBase::validateElement | public static | function | Form validation handler for widget elements. | 1 | |
| OptionsWidgetBase::__construct | public | function | Overrides WidgetBase::__construct | 1 | |
| PluginBase::$configuration | protected | property | Configuration information passed into the plugin. | 1 | |
| PluginBase::$pluginDefinition | protected | property | The plugin implementation definition. | 1 | |
| PluginBase::$pluginId | protected | property | The plugin_id. | ||
| PluginBase::DERIVATIVE_SEPARATOR | constant | A string which is used to separate base plugin IDs from the derivative ID. | |||
| PluginBase::getBaseId | public | function | Overrides DerivativeInspectionInterface::getBaseId | ||
| PluginBase::getDerivativeId | public | function | Overrides DerivativeInspectionInterface::getDerivativeId | ||
| PluginBase::getPluginDefinition | public | function | Overrides PluginInspectionInterface::getPluginDefinition | 3 | |
| PluginBase::getPluginId | public | function | Overrides PluginInspectionInterface::getPluginId | ||
| PluginBase::isConfigurable | public | function | Determines if the plugin is configurable. | ||
| PluginSettingsBase::$defaultSettingsMerged | protected | property | Whether default settings have been merged into the current $settings. | ||
| PluginSettingsBase::$thirdPartySettings | protected | property | The plugin settings injected by third party modules. | ||
| PluginSettingsBase::calculateDependencies | public | function | Overrides DependentPluginInterface::calculateDependencies | 6 | |
| PluginSettingsBase::defaultSettings | public static | function | Overrides PluginSettingsInterface::defaultSettings | 42 | |
| PluginSettingsBase::getSetting | public | function | Overrides PluginSettingsInterface::getSetting | ||
| PluginSettingsBase::getSettings | public | function | Overrides PluginSettingsInterface::getSettings | ||
| PluginSettingsBase::getThirdPartyProviders | public | function | Overrides ThirdPartySettingsInterface::getThirdPartyProviders | ||
| PluginSettingsBase::getThirdPartySetting | public | function | Overrides ThirdPartySettingsInterface::getThirdPartySetting | ||
| PluginSettingsBase::getThirdPartySettings | public | function | Overrides ThirdPartySettingsInterface::getThirdPartySettings | ||
| PluginSettingsBase::mergeDefaults | protected | function | Merges default settings values into $settings. | ||
| PluginSettingsBase::onDependencyRemoval | public | function | Overrides PluginSettingsInterface::onDependencyRemoval | 3 | |
| PluginSettingsBase::setSetting | public | function | Overrides PluginSettingsInterface::setSetting | ||
| PluginSettingsBase::setSettings | public | function | Overrides PluginSettingsInterface::setSettings | ||
| PluginSettingsBase::setThirdPartySetting | public | function | Overrides ThirdPartySettingsInterface::setThirdPartySetting | ||
| PluginSettingsBase::unsetThirdPartySetting | public | function | Overrides ThirdPartySettingsInterface::unsetThirdPartySetting | ||
| StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 1 | |
| StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
| StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
| StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
| StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
| StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | ||
| WidgetBase::$fieldDefinition | protected | property | The field definition. | ||
| WidgetBase::$settings | protected | property | The widget settings. | Overrides PluginSettingsBase::$settings | |
| WidgetBase::addMoreAjax | public static | function | Ajax callback for the "Add another item" button. | ||
| WidgetBase::addMoreSubmit | public static | function | Submission handler for the "Add another item" button. | ||
| WidgetBase::afterBuild | public static | function | After-build handler for field elements in a form. | ||
| WidgetBase::create | public static | function | Overrides ContainerFactoryPluginInterface::create | 5 | |
| WidgetBase::errorElement | public | function | Overrides WidgetInterface::errorElement | 8 | |
| WidgetBase::extractFormValues | public | function | Overrides WidgetBaseInterface::extractFormValues | 2 | |
| WidgetBase::flagErrors | public | function | Overrides WidgetBaseInterface::flagErrors | 2 | |
| WidgetBase::form | public | function | Overrides WidgetBaseInterface::form | 3 | |
| WidgetBase::formMultipleElements | protected | function | Special handling to create form elements for multiple values. | 1 | |
| WidgetBase::formSingleElement | protected | function | Generates the form element for a single copy of the widget. | ||
| WidgetBase::getFieldSetting | protected | function | Returns the value of a field setting. | ||
| WidgetBase::getFieldSettings | protected | function | Returns the array of field settings. | ||
| WidgetBase::getFilteredDescription | protected | function | Returns the filtered field description. | ||
| WidgetBase::getWidgetState | public static | function | Overrides WidgetBaseInterface::getWidgetState | ||
| WidgetBase::getWidgetStateParents | protected static | function | Returns the location of processing information within $form_state. | ||
| WidgetBase::handlesMultipleValues | protected | function | Returns whether the widget handles multiple values. | ||
| WidgetBase::isApplicable | public static | function | Overrides WidgetInterface::isApplicable | 4 | |
| WidgetBase::isDefaultValueWidget | protected | function | Returns whether the widget used for default value form. | ||
| WidgetBase::massageFormValues | public | function | Overrides WidgetInterface::massageFormValues | 7 | |
| WidgetBase::settingsForm | public | function | Overrides WidgetInterface::settingsForm | 16 | |
| WidgetBase::settingsSummary | public | function | Overrides WidgetInterface::settingsSummary | 15 | |
| WidgetBase::setWidgetState | public static | function | Overrides WidgetBaseInterface::setWidgetState |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.