Problem/Motivation
This is a followup for #1735118: Convert Field API to CMI and postponed on that issue.
The constructors for Field
and FieldInstance
provide default values for some $values
.
In Field
:
<?php
// Provide defaults.
$values += array(
'settings'=> array(),
'cardinality'=> 1,
'translatable'=> FALSE,
'entity_types'=> array(),
'locked'=> FALSE,
'deleted'=> 0,
'storage'=> array(),
'indexes'=> array(),
);
?>
In FieldInstance
:
<?php
// Provide defaults.
$values += array(
'label'=> $values['field_name'],
'description'=> '',
'required'=> FALSE,
'default_value'=> array(),
'default_value_function'=> '',
'settings'=> array(),
'widget'=> array(),
'deleted'=> 0,
);
?>
These defaults are buried inside the constructors, so it is not clear to calling code or developers what defaults are available.
Proposed resolution
Provide a static method on the class that returns these defaults.
Remaining tasks
- Create an initial patch that adds a static method to both classes.
- Update the constructors to use these static methods.
- The default for the field label in
FieldInstance
will need to be merged in afterward in the constructor since this is a dynamic value.