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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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 ; } |
Please login to continue.