Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293279

Unify handling of default values between base and configurable fields

$
0
0

- EntityNG Field class has the applyDefaultValue() method.
- Configurable fields still assign their default values through field.module's hook_entity_create(), and a series of helper functions:
field_populate_default_values(), field_get_default_value().

Attached patch unifies the handling of default values for base and config fields:
- removes field_entity_create(), field_populate_default_values(), field_get_default_value()
- adds FieldDefinitionInterface::getFieldDefaultValue(), and implements it in field API's Field and FieldInstance config entities;
for Field : empty
for FieldInstance: contains the previous logic from field_get_default_value()
- splits applyDefaultValue() into a helper getDefaultValue()
- ConfigField overrides getDefaultValue() to return $instance->getFieldDefaultValue()

Those last two points can be simplified once base field definitions are FieldDefinitionInterface objects (#2047229: Make use of classes for entity field and data definitions). applyDefaultValue() can directly call $this->definition->getFieldDefaultValue()

API changes:
- field_populate_default_values() is removed - was just a helper function, not likely to have standalone uses
- field_get_default_value() --> FieldDefinitionInterface::getFieldDefaultValue()
- dynamic 'default_value_function' callbacks for configurable fields change signatures
before: callback(EntityInterface $entity, Field $field, FieldInstance $instance, $langcode)
after: callback(EntityInterface $entity, FieldDefinitionInterface $field_definition)


Viewing all articles
Browse latest Browse all 293279

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>