You are here

protected function OptionsSelectWidget::getEmptyLabel in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::getEmptyLabel()

Returns the empty option label to add to the list of options, if any.

Return value

string|NULL Either a label of the empty option, or NULL.

Overrides OptionsWidgetBase::getEmptyLabel

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php, line 66
Contains \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget.

Class

OptionsSelectWidget
Plugin implementation of the 'options_select' widget.

Namespace

Drupal\Core\Field\Plugin\Field\FieldWidget

Code

protected function getEmptyLabel() {
  if ($this->multiple) {

    // Multiple select: add a 'none' option for non-required fields.
    if (!$this->required) {
      return t('- None -');
    }
  }
  else {

    // Single select: add a 'none' option for non-required fields,
    // and a 'select a value' option for required fields that do not come
    // with a value selected.
    if (!$this->required) {
      return t('- None -');
    }
    if (!$this->has_value) {
      return t('- Select a value -');
    }
  }
}