diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php index fe6886a..d4e276f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/Field.php @@ -95,7 +95,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess { * * @var array */ - public $settings; + public $settings = array(); /** * The field cardinality. @@ -105,7 +105,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess { * * @var integer */ - public $cardinality; + public $cardinality = 1; /** * Flag indicating whether the field is translatable. @@ -114,7 +114,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess { * * @var bool */ - public $translatable; + public $translatable = FALSE; /** * The entity types on which the field is allowed to have instances. @@ -124,7 +124,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess { * * @var array */ - public $entity_types; + public $entity_types = array(); /** * Flag indicating whether the field is available for editing. @@ -138,7 +138,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess { * * @var bool */ - public $locked; + public $locked = FALSE; /** * The field storage definition. @@ -157,7 +157,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess { * * @var array */ - public $storage; + public $storage = array(); /** * The custom storage indexes for the field data storage. @@ -175,7 +175,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess { * * @var array */ - public $indexes; + public $indexes = array(); /** * Flag indicating whether the field is deleted. @@ -190,7 +190,7 @@ class Field extends ConfigEntityBase implements \ArrayAccess { * * @var bool */ - public $deleted; + public $deleted = FALSE; /** * The field schema. @@ -228,17 +228,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' => 0, - 'storage' => array(), - 'indexes' => array(), - ); parent::__construct($values, $entity_type); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php index 9db2f3d..dcb3611 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php @@ -89,6 +89,8 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess { * 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. + * * @var string */ public $label; @@ -102,7 +104,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess { * * @var string */ - public $description; + public $description = ''; /** * Field-type specific settings. @@ -112,7 +114,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess { * * @var array */ - public $settings; + public $settings = array(); /** * Flag indicating whether the field is required. @@ -123,7 +125,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess { * * @var bool */ - public $required; + public $required = FALSE; /** * Default field value. @@ -153,7 +155,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess { * * @var array */ - public $default_value; + public $default_value = array(); /** * The name of a callback function that returns default values. @@ -175,7 +177,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess { * * @var string */ - public $default_value_function; + public $default_value_function = ''; /** * The widget definition. @@ -193,7 +195,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess { * * @var array */ - public $widget; + public $widget = array(); /** * Flag indicating whether the instance is deleted. @@ -208,7 +210,7 @@ class FieldInstance extends ConfigEntityBase implements \ArrayAccess { * * @var bool */ - public $deleted; + public $deleted = FALSE; /** * The widget plugin used for this instance. @@ -264,17 +266,11 @@ public function __construct(array $values, $entity_type = 'field_instance') { throw new FieldException('Attempt to create an instance of an unspecified field.'); } - // Provide defaults. - $values += array( - 'label' => $values['field_name'], - 'description' => '', - 'required' => FALSE, - 'default_value' => array(), - 'default_value_function' => '', - 'settings' => array(), - 'widget' => array(), - 'deleted' => 0, - ); + // Set field label to field name if no value has been set. + if ($this->label == NULL) { + $this->label = $values['field_name']; + } + parent::__construct($values, $entity_type); }