diff --git a/core/modules/field/field.install b/core/modules/field/field.install index bc566d6..ce6bfa0 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -394,6 +394,66 @@ function field_update_8001() { } /** + * Migrate all instance display settings to configuration. + * + * @ingroup config_upgrade + */ +function field_update_8002() { + $displays = array(); + + $query = db_select('field_config_instance', 'fc')->fields('fc'); + foreach ($query->execute() as $record) { + + // Unserialize the data array and start investigating the display key + // which holds the configuration of this instance for all view modes. + $data = unserialize($record->data); + + // @todo Somehow, user picture field has no display key, + // check with user picture field upgrade path. + if (!isset($data['display'])) { + continue; + } + + foreach ($data['display'] as $view_mode => $configuration) { + + // Determine name and create initial entry in the $displays array if + // it does not exist yet. + $name = 'field.entity_display.' . $record->entity_type . '.' . $record->bundle . '.' . $view_mode; + if (!isset($displays[$name])) { + $displays[$name] = array( + 'id' => $record->entity_type . '.' . $record->bundle . '.' . $view_mode, + 'targetEntityType' => $record->entity_type, + 'bundle' => $record->bundle, + 'viewMode' => $view_mode, + 'content' => array(), + ); + } + + // Add field configuration of this view mode to the content key + // of the display, but only if the formatter type is not set to hidden. + // We do not store hidden fields on the new display object. + if ($configuration['type'] != 'hidden') { + $displays[$name]['content'][$record->field_name] = $configuration; + } + } + + // Remove the display key from the configuration and save the instance + // back into the table. + unset($data['display']); + db_update('field_config_instance') + ->condition('id', $record->id) + ->fields(array( + 'data' => serialize($data), + )) + ->execute(); + } + + foreach ($displays as $name => $configuration) { + config($name)->setData($configuration)->save(); + } +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php new file mode 100644 index 0000000..ba3b772 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php @@ -0,0 +1,45 @@ + 'Field upgrade test', + 'description' => 'Tests upgrade of Field API.', + 'group' => 'Upgrade path', + ); + } + + public function setUp() { + $this->databaseDumpFiles = array( + drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz', + ); + parent::setUp(); + } + + /** + * Tests upgrade of entity displays. + */ + public function testEntityDisplayUpgrade() { + $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.'); + + // Verify that entity display config was created. + // entity_get_display() creates a display if the the one we ask does not + // exist, so use entity_load() instead. + $this->assertTrue(entity_load('entity_display', 'node.article.default')); + $this->assertTrue(entity_load('entity_display', 'node.article.teaser')); + + // Verify that display key in the instance data was removed. + $body_instance = field_info_instance('node', 'body', 'article'); + $this->assertTrue(!isset($body_instance['display'])); + } +} diff --git a/core/update.php b/core/update.php index 8563657..fcad34e 100644 --- a/core/update.php +++ b/core/update.php @@ -477,6 +477,8 @@ function update_check_requirements($skip_warnings = FALSE) { ->addArgument(new Reference('router.dumper')) ->addArgument(new Reference('lock')) ->addArgument(new Reference('dispatcher')); +$container->register('plugin.manager.field.widget', 'Drupal\field\Plugin\Type\Widget\WidgetPluginManager'); +$container->register('plugin.manager.field.formatter', 'Drupal\field\Plugin\Type\Formatter\FormatterPluginManager'); // Turn error reporting back on. From now on, only fatal errors (which are // not passed through the error handler) will cause a message to be printed.