diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php index f9db116..b1949de 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php @@ -157,14 +157,14 @@ public function defaultValuesForm(array &$form, array &$form_state) { /** * {@inheritdoc} */ - public function defaultValuesFormValidate(array &$form, array &$form_state) { + public function defaultValuesFormValidate(array $element, array &$form, array &$form_state) { return array(); } /** * {@inheritdoc} */ - public function defaultValuesFormSubmit(array &$form, array &$form_state) { + public function defaultValuesFormSubmit(array $element, array &$form, array &$form_state) { return array(); } 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 98e40c9..eeb06de 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 @@ -53,7 +53,7 @@ public function defaultValuesForm(array &$form, array &$form_state) { $entity = $form['#entity']; $default_value = $this->getFieldDefinition()->default_value; $field_name = $this->getFieldDefinition()->getFieldName(); - $default_widget = $this->defaultValueWidget(); + $widget = $this->defaultValueWidget(); $this->getFieldDefinition()->required = 0; @@ -75,22 +75,20 @@ public function defaultValuesForm(array &$form, array &$form_state) { '#parents' => array(), ); - return $element += $default_widget->form($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); + return $element += $widget->form($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); } /** * {@inheritdoc} */ - public function defaultValuesFormValidate(array &$form, array &$form_state) { + public function defaultValuesFormValidate(array $element, array &$form, array &$form_state) { $entity = $form['#entity']; - $default_widget = $this->defaultValueWidget(); + $widget = $this->defaultValueWidget(); $field_name = $this->getFieldDefinition()->getFieldName(); - $element = $form['instance']['default_value_widget']; - // Extract the 'default value'. $items = $entity->getNGEntity()->{$field_name}; - $default_widget->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); + $widget->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); $violations = $items->validate(); // Report errors. @@ -101,22 +99,20 @@ public function defaultValuesFormValidate(array &$form, array &$form_state) { field_form_set_state($element['#parents'], $field_name, Language::LANGCODE_NOT_SPECIFIED, $form_state, $field_state); // Assign reported errors to the correct form element. - $default_widget->flagErrors($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); + $widget->flagErrors($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); } } /** * {@inheritdoc} */ - public function defaultValuesFormSubmit(array &$form, array &$form_state) { + public function defaultValuesFormSubmit(array $element, array &$form, array &$form_state) { $entity = $form['#entity']; - $default_widget = $this->defaultValueWidget(); + $widget = $this->defaultValueWidget(); $field_name = $this->getFieldDefinition()->getFieldName(); - $element = $form['instance']['default_value_widget']; - // Extract field values. $items = $entity->getNGEntity()->{$field_name}; - $default_widget->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); + $widget->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); return $items->getValue() ?: NULL; } @@ -131,10 +127,10 @@ protected function defaultValueWidget() { // When field is hidden, use the default widget and store it in the form if (!$widget = $entity_form_display->getRenderer($field_name)) { $field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->getFieldDefinition()->getFieldType()); - $default_widget = \Drupal::service('plugin.manager.field.widget')->getDefinition($field_type['default_widget']); + $widget = \Drupal::service('plugin.manager.field.widget')->getDefinition($field_type['default_widget']); $configuration = array( 'field_definition' => $this->getFieldDefinition(), - 'settings' => $default_widget['settings'] + 'settings' => $widget['settings'] ); $widget = \Drupal::service('plugin.manager.field.widget')->createInstance($field_type['default_widget'], $configuration); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php index e4c16b1..e6aceee 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php @@ -95,8 +95,6 @@ public function instanceSettingsForm(array $form, array &$form_state); * Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow * administrators to configure instance-level default value. * - * @param array $element - * The default value form base element * @param array $form * The form where the settings form is being included in. * @param array $form_state @@ -113,6 +111,8 @@ public function defaultValuesForm(array &$form, array &$form_state); * Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow * administrators to configure instance-level default value. * + * @param array $element + * The default value form base element * @param array $form * The form where the settings form is being included in. * @param array $form_state @@ -121,7 +121,7 @@ public function defaultValuesForm(array &$form, array &$form_state); * @return array * The field instance default value. */ - public function defaultValuesFormValidate(array &$form, array &$form_state); + public function defaultValuesFormValidate(array $element, array &$form, array &$form_state); /** * Submits the default value widget for a given field instance. @@ -129,6 +129,8 @@ public function defaultValuesFormValidate(array &$form, array &$form_state); * Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow * administrators to configure instance-level default value. * + * @param array $element + * The default value form base element * @param array $form * The form where the settings form is being included in. * @param array $form_state @@ -137,6 +139,6 @@ public function defaultValuesFormValidate(array &$form, array &$form_state); * @return array * The field instance default value. */ - public function defaultValuesFormSubmit(array &$form, array &$form_state); + public function defaultValuesFormSubmit(array $element, array &$form, array &$form_state); } 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 2cb783c..59c02a7 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 @@ -140,10 +140,8 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac $form['instance']['settings'] = $this->getFieldItem($form['#entity'], $this->instance['field_name'])->instanceSettingsForm($form, $form_state); $form['instance']['settings']['#weight'] = 10; - // Add handling for default value if not provided by any other module. - if (field_behaviors_widget('default_value', $this->instance) == FIELD_BEHAVIOR_DEFAULT && empty($this->instance['default_value_function'])) { - $form['instance']['default_value_widget'] = $this->getDefaultValueWidget($form, $form_state); - } + // Add handling for default value. + $form['instance']['default_value_widget'] = $this->getFieldItem($form['#entity'], $this->instance['field_name'])->defaultValuesForm($form, $form_state); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( @@ -163,7 +161,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac */ public function validateForm(array &$form, array &$form_state) { if (isset($form['instance']['default_value_widget'])) { - $this->getFieldItem($form['#entity'], $this->instance['field_name'])->defaultValuesFormValidate($form, $form_state); + $this->getFieldItem($form['#entity'], $this->instance['field_name'])->defaultValuesFormValidate($form['instance']['default_value_widget'], $form, $form_state); } } @@ -173,7 +171,7 @@ public function validateForm(array &$form, array &$form_state) { public function submitForm(array &$form, array &$form_state) { // Handle the default value. if (isset($form['instance']['default_value_widget'])) { - $this->instance['default_value'] = $this->getFieldItem($form['#entity'], $this->instance['field_name'])->defaultValuesFormSubmit($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. @@ -200,14 +198,6 @@ public function delete(array &$form, array &$form_state) { } /** - * Builds the default value widget for a given field instance. - */ - protected function getDefaultValueWidget(array &$form, &$form_state) { - $element = $this->getFieldItem($form['#entity'], $this->instance['field_name'])->defaultValuesForm($form, $form_state); - return $element; - } - - /** * Returns a FieldItem object for an entity. * * @todo Remove when all entity types extend EntityNG.