You are here

public function DefaultLanguageItem::applyDefaultValue in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/language/src/DefaultLanguageItem.php \Drupal\language\DefaultLanguageItem::applyDefaultValue()

Applies the default value.

Parameters

bool $notify: (optional) Whether to notify the parent object of the change. Defaults to TRUE. If a property is updated from a parent object, set it to FALSE to avoid being notified again.

Return value

$this Returns itself to allow for chaining.

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;
}