Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Followup for #2164601: Stop auto-creating FieldItems on mere reading of $entity->field[N].
Patch over there has this in FieldItemList::applyDefaultValue() :
if (no default value is specified for the field) {
// Create one field item and give it a chance to apply its defaults.
// Remove it if this ended up doing nothing...
$item = $this->first() ?: $this->appendItem();
$item->applyDefaultValue(FALSE);
$this->filterEmptyItems();
}
Having to create an item in case it wants to set a value is absurd. Field types that need this have other ways:
- use the 'default_value' annotation for the field type added by #2318605: uuid, created, changed, language default value implementations need to be updated
- implement FieldItemList::processDefaultValue(),
- override FieldItemList::applyDefaultValue() itself
Comments