Issue #2620364 by quietone, bburg, Jo Fitzgerald, Yogesh Pawar, amoebanath, phenaproxima, Gábor Hojtsy, catch: Variable to config: theme settings [d7]
parent
d15ee7148f
commit
80445bee8c
|
@ -44328,6 +44328,14 @@ $connection->insert('variable')
|
|||
'name' => 'theme_settings',
|
||||
'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;',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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
|
|
@ -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 [];
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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'));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue