diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 6a761a9..7c780f4 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -74,32 +74,32 @@ protected function init(array &$form_state, EntityInterface $entity) { * @see Drupal\Core\Entity\EntityFormController::build() */ public function form(array $form, array &$form_state, EntityInterface $entity) { + // Get the entity_form_display object for this form mode (operation). + $form_display = entity_get_render_form_display($entity, $this->operation); + + // Let modules alter the form display. + $form_display_context = array( + 'entity_type' => $entity->entityType(), + 'bundle' => $entity->bundle(), + 'form_mode' => $this->operation, + ); + drupal_alter('entity_form_display', $form_display, $form_display_context); + + // Persist the altered form display in $form_state so we can use it during + // validation and submit. + $form_state['form_display'] = $form_display; + // @todo Exploit the Field API to generate the default widgets for the // entity properties. $info = $entity->entityInfo(); if (!empty($info['fieldable'])) { - // Get the entity_form_display object for this form mode (operation). - $form_display = entity_get_render_form_display($entity, $this->operation); - - // Let modules alter the form display. - $form_display_context = array( - 'entity_type' => $entity->entityType(), - 'bundle' => $entity->bundle(), - 'form_mode' => $this->operation, - ); - drupal_alter('entity_form_display', $form_display, $form_display_context); - - // Persist the altered form display in $form_state so we can use it during - // validation and submit. - $form_state['form_display'] = $form_display; - field_attach_form($entity, $form, $form_state, $this->getFormLangcode($form_state)); + } - // Assign the weights configured in the form display. - foreach ($form_display->getComponents() as $name => $options) { - if (isset($form[$name])) { - $form[$name]['#weight'] = $options['weight']; - } + // Assign the weights configured in the form display. + foreach ($form_display->getComponents() as $name => $options) { + if (isset($form[$name])) { + $form[$name]['#weight'] = $options['weight']; } } diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php index 334f07a..f2e2e8d 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php @@ -23,32 +23,32 @@ class EntityFormControllerNG extends EntityFormController { * Overrides EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $entity) { + // Get the entity_form_display object for this form mode (operation). + $form_display = entity_get_render_form_display($entity, $this->operation); + + // Let modules alter the form display. + $form_display_context = array( + 'entity_type' => $entity->entityType(), + 'bundle' => $entity->bundle(), + 'form_mode' => $this->operation, + ); + drupal_alter('entity_form_display', $form_display, $form_display_context); + + // Persist the altered form display in $form_state so we can use it during + // validation and submit. + $form_state['form_display'] = $form_display; + // @todo Exploit the Field API to generate the default widgets for the // entity properties. $info = $entity->entityInfo(); if (!empty($info['fieldable'])) { - // Get the entity_form_display object for this form mode (operation). - $form_display = entity_get_render_form_display($entity, $this->operation); - - // Let modules alter the form display. - $form_display_context = array( - 'entity_type' => $entity->entityType(), - 'bundle' => $entity->bundle(), - 'form_mode' => $this->operation, - ); - drupal_alter('entity_form_display', $form_display, $form_display_context); - - // Persist the altered form display in $form_state so we can use it during - // validation and submit. - $form_state['form_display'] = $form_display; - field_attach_form($entity->getBCEntity(), $form, $form_state, $this->getFormLangcode($form_state)); + } - // Assign the weights configured in the form display. - foreach ($form_display->getComponents() as $name => $options) { - if (isset($form[$name])) { - $form[$name]['#weight'] = $options['weight']; - } + // Assign the weights configured in the form display. + foreach ($form_display->getComponents() as $name => $options) { + if (isset($form[$name])) { + $form[$name]['#weight'] = $options['weight']; } } diff --git a/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php b/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php index ea7433f..c69ed33 100644 --- a/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityFormDisplay.php @@ -29,7 +29,7 @@ * } * ) */ -class EntityFormDisplay extends EntityDisplayBase { +class EntityFormDisplay extends EntityDisplayBase implements \Serializable { /** * Overrides \Drupal\entity\EntityDisplayBase::__construct(). @@ -55,19 +55,9 @@ public function getWidget($field_name) { return $this->plugins[$field_name]; } - // Check if this field actually exists. - if ($instance = field_info_instance($this->targetEntityType, $field_name, $this->bundle)) { - // Try to get the widget configuration from the stored display properties. - if (!$configuration = $this->getComponent($field_name)) { - // We don't store hidden fields but we need to use the 'Hidden' widget - // for them. - $configuration = array( - 'type' => 'hidden', - 'settings' => array(), - 'weight' => 0, - ); - } - + // Instantiate the widget object from the stored display properties. + if ($configuration = $this->getComponent($field_name)) { + $instance = field_info_instance($this->targetEntityType, $field_name, $this->bundle); $widget = $this->pluginManager->getInstance(array( 'instance' => $instance, 'form_mode' => $this->originalMode, @@ -85,4 +75,23 @@ public function getWidget($field_name) { return $widget; } + /** + * {@inheritdoc} + */ + public function serialize() { + // Only store the definition, not external objects or derived data. + $data = $this->getExportProperties() + array('entityType' => $this->entityType()); + return serialize($data); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) { + $data = unserialize($serialized); + $entity_type = $data['entityType']; + unset($data['entityType']); + $this->__construct($data, $entity_type); + } + } diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index 8decc14..b508454 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -826,9 +826,6 @@ function _field_invoke_widget_target($form_display) { * @see field_form_set_state() */ function field_attach_form(EntityInterface $entity, &$form, &$form_state, $langcode = NULL, array $options = array()) { - // Enable BC if necessary. - $entity = $entity->getBCEntity(); - // Set #parents to 'top-level' by default. $form += array('#parents' => array()); @@ -1125,13 +1122,7 @@ function field_attach_form_validate(EntityInterface $entity, $form, &$form_state */ function field_attach_extract_form_values(EntityInterface $entity, $form, &$form_state, array $options = array()) { // Extract field values from submitted values. - if (isset($form_state['form_display'])) { - $form_display = $form_state['form_display']; - } - else { - // @todo Remove this hack when http://drupal.org/node/1856556 is fixed. - $form_display = $form_state['form_display'] = entity_get_form_display($entity->entityType(), $entity->entityType()); - } + $form_display = $form_state['form_display']; field_invoke_method('extractFormValues', _field_invoke_widget_target($form_display), $entity, $form, $form_state, $options); // Let other modules act on submitting the entity. 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 01cfbd1..d412a0d 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 @@ -90,7 +90,6 @@ public function getInstance(array $options) { $configuration += array( 'instance' => $instance, - 'form_mode' => $options['form_mode'], ); return $this->createInstance($plugin_id, $configuration); } diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index fa9ebd1..07a715b 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -1011,7 +1011,7 @@ function field_ui_field_edit_form_submit($form, &$form_state) { // Handle widget settings. $options = $entity_form_display->getComponent($instance['field_name']); - $options['settings'] = NestedArray::mergeDeep($options['settings'], $form_state['values']['instance']['widget']['settings']); + $options['settings'] = $form_state['values']['instance']['widget']['settings']; $entity_form_display->setComponent($instance['field_name'], $options)->save(); unset($form_state['values']['instance']['widget']);