diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index 96031c5..7a9c8a8 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -14,9 +14,8 @@ * Implements hook_entity_bundle_rename(). */ function entity_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { - $entity_info = entity_get_info('entity_display'); - // Rename entity displays. + $entity_info = entity_get_info('entity_display'); if ($bundle_old !== $bundle_new) { $ids = config_get_storage_names_with_prefix('entity.display.' . $entity_type . '.' . $bundle_old); foreach ($ids as $id) { @@ -30,6 +29,7 @@ function entity_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { } // Rename entity form displays. + $entity_info = entity_get_info('entity_form_display'); if ($bundle_old !== $bundle_new) { $ids = config_get_storage_names_with_prefix('entity.form_display.' . $entity_type . '.' . $bundle_old); foreach ($ids as $id) { diff --git a/core/modules/field/field.install b/core/modules/field/field.install index 1d8e1de..0a8ac9e 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -285,7 +285,7 @@ function field_update_8002() { // Determine name and create initial entry in the $form_displays array. $form_display_id = $record->entity_type . '.' . $record->bundle . '.default'; if (!isset($form_displays[$form_display_id])) { - $form_displays[$form_display_id] = _update_8000_entity_get_display($record->entity_type, $record->bundle, 'default'); + $form_displays[$form_display_id] = _update_8000_entity_get_form_display($record->entity_type, $record->bundle, 'default'); } // We do not need the 'module' key anymore. @@ -334,11 +334,11 @@ function field_update_8002() { foreach ($variable_value['extra_fields']['form'] as $field_name => $field_settings) { // Determine name and create initial entry in the $form_displays // array if it does not exist yet. - $form_display_id = $record->entity_type . '.' . $record->bundle . '.default'; + $form_display_id = $entity_type . '.' . $bundle . '.default'; if (!isset($form_displays[$form_display_id])) { - $form_displays[$form_display_id] = _update_8000_entity_get_form_display($record->entity_type, $record->bundle, 'default'); + $form_displays[$form_display_id] = _update_8000_entity_get_form_display($entity_type, $bundle, 'default'); } - $form_displays[$form_display_id]->set("content.$field_name", $variable_value['extra_fields']['form']); + $form_displays[$form_display_id]->set("content.$field_name", $field_settings); } // Remove the old entry. diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index 02c406d..5d9a0c5 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -20,7 +20,7 @@ class FieldOverview extends OverviewBase { public function __construct($entity_type, $bundle, $view_mode = NULL) { $this->entity_type = $entity_type; $this->bundle = $bundle; - $this->view_mode = 'form'; + $this->view_mode = 'default'; $this->adminPath = field_ui_bundle_admin_path($this->entity_type, $this->bundle); } @@ -63,7 +63,7 @@ public function buildForm(array $form, array &$form_state) { $field_types = field_info_field_types(); $widget_types = field_info_widget_types(); $extra_fields = field_info_extra_fields($this->entity_type, $this->bundle, 'form'); - $entity_form_display = entity_get_form_display($this->entity_type, $this->bundle); + $entity_form_display = entity_get_form_display($this->entity_type, $this->bundle, $this->view_mode); $form += array( '#entity_type' => $this->entity_type, @@ -530,6 +530,26 @@ protected function validateAddExisting(array $form, array &$form_state) { */ public function submitForm(array &$form, array &$form_state) { $form_values = $form_state['values']['fields']; + $entity_form_display = entity_get_form_display($this->entity_type, $this->bundle, $this->view_mode); + + // Collect data for 'regular' fields. + foreach ($form['#fields'] as $field_name) { + $options = $entity_form_display->getComponent($field_name); + $options['weight'] = $form_values[$field_name]['weight']; + + $entity_form_display->setComponent($field_name, $options); + } + + // Collect data for 'extra' fields. + foreach ($form['#extra'] as $field_name) { + $entity_form_display->setComponent($field_name, array( + 'weight' => $form_values[$field_name]['weight'], + )); + } + + // Save the form display. + $entity_form_display->save(); + $destinations = array(); // Create new field. diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php index 38c57d6..6bc2bd0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php @@ -88,6 +88,51 @@ public function testEntityDisplayUpgrade() { } /** + * Tests upgrade of entity form displays. + */ + public function testEntityFormDisplayUpgrade() { + $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + + // Check that the configuration entries were created. + $displays = array( + 'default' => config('entity.form_display.node.article.default')->get(), + ); + $this->assertTrue(!empty($displays['default'])); + + // Check that manifest entries for the 'article' node type were correctly + // created. + $manifest = config('manifest.entity.form_display'); + $data = $manifest->get(); + $this->assertEqual($data['node.article.default'], array('name' => 'entity.form_display.node.article.default')); + + // Check that the 'body' field is configured as expected. + $expected = array( + 'default' => array( + 'type' => 'text_textarea_with_summary', + 'weight' => -4, + 'settings' => array( + 'rows' => '20', + 'summary_rows' => '5', + ), + ), + ); + $this->assertEqual($displays['default']['content']['body'], $expected['default']); + + // Check that the display key in the instance data was removed. + $body_instance = field_info_instance('node', 'body', 'article'); + $this->assertTrue(!isset($body_instance['form'])); + + // Check that the 'title' extra field is configured as expected. + $expected = array( + 'default' => array( + 'weight' => -5, + 'visible' => 1, + ), + ); + $this->assertEqual($displays['default']['content']['title'], $expected['default']); + } + + /** * Tests migration of field and instance definitions to config. */ function testFieldUpgradeToConfig() { @@ -149,15 +194,6 @@ function testFieldUpgradeToConfig() { 'text_processing' => 1, 'user_register_form' => FALSE, ), - 'widget' => array( - 'type' => 'text_textarea_with_summary', - 'module' => 'text', - 'settings' => array( - 'rows' => 20, - 'summary_rows' => 5, - ), - 'weight' => -4, - ), 'status' => 1, 'langcode' => 'und', )); diff --git a/core/modules/system/tests/upgrade/drupal-7.field.database.php b/core/modules/system/tests/upgrade/drupal-7.field.database.php index 9434c7c..baa5027 100644 --- a/core/modules/system/tests/upgrade/drupal-7.field.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.field.database.php @@ -28,7 +28,12 @@ ), ), 'extra_fields' => array( - 'form' => array(), + 'form' => array( + 'title' => array( + 'weight' => -5, + 'visible' => 1, + ), + ), 'display' => array( 'language' => array( 'default' => array(