function OptionsSelectWidget::getEmptyLabel

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::getEmptyLabel()
  2. 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::getEmptyLabel()
  3. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget::getEmptyLabel()
  4. 8.9.x 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 75

Class

OptionsSelectWidget
Plugin implementation of the 'options_select' widget.

Namespace

Drupal\Core\Field\Plugin\Field\FieldWidget

Code

protected function getEmptyLabel() {
  // Add a 'none' option for non-required fields.
  if (!$this->required) {
    return $this->t('- None -');
  }
  return NULL;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.