Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. OptionsSelectWidget.php

function OptionsSelectWidget::getEmptyLabel

Overrides OptionsWidgetBase::getEmptyLabel

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php, line 62

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 $this->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 $this->t('- None -');
        }
        if (!$this->has_value) {
            return $this->t('- Select a value -');
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal