Commit f3216900 authored by alexpott's avatar alexpott

Issue #3024460 by quietone, Gábor Hojtsy, masipila, heddn: Migrate D7 comment...

Issue #3024460 by quietone, Gábor Hojtsy, masipila, heddn: Migrate D7 comment type language settings
parent 982773de
id: d7_language_content_comment_settings
label: Drupal 7 language content comment settings
migration_tags:
- Drupal 7
- Configuration
- Multilingual
source:
plugin: d7_language_content_settings
constants:
target_type: comment
id_prefix: comment_node_
label_suffix: comment
process:
target_bundle:
-
plugin: concat
source:
- constants/id_prefix
- type
-
plugin: static_map
bypass: true
# The Forum module provides its own comment type (comment_forum), which we
# want to reuse if it exists.
map:
comment_node_forum: comment_forum
target_entity_type_id: constants/target_type
default_langcode:
-
plugin: static_map
source: language_content_type
map:
0: site_default
1: current_interface
2: current_interface
4: current_interface
default_value: NULL
-
plugin: skip_on_empty
method: row
language_alterable:
plugin: static_map
source: language_content_type
map:
0: false
1: true
2: true
4: true
third_party_settings/content_translation/enabled:
plugin: content_translation_enabled_setting
source:
- language_content_type
- entity_translation_entity_types
- constants/target_type
destination:
plugin: entity:language_content_settings
content_translation_update_definitions:
- comment
migration_dependencies:
required:
- d7_comment_type
<?php
namespace Drupal\language\Plugin\migrate\process;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Determines the content translation setting.
*
* The source value is an indexed array of three values:
* - The language content type, e.g. '1'
* - The entity_translation_entity_types, an array of entity types.
* - An entity type used with entity translation, e.g. comment.
*
* @MigrateProcessPlugin(
* id = "content_translation_enabled_setting"
* )
*/
class ContentTranslationEnabledSetting extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_array($value)) {
throw new MigrateException('Input should be an array');
}
list($language_content_type, $entity_translation_entity_types, $entity_type) = $value;
switch ($language_content_type) {
// In the case of being 0, it will be skipped. We are not actually setting
// a null value.
case 0;
$setting = NULL;
break;
case 1:
$setting = FALSE;
break;
case 2:
$setting = FALSE;
break;
case 4:
// If entity translation is enabled return the status of comment
// translations.
$setting = FALSE;
if (!empty($entity_translation_entity_types[$entity_type])) {
$setting = TRUE;
}
break;
default:
$setting = NULL;
break;
}
return $setting;
}
}
......@@ -50,6 +50,10 @@ public function prepareRow(Row $row) {
else {
$row->setSourceProperty('i18n_lock_node', 0);
}
// Get the entity translation entity settings.
$entity_translation_entity_types = $this->variableGet('entity_translation_entity_types', NULL);
$row->setSourceProperty('entity_translation_entity_types', $entity_translation_entity_types);
return parent::prepareRow($row);
}
......
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d7;
use Drupal\Core\Database\Database;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\migrate\Kernel\MigrateDumpAlterInterface;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests language content comment settings migration with no entity translation.
*
* @group migrate_drupal_7
*/
class MigrateLanguageContentCommentSettingsNoEntityTranslationTest extends MigrateDrupal7TestBase implements MigrateDumpAlterInterface {
/**
* {@inheritdoc}
*/
public static $modules = [
'comment',
'content_translation',
'language',
'node',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->migrateCommentTypes();
$this->executeMigration('d7_language_content_comment_settings');
}
/**
* {@inheritdoc}
*/
public static function migrateDumpAlter(KernelTestBase $test) {
// Disable comment entity translation.
$db = Database::getConnection('default', 'migrate');
$db->update('variable')
->condition('name', 'entity_translation_entity_types')
->fields([
'value' => 'a:4:{s:4:"node";s:4:"node";s:13:"taxonomy_term";i:0;s:7:"comment";i:0;s:4:"user";i:0;}',
])
->execute();
}
/**
* Tests migration of content language settings.
*/
public function testLanguageCommentSettings() {
// Article and Blog content type have multilingual settings of 'Enabled,
// with Translation'. Assert that comments are translatable and the default
// language is 'current_interface'.
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_article');
$this->assertSame('comment', $config->getTargetEntityTypeId());
$this->assertSame('comment_node_article', $config->getTargetBundle());
$this->assertSame('current_interface', $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
$third_party_settings = [
'content_translation' => [
'enabled' => FALSE,
],
];
$this->assertSame($third_party_settings, $config->get('third_party_settings'));
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_blog');
$this->assertSame('comment', $config->getTargetEntityTypeId());
$this->assertSame('comment_node_blog', $config->getTargetBundle());
$this->assertSame('current_interface', $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
$this->assertSame($third_party_settings, $config->get('third_party_settings'));
// Page content type has multilingual settings of 'Enabled'. Assert that
// comments are translatable and default language is 'current_interface'.
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_page');
$this->assertSame('comment', $config->getTargetEntityTypeId());
$this->assertSame('comment_node_page', $config->getTargetBundle());
$this->assertSame('current_interface', $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
$this->assertSame($third_party_settings, $config->get('third_party_settings'));
// Test content type has multilingual settings of 'Enabled, with field
// translation'.
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_test_content_type');
$this->assertSame('comment', $config->getTargetEntityTypeId());
$this->assertSame('comment_node_test_content_type', $config->getTargetBundle());
$this->assertSame('current_interface', $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
$third_party_settings = [
'content_translation' => [
'enabled' => FALSE,
],
];
$this->assertSame($third_party_settings, $config->get('third_party_settings'));
// Assert that non-translatable content is not translatable and the default
// language is 'site_default.
$not_translatable = [
'comment_node_book',
'comment_forum',
];
foreach ($not_translatable as $bundle) {
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', $bundle);
$this->assertTrue($config->isDefaultConfiguration());
$this->assertFalse($config->isLanguageAlterable());
$this->assertSame('site_default', $config->getDefaultLangcode(), "Default language is not 'site_default' for comment bundle $bundle");
}
}
}
<?php
namespace Drupal\Tests\language\Kernel\Migrate\d7;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of language comment settings.
*
* @group migrate_drupal_7
*/
class MigrateLanguageContentCommentSettingsTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'comment',
'content_translation',
'language',
'node',
'text',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->migrateCommentTypes();
$this->executeMigration('d7_language_content_comment_settings');
}
/**
* Tests migration of content language settings.
*/
public function testLanguageCommentSettings() {
// Article and Blog content type have multilingual settings of 'Enabled,
// with Translation'. Assert that comments are translatable and the default
// language is 'current_interface'.
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_article');
$this->assertSame('comment', $config->getTargetEntityTypeId());
$this->assertSame('comment_node_article', $config->getTargetBundle());
$this->assertSame('current_interface', $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
$third_party_settings = [
'content_translation' => [
'enabled' => FALSE,
],
];
$this->assertSame($third_party_settings, $config->get('third_party_settings'));
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_blog');
$this->assertSame('comment', $config->getTargetEntityTypeId());
$this->assertSame('comment_node_blog', $config->getTargetBundle());
$this->assertSame('current_interface', $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
$this->assertSame($third_party_settings, $config->get('third_party_settings'));
// Page content type has multilingual settings of 'Enabled'. Assert that
// comments are translatable and default language is 'current_interface'.
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_page');
$this->assertSame('comment', $config->getTargetEntityTypeId());
$this->assertSame('comment_node_page', $config->getTargetBundle());
$this->assertSame('current_interface', $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
$this->assertSame($third_party_settings, $config->get('third_party_settings'));
// Test content type has multilingual settings of 'Enabled, with field
// translation'.
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_test_content_type');
$this->assertSame('comment', $config->getTargetEntityTypeId());
$this->assertSame('comment_node_test_content_type', $config->getTargetBundle());
$this->assertSame('current_interface', $config->getDefaultLangcode());
$this->assertTrue($config->isLanguageAlterable());
$third_party_settings = [
'content_translation' => [
'enabled' => TRUE,
],
];
$this->assertSame($third_party_settings, $config->get('third_party_settings'));
// Assert that non-translatable content is not translatable and the default
// language is 'site_default.
$not_translatable = [
'comment_node_book',
'comment_forum',
];
foreach ($not_translatable as $bundle) {
$config = ContentLanguageSettings::loadByEntityTypeBundle('comment', $bundle);
$this->assertTrue($config->isDefaultConfiguration());
$this->assertFalse($config->isLanguageAlterable());
$this->assertSame('site_default', $config->getDefaultLangcode(), "Default language is not 'site_default' for comment bundle $bundle");
}
}
}
......@@ -40,8 +40,14 @@ public function testLanguageContent() {
$this->assertFalse($config->get('language_alterable'));
$this->assertTrue($config->get('third_party_settings.content_translation.enabled'));
// Assert that a non-translatable content is not translatable.
// Assert that a translatable content is translatable.
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'page');
$this->assertFalse($config->isDefaultConfiguration());
$this->assertTrue($config->isLanguageAlterable());
$this->assertSame($config->getDefaultLangcode(), 'current_interface');
// Assert that a non-translatable content is not translatable.
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'forum');
$this->assertTrue($config->isDefaultConfiguration());
$this->assertFalse($config->isLanguageAlterable());
$this->assertSame($config->getDefaultLangcode(), 'site_default');
......
......@@ -54608,7 +54608,7 @@
))
->values(array(
'name' => 'language_content_type_page',
'value' => 's:1:"0";',
'value' => 's:1:"1";',
))
->values(array(
'name' => 'language_content_type_test_content_type',
......@@ -77,7 +77,7 @@ protected function getEntityCounts() {
'file' => 3,
'filter_format' => 7,
'image_style' => 6,
'language_content_settings' => 6,
'language_content_settings' => 11,
'node' => 6,
'node_type' => 6,
'rdf_mapping' => 8,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment