summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-04-28 14:27:52 (GMT)
committerNathaniel Catchpole2017-04-28 14:27:52 (GMT)
commit80445bee8c48fb32e18d552406c736ffe59e467f (patch)
treecf9546b7d7c3b2b6435c7dbc0c0ee9eeaa31adf7
parentd15ee7148f6f6eef3e15f4b541fa71d812134606 (diff)
Issue #2620364 by quietone, bburg, Jo Fitzgerald, Yogesh Pawar, amoebanath, phenaproxima, Gábor Hojtsy, catch: Variable to config: theme settings [d7]
-rw-r--r--core/modules/migrate_drupal/tests/fixtures/drupal7.php8
-rw-r--r--core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php4
-rw-r--r--core/modules/system/migration_templates/d7_theme_settings.yml44
-rw-r--r--core/modules/system/src/Plugin/migrate/destination/d7/ThemeSettings.php94
-rw-r--r--core/modules/system/src/Plugin/migrate/source/d7/ThemeSettings.php44
-rw-r--r--core/modules/system/tests/src/Kernel/Migrate/d7/MigrateThemeSettingsTest.php59
-rw-r--r--core/modules/system/tests/src/Kernel/Plugin/migrate/source/d7/ThemeSettingsTest.php65
7 files changed, 318 insertions, 0 deletions
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
index 1831171..78fb095 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
@@ -44329,6 +44329,14 @@ $connection->insert('variable')
'value' => 'a:16:{s:11:"toggle_logo";i:0;s:11:"toggle_name";i:1;s:13:"toggle_slogan";i:0;s:24:"toggle_node_user_picture";i:0;s:27:"toggle_comment_user_picture";i:0;s:32:"toggle_comment_user_verification";i:0;s:14:"toggle_favicon";i:0;s:16:"toggle_main_menu";i:0;s:21:"toggle_secondary_menu";i:0;s:12:"default_logo";i:1;s:9:"logo_path";s:23:"public://customlogo.png";s:11:"logo_upload";s:0:"";s:15:"default_favicon";i:0;s:12:"favicon_path";s:24:"public://somefavicon.png";s:14:"favicon_upload";s:0:"";s:16:"favicon_mimetype";s:9:"image/png";}',
))
->values(array(
+ 'name' => 'theme_bartik_settings',
+ 'value' => 'a:18:{s:11:"toggle_logo";i:1;s:11:"toggle_name";i:1;s:13:"toggle_slogan";i:1;s:24:"toggle_node_user_picture";i:1;s:27:"toggle_comment_user_picture";i:1;s:32:"toggle_comment_user_verification";i:1;s:14:"toggle_favicon";i:1;s:16:"toggle_main_menu";i:1;s:21:"toggle_secondary_menu";i:1;s:12:"default_logo";i:0;s:9:"logo_path";s:16:"public://gnu.png";s:15:"default_favicon";i:1;s:12:"favicon_path";s:0:"";s:14:"favicon_upload";s:0:"";s:6:"scheme";s:7:"default";s:7:"palette";a:9:{s:3:"top";s:7:"#0779bf";s:6:"bottom";s:7:"#48a9e4";s:2:"bg";s:7:"#ffffff";s:7:"sidebar";s:7:"#f6f6f2";s:14:"sidebarborders";s:7:"#f9f9f9";s:6:"footer";s:7:"#292929";s:11:"titleslogan";s:7:"#fffeff";s:4:"text";s:7:"#3b3b3b";s:4:"link";s:7:"#0071B3";}s:5:"theme";s:6:"bartik";s:4:"info";a:12:{s:6:"fields";a:9:{s:3:"top";s:10:"Header top";s:6:"bottom";s:13:"Header bottom";s:2:"bg";s:15:"Main background";s:7:"sidebar";s:18:"Sidebar background";s:14:"sidebarborders";s:15:"Sidebar borders";s:6:"footer";s:17:"Footer background";s:11:"titleslogan";s:16:"Title and slogan";s:4:"text";s:10:"Text color";s:4:"link";s:10:"Link color";}s:7:"schemes";a:6:{s:7:"default";a:2:{s:5:"title";s:21:"Blue Lagoon (default)";s:6:"colors";a:9:{s:3:"top";s:7:"#0779bf";s:6:"bottom";s:7:"#48a9e4";s:2:"bg";s:7:"#ffffff";s:7:"sidebar";s:7:"#f6f6f2";s:14:"sidebarborders";s:7:"#f9f9f9";s:6:"footer";s:7:"#292929";s:11:"titleslogan";s:7:"#fffeff";s:4:"text";s:7:"#3b3b3b";s:4:"link";s:7:"#0071B3";}}s:9:"firehouse";a:2:{s:5:"title";s:9:"Firehouse";s:6:"colors";a:9:{s:3:"top";s:7:"#cd2d2d";s:6:"bottom";s:7:"#cf3535";s:2:"bg";s:7:"#ffffff";s:7:"sidebar";s:7:"#f1f4f0";s:14:"sidebarborders";s:7:"#ededed";s:6:"footer";s:7:"#1f1d1c";s:11:"titleslogan";s:7:"#fffeff";s:4:"text";s:7:"#3b3b3b";s:4:"link";s:7:"#d6121f";}}s:3:"ice";a:2:{s:5:"title";s:3:"Ice";s:6:"colors";a:9:{s:3:"top";s:7:"#d0d0d0";s:6:"bottom";s:7:"#c2c4c5";s:2:"bg";s:7:"#ffffff";s:7:"sidebar";s:7:"#ffffff";s:14:"sidebarborders";s:7:"#cccccc";s:6:"footer";s:7:"#24272c";s:11:"titleslogan";s:7:"#000000";s:4:"text";s:7:"#4a4a4a";s:4:"link";s:7:"#019dbf";}}s:4:"plum";a:2:{s:5:"title";s:4:"Plum";s:6:"colors";a:9:{s:3:"top";s:7:"#4c1c58";s:6:"bottom";s:7:"#593662";s:2:"bg";s:7:"#fffdf7";s:7:"sidebar";s:7:"#edede7";s:14:"sidebarborders";s:7:"#e7e7e7";s:6:"footer";s:7:"#2c2c28";s:11:"titleslogan";s:7:"#ffffff";s:4:"text";s:7:"#301313";s:4:"link";s:7:"#9d408d";}}s:5:"slate";a:2:{s:5:"title";s:5:"Slate";s:6:"colors";a:9:{s:3:"top";s:7:"#4a4a4a";s:6:"bottom";s:7:"#4e4e4e";s:2:"bg";s:7:"#ffffff";s:7:"sidebar";s:7:"#ffffff";s:14:"sidebarborders";s:7:"#d0d0d0";s:6:"footer";s:7:"#161617";s:11:"titleslogan";s:7:"#ffffff";s:4:"text";s:7:"#3b3b3b";s:4:"link";s:7:"#0073b6";}}s:0:"";a:2:{s:5:"title";s:6:"Custom";s:6:"colors";a:0:{}}}s:3:"css";a:1:{i:0;s:14:"css/colors.css";}s:4:"copy";a:1:{i:0;s:8:"logo.png";}s:9:"gradients";a:1:{i:0;a:3:{s:9:"dimension";a:4:{i:0;i:0;i:1;i:0;i:2;i:0;i:3;i:0;}s:9:"direction";s:8:"vertical";s:6:"colors";a:2:{i:0;s:3:"top";i:1;s:6:"bottom";}}}s:4:"fill";a:0:{}s:6:"slices";a:0:{}s:12:"blend_target";s:7:"#ffffff";s:11:"preview_css";s:17:"color/preview.css";s:10:"preview_js";s:16:"color/preview.js";s:12:"preview_html";s:18:"color/preview.html";s:10:"base_image";s:14:"color/base.png";}}',
+))
+->values(array(
+ 'name' => 'theme_seven_settings',
+ 'value' => 'a:15:{s:11:"toggle_logo";i:1;s:11:"toggle_name";i:1;s:13:"toggle_slogan";i:1;s:24:"toggle_node_user_picture";i:1;s:27:"toggle_comment_user_picture";i:0;s:32:"toggle_comment_user_verification";i:1;s:14:"toggle_favicon";i:1;s:16:"toggle_main_menu";i:1;s:21:"toggle_secondary_menu";i:0;s:12:"default_logo";i:1;s:9:"logo_path";s:0:"";s:11:"logo_upload";s:0:"";s:15:"default_favicon";i:1;s:12:"favicon_path";s:0:"";s:14:"favicon_upload";s:0:"";}',
+))
+->values(array(
'name' => 'tracker_batch_size',
'value' => 'i:999;',
))
diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
index 29b1484..26304a1 100644
--- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
+++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
@@ -590,6 +590,10 @@ class MigrateUpgradeForm extends ConfirmFormBase {
'source_module' => 'profile',
'destination_module' => 'user',
],
+ 'd7_theme_settings' => [
+ 'source_module' => 'system',
+ 'destination_module' => 'system',
+ ],
'd6_user' => [
'source_module' => 'user',
'destination_module' => 'user',
diff --git a/core/modules/system/migration_templates/d7_theme_settings.yml b/core/modules/system/migration_templates/d7_theme_settings.yml
new file mode 100644
index 0000000..09f5fe1
--- /dev/null
+++ b/core/modules/system/migration_templates/d7_theme_settings.yml
@@ -0,0 +1,44 @@
+id: d7_theme_settings
+label: D7 theme settings
+migration_tags:
+ - Drupal 7
+source:
+ plugin: d7_theme_settings
+ constants:
+ config_suffix: '.settings'
+process:
+ # Build the configuration name from the variable name, i.e.
+ # theme_bartik_settings becomes bartik.settings.
+ theme_name:
+ -
+ plugin: explode
+ source: name
+ delimiter: _
+ -
+ plugin: extract
+ index:
+ - 1
+ configuration_name:
+ plugin: concat
+ source:
+ - '@theme_name'
+ - constants/config_suffix
+ toggle_logo: theme_settings/toggle_logo
+ toggle_name: value/toggle_name
+ toggle_slogan: value/toggle_slogan
+ toggle_node_user_picture: value/toggle_node_user_picture
+ toggle_comment_user_picture: value/toggle_comment_user_picture
+ toggle_comment_user_verification: value/toggle_comment_user_verification
+ toggle_favicon: value/toggle_favicon
+ default_logo: value/default_logo
+ logo_path: value/logo_path
+ logo_upload: value/logo_upload
+ default_favicon: value/default_favicon
+ favicon_path: value/favicon_path
+ favicon_mimetype: value/favicon_mimetype
+# Ignore settings not present in Drupal 8.
+# value/favicon_upload
+# value/toggle_main_menu
+# value/toggle_secondary_menu
+destination:
+ plugin: d7_theme_settings
diff --git a/core/modules/system/src/Plugin/migrate/destination/d7/ThemeSettings.php b/core/modules/system/src/Plugin/migrate/destination/d7/ThemeSettings.php
new file mode 100644
index 0000000..55ac721
--- /dev/null
+++ b/core/modules/system/src/Plugin/migrate/destination/d7/ThemeSettings.php
@@ -0,0 +1,94 @@
+<?php
+
+namespace Drupal\system\Plugin\migrate\destination\d7;
+
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\Core\Config\ConfigFactoryInterface;
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\migrate\Row;
+use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Persist theme settings to the config system.
+ *
+ * @MigrateDestination(
+ * id = "d7_theme_settings"
+ * )
+ */
+class ThemeSettings extends DestinationBase implements ContainerFactoryPluginInterface {
+
+ /**
+ * The configuration factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
+ * Constructs a theme settings destination object.
+ *
+ * @param array $configuration
+ * Plugin configuration.
+ * @param string $plugin_id
+ * The plugin ID.
+ * @param mixed $plugin_definition
+ * The plugin definition.
+ * @param \Drupal\migrate\Plugin\MigrationInterface $migration
+ * The current migration.
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The configuration factory.
+ */
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, ConfigFactoryInterface $config_factory) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
+ $this->configFactory = $config_factory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
+ return new static(
+ $configuration,
+ $plugin_id,
+ $plugin_definition,
+ $migration,
+ $container->get('config.factory')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function import(Row $row, array $old_destination_id_values = []) {
+ $imported = FALSE;
+ $config = $this->configFactory->getEditable($row->getDestinationProperty('configuration_name'));
+ $theme_settings = $row->getDestination();
+ // Remove keys not in theme settings.
+ unset($theme_settings['configuration_name']);
+ unset($theme_settings['theme_name']);
+ if (isset($theme_settings)) {
+ theme_settings_convert_to_config($theme_settings, $config);
+ $config->save();
+ $imported = TRUE;
+ }
+ return $imported;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIds() {
+ $ids['name']['type'] = 'string';
+ return $ids;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function fields(MigrationInterface $migration = NULL) {
+ // Theme settings vary by theme, so no specific fields are defined.
+ return [];
+ }
+
+}
diff --git a/core/modules/system/src/Plugin/migrate/source/d7/ThemeSettings.php b/core/modules/system/src/Plugin/migrate/source/d7/ThemeSettings.php
new file mode 100644
index 0000000..5561a9a
--- /dev/null
+++ b/core/modules/system/src/Plugin/migrate/source/d7/ThemeSettings.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Drupal\system\Plugin\migrate\source\d7;
+
+use Drupal\migrate_drupal\Plugin\migrate\source\VariableMultiRow;
+
+/**
+ * Drupal 7 system source from database.
+ *
+ * @MigrateSource(
+ * id = "d7_theme_settings",
+ * source_provider = "system"
+ * )
+ */
+class ThemeSettings extends VariableMultiRow {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function query() {
+ return $this->select('variable', 'v')
+ ->fields('v', ['name', 'value'])
+ ->condition('name', 'theme_%_settings', 'LIKE');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function fields() {
+ return [
+ 'name' => $this->t('Theme settings variable for a theme.'),
+ 'value' => $this->t('The theme settings variable value.'),
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getIds() {
+ $ids['name']['type'] = 'string';
+ return $ids;
+ }
+
+}
diff --git a/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateThemeSettingsTest.php b/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateThemeSettingsTest.php
new file mode 100644
index 0000000..08f70cf
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/Migrate/d7/MigrateThemeSettingsTest.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Drupal\Tests\system\Kernel\Migrate\d7;
+
+use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
+
+/**
+ * Tests migration of Theme settings variables to configuration.
+ *
+ * @group system
+ */
+class MigrateThemeSettingsTest extends MigrateDrupal7TestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ // Install bartik theme.
+ \Drupal::service('theme_handler')->install(['bartik']);
+ // Install seven theme.
+ \Drupal::service('theme_handler')->install(['seven']);
+ $this->executeMigration('d7_theme_settings');
+ }
+
+ /**
+ * Tests migration of theme settings to variables to configuration.
+ */
+ public function testMigrateThemeSettings() {
+ $config = $this->config('bartik.settings');
+
+ $this->assertSame('', $config->get('favicon.path'));
+ $this->assertTrue($config->get('favicon.use_default'));
+ $this->assertTrue($config->get('features.comment_user_picture'));
+ $this->assertTrue($config->get('features.comment_user_verification'));
+ $this->assertTrue($config->get('features.favicon'));
+ $this->assertTrue($config->get('features.node_user_picture'));
+ $this->assertFalse($config->get('features.logo'));
+ $this->assertTrue($config->get('features.name'));
+ $this->assertTrue($config->get('features.slogan'));
+ $this->assertSame('public://gnu.png', $config->get('logo.path'));
+ $this->assertFalse($config->get('logo.use_default'));
+
+ $config = $this->config('seven.settings');
+ $this->assertSame('', $config->get('favicon.path'));
+ $this->assertTrue($config->get('favicon.use_default'));
+ $this->assertFalse($config->get('features.comment_user_picture'));
+ $this->assertTrue($config->get('features.comment_user_verification'));
+ $this->assertTrue($config->get('features.favicon'));
+ $this->assertTrue($config->get('features.node_user_picture'));
+ $this->assertFalse($config->get('features.logo'));
+ $this->assertTrue($config->get('features.name'));
+ $this->assertTrue($config->get('features.slogan'));
+ $this->assertSame('', $config->get('logo.path'));
+ $this->assertTrue($config->get('logo.use_default'));
+ }
+
+}
diff --git a/core/modules/system/tests/src/Kernel/Plugin/migrate/source/d7/ThemeSettingsTest.php b/core/modules/system/tests/src/Kernel/Plugin/migrate/source/d7/ThemeSettingsTest.php
new file mode 100644
index 0000000..17b54fa
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/Plugin/migrate/source/d7/ThemeSettingsTest.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace Drupal\Tests\system\Kernel\Plugin\migrate\source\d7;
+
+use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
+
+/**
+ * Tests D7 theme settings source plugin.
+ *
+ * @covers Drupal\system\Plugin\migrate\source\d7\ThemeSettings
+ *
+ * @group system
+ */
+class ThemeSettingsTest extends MigrateSqlSourceTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['system', 'migrate_drupal'];
+
+ /**
+ * {@inheritdoc}
+ */
+ public function providerSource() {
+ $tests = [];
+
+ // The source data.
+ $value = [
+ 'toggle_logo' => 1,
+ 'toggle_name' => 1,
+ 'toggle_slogan' => 1,
+ 'toggle_node_user_picture' => 1,
+ 'toggle_comment_user_picture' => 1,
+ 'toggle_comment_user_verification' => 1,
+ 'toggle_favicon' => 1,
+ 'toggle_main_menu' => 1,
+ 'toggle_secondary_menu' => 1,
+ 'default_logo' => 1,
+ 'logo_path' => ' ',
+ 'logo_upload' => ' ',
+ 'default_favicon' => 1,
+ 'favicon_path' => ' ',
+ 'favicon_upload' => ' ',
+ 'scheme' => 'firehouse',
+ ];
+
+ $tests[0]['source_data']['variable'] = [
+ [
+ 'name' => 'theme_bartik_settings',
+ 'value' => serialize($value),
+ ],
+ ];
+
+ // The expected results are nearly identical to the source data.
+ $tests[0]['expected_data'] = [
+ [
+ 'name' => 'theme_bartik_settings',
+ 'value' => $value,
+ ],
+ ];
+
+ return $tests;
+ }
+
+}