diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php index cad3f5c..69b084c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php @@ -68,15 +68,8 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen */ protected function getEmptyOption() { if (!$this->required && !$this->multiple) { - return static::OPTIONS_EMPTY_NONE; + return [static::OPTIONS_EMPTY_NONE => t('N/A')]; } } - /** - * {@inheritdoc} - */ - protected function getEmptyLabel() { - return t('N/A'); - } - } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php index dc5ade0..c045bc6 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php @@ -66,7 +66,7 @@ protected function getEmptyOption() { if ($this->multiple) { // Multiple select: add a 'none' option for non-required fields. if (!$this->required) { - return static::OPTIONS_EMPTY_NONE; + return [static::OPTIONS_EMPTY_NONE => t('- None -')]; } } else { @@ -74,18 +74,12 @@ protected function getEmptyOption() { // and a 'select a value' option for required fields that do not come // with a value selected. if (!$this->required) { - return static::OPTIONS_EMPTY_NONE; + return [static::OPTIONS_EMPTY_NONE => t('- None -')]; } if (!$this->has_value) { - return static::OPTIONS_EMPTY_SELECT; + return [static::OPTIONS_EMPTY_SELECT => t('- Select a value -')]; } } } - /** - * {@inheritdoc} - */ - protected function getEmptyLabel() { - return ($this->getEmptyOption() == static::OPTIONS_EMPTY_NONE ? t('- None -') : t('- Select a value -')); - } } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php index 7deabb2..6ba3042 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php @@ -130,9 +130,8 @@ protected function getOptions(FieldableEntityInterface $entity) { ->getSettableOptions(\Drupal::currentUser()); // Add an empty option if the widget needs one. - if ($this->getEmptyOption()) { - $label = $this->getEmptyLabel(); - $options = array('_none' => $label) + $options; + if ($empty_option = $this->getEmptyOption()) { + $options = $empty_option + $options; } $module_handler = \Drupal::moduleHandler(); @@ -205,19 +204,12 @@ protected function sanitizeLabel(&$label) { } /** - * Returns the empty option to add to the list of options, if any. + * Returns the empty option and label to add to the list of options, if any. * - * @return string|null - * Either static::OPTIONS_EMPTY_NONE, static::OPTIONS_EMPTY_SELECT, or NULL. + * @return array|null + * Either static::OPTIONS_EMPTY_NONE, static::OPTIONS_EMPTY_SELECT as a key + * and value as a label of the empty option, or NULL. */ protected function getEmptyOption() { } - /** - * Returns the empty option label . - * - * @return string|null - * Either string, or NULL. - */ - protected function getEmptyLabel() { } - }