diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php index fbe028d..66df59d 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php @@ -121,7 +121,7 @@ public function defaultValuesFormSubmit(array $element, array &$form, array &$fo * Returns the widget object used in default value form. * * @param array $form_state - * The form_state array + * The form_state array. * * @return \Drupal\field\Plugin\Type\Widget\WidgetInterface * A Widget object. @@ -132,12 +132,15 @@ protected function defaultValueWidget(array &$form_state) { $entity = $this->getParent()->getParent(); $entity_form_display = entity_get_form_display($entity->entityType(), $entity->bundle(), 'default'); - // When field is hidden, use the default widget and store it in the form - if (!$form_state['default_value_widget'] = $entity_form_display->getRenderer($field_name)) { - $form_state['default_value_widget'] = \Drupal::service('plugin.manager.field.widget')->getInstance(array('field_definition' => $this->getFieldDefinition())); + $widget = $entity_form_display->getRenderer($field_name); + // When field is hidden, use the default widget and store it in the form. + if (!$widget) { + $widget = \Drupal::service('plugin.manager.field.widget')->getInstance(array('field_definition' => $this->getFieldDefinition())); } + $form_state['default_value_widget'] = $widget; } return $form_state['default_value_widget']; } + } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php index cf7332c..0fe4be9 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php @@ -87,12 +87,18 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac * A Widget object. */ public function getInstance(array $options) { - $configuration = isset($options['configuration']) ? $options['configuration'] : array(); + // Fill in defaults for missing properties. + $options += array( + 'configuration' => array(), + 'prepare' => TRUE, + ); + + $configuration = $options['configuration']; $field_definition = $options['field_definition']; $field_type = $field_definition->getFieldType(); // Fill in default configuration if needed. - if (!isset($options['prepare']) || $options['prepare'] == TRUE) { + if ($options['prepare']) { $configuration = $this->prepareConfiguration($field_type, $configuration); } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php index ec9f906..4c69088 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php @@ -160,7 +160,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac * {@inheritdoc} */ public function validateForm(array &$form, array &$form_state) { - $this->getFieldItem($form['#entity'], $this->instance['field_name'])->defaultValuesFormValidate($form['instance']['default_value_widget'], $form, $form_state); + $this->getFieldItem($form['#entity'], $this->instance['field_name'])->defaultValuesFormValidate($form['instance']['default_value_widget'], $form, $form_state); } /** @@ -168,7 +168,7 @@ public function validateForm(array &$form, array &$form_state) { */ public function submitForm(array &$form, array &$form_state) { // Handle the default value. - $this->instance['default_value'] = $this->getFieldItem($form['#entity'], $this->instance['field_name'])->defaultValuesFormSubmit($form['instance']['default_value_widget'], $form, $form_state); + $this->instance['default_value'] = $this->getFieldItem($form['#entity'], $this->instance['field_name'])->defaultValuesFormSubmit($form['instance']['default_value_widget'], $form, $form_state); // Merge incoming values into the instance. foreach ($form_state['values']['instance'] as $key => $value) {