Commit ae08f47b authored by webchick's avatar webchick

Issue #1969032 by cam8001, swentel, amateescu: More sensible way of defining field default values.

parent 1125fa78
......@@ -97,7 +97,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess, \Serializable {
*
* @var array
*/
public $settings;
public $settings = array();
/**
* The field cardinality.
......@@ -107,7 +107,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess, \Serializable {
*
* @var integer
*/
public $cardinality;
public $cardinality = 1;
/**
* Flag indicating whether the field is translatable.
......@@ -116,7 +116,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess, \Serializable {
*
* @var bool
*/
public $translatable;
public $translatable = FALSE;
/**
* The entity types on which the field is allowed to have instances.
......@@ -126,7 +126,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess, \Serializable {
*
* @var array
*/
public $entity_types;
public $entity_types = array();
/**
* Flag indicating whether the field is available for editing.
......@@ -140,7 +140,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess, \Serializable {
*
* @var bool
*/
public $locked;
public $locked = FALSE;
/**
* The field storage definition.
......@@ -159,7 +159,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess, \Serializable {
*
* @var array
*/
public $storage;
public $storage = array();
/**
* The custom storage indexes for the field data storage.
......@@ -177,7 +177,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess, \Serializable {
*
* @var array
*/
public $indexes;
public $indexes = array();
/**
* Flag indicating whether the field is deleted.
......@@ -192,7 +192,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess, \Serializable {
*
* @var bool
*/
public $deleted;
public $deleted = FALSE;
/**
* The field schema.
......@@ -230,17 +230,6 @@ public function __construct(array $values, $entity_type = 'field_entity') {
throw new FieldException('Attempt to create a field with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character');
}
// Provide defaults.
$values += array(
'settings' => array(),
'cardinality' => 1,
'translatable' => FALSE,
'entity_types' => array(),
'locked' => FALSE,
'deleted' => FALSE,
'storage' => array(),
'indexes' => array(),
);
parent::__construct($values, $entity_type);
}
......
......@@ -79,6 +79,9 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess, \Serializa
* This will be used as the title of Form API elements for the field in entity
* edit forms, or as the label for the field values in displayed entities.
*
* If not specified, this defaults to the field_name (mostly useful for field
* instances created in tests).
*
* @var string
*/
public $label;
......@@ -92,7 +95,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess, \Serializa
*
* @var string
*/
public $description;
public $description = '';
/**
* Field-type specific settings.
......@@ -102,7 +105,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess, \Serializa
*
* @var array
*/
public $settings;
public $settings = array();
/**
* Flag indicating whether the field is required.
......@@ -113,7 +116,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess, \Serializa
*
* @var bool
*/
public $required;
public $required = FALSE;
/**
* Default field value.
......@@ -143,7 +146,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess, \Serializa
*
* @var array
*/
public $default_value;
public $default_value = array();
/**
* The name of a callback function that returns default values.
......@@ -165,7 +168,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess, \Serializa
*
* @var string
*/
public $default_value_function;
public $default_value_function = '';
/**
* The widget definition.
......@@ -183,7 +186,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess, \Serializa
*
* @var array
*/
public $widget;
public $widget = array();
/**
* Flag indicating whether the instance is deleted.
......@@ -198,7 +201,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess, \Serializa
*
* @var bool
*/
public $deleted;
public $deleted = FALSE;
/**
* The field ConfigEntity object corresponding to $field_uuid.
......@@ -265,18 +268,10 @@ public function __construct(array $values, $entity_type = 'field_instance') {
throw new FieldException(format_string('Attempt to create an instance of field @field_id without a bundle.', array('@field_id' => $this->field->id)));
}
// Provide defaults.
// 'Label' defaults to the field ID (mostly useful for field instances
// created in tests).
$values += array(
// 'Label' defaults to the field ID (mostly useful for field instances
// created in tests).
'label' => $this->field->id,
'description' => '',
'required' => FALSE,
'default_value' => array(),
'default_value_function' => '',
'settings' => array(),
'widget' => array(),
'deleted' => FALSE,
);
parent::__construct($values, $entity_type);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment