You are here

protected function EntityReferenceHierarchySelect::getEmptyLabel in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/EntityReferenceHierarchySelect.php \Drupal\entity_hierarchy\Plugin\Field\FieldWidget\EntityReferenceHierarchySelect::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

src/Plugin/Field/FieldWidget/EntityReferenceHierarchySelect.php, line 117

Class

EntityReferenceHierarchySelect
Select widget.

Namespace

Drupal\entity_hierarchy\Plugin\Field\FieldWidget

Code

protected function getEmptyLabel() {

  // 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 -');
  }
}