function DefaultLanguageItem::applyDefaultValue

Same name in other branches
  1. 9 core/modules/language/src/DefaultLanguageItem.php \Drupal\language\DefaultLanguageItem::applyDefaultValue()
  2. 10 core/modules/language/src/DefaultLanguageItem.php \Drupal\language\DefaultLanguageItem::applyDefaultValue()
  3. 11.x core/modules/language/src/DefaultLanguageItem.php \Drupal\language\DefaultLanguageItem::applyDefaultValue()

Overrides LanguageItem::applyDefaultValue

File

core/modules/language/src/DefaultLanguageItem.php, line 25

Class

DefaultLanguageItem
Alternative plugin implementation of the 'language' field type.

Namespace

Drupal\language

Code

public function applyDefaultValue($notify = TRUE) {
    // Default to LANGCODE_NOT_SPECIFIED.
    $langcode = Language::LANGCODE_NOT_SPECIFIED;
    if ($entity = $this->getEntity()) {
        $langcode = $this->getDefaultLangcode($entity);
    }
    // Always notify otherwise default langcode will not be set correctly.
    $this->setValue([
        'value' => $langcode,
    ], TRUE);
    return $this;
}

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