function FieldItemList::applyDefaultValue
Same name in other branches
- 9 core/lib/Drupal/Core/Field/FieldItemList.php \Drupal\Core\Field\FieldItemList::applyDefaultValue()
- 8.9.x core/lib/Drupal/Core/Field/FieldItemList.php \Drupal\Core\Field\FieldItemList::applyDefaultValue()
- 10 core/lib/Drupal/Core/Field/FieldItemList.php \Drupal\Core\Field\FieldItemList::applyDefaultValue()
Overrides TypedData::applyDefaultValue
File
-
core/
lib/ Drupal/ Core/ Field/ FieldItemList.php, line 168
Class
- FieldItemList
- Represents an entity field; that is, a list of field item objects.
Namespace
Drupal\Core\FieldCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.