You are here

public function DefaultLanguageItem::applyDefaultValue in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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

\Drupal\Core\TypedData\TypedDataInterface Returns itself to allow for chaining.

Overrides LanguageItem::applyDefaultValue

File

core/modules/language/src/DefaultLanguageItem.php, line 30
Contains \Drupal\language\DefaultLanguageItem.

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(array(
    'value' => $langcode,
  ), TRUE);
  return $this;
}