FieldItemList::applyDefaultValue

public FieldItemList::applyDefaultValue($notify = TRUE)

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 TypedData::applyDefaultValue

File

core/lib/Drupal/Core/Field/FieldItemList.php, line 179

Class

FieldItemList
Represents an entity field; that is, a list of field item objects.

Namespace

Drupal\Core\Field

Code

public function applyDefaultValue($notify = TRUE) {
  if ($value = $this->getFieldDefinition()->getDefaultValue($this->getEntity())) {
    $this->setValue($value, $notify);
  }
  else {
    // Create one field item and give it a chance to apply its defaults.
    // Remove it if this ended up doing nothing.
    // @todo Having to create an item in case it wants to set a value is
    // absurd. Remove that in https://www.drupal.org/node/2356623.
    $item = $this->first() ? : $this->appendItem();
    $item->applyDefaultValue(FALSE);
    $this->filterEmptyItems();
  }
  return $this;
}
doc_Drupal
2016-10-29 09:11:52
Comments
Leave a Comment

Please login to continue.