diff --git a/core/modules/comment/src/Plugin/migrate/destination/EntityComment.php b/core/modules/comment/src/Plugin/migrate/destination/EntityComment.php index e3582c5..8701631 100644 --- a/core/modules/comment/src/Plugin/migrate/destination/EntityComment.php +++ b/core/modules/comment/src/Plugin/migrate/destination/EntityComment.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Field\FieldTypePluginManagerInterface; +use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\State\StateInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; @@ -41,6 +42,11 @@ class EntityComment extends EntityContentBase { protected $stubCommentedEntityIds; /** + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $language_manager; + + /** * Builds an comment entity destination. * * @param array $configuration @@ -55,6 +61,8 @@ class EntityComment extends EntityContentBase { * The storage for this entity type. * @param array $bundles * The list of bundles this entity type has. + * @param LanguageManagerInterface $language_manager + * The language manager. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager @@ -64,10 +72,11 @@ class EntityComment extends EntityContentBase { * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query * The query object that can query the given entity type. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state, QueryFactory $entity_query) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager); + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state, QueryFactory $entity_query) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $language_manager, $entity_manager, $field_type_manager); $this->state = $state; $this->entityQuery = $entity_query; + $this->language_manager = $language_manager; } /** @@ -81,7 +90,9 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $migration, $container->get('entity.manager')->getStorage($entity_type), - array_keys($container->get('entity.manager')->getBundleInfo($entity_type)), + array_keys($container->get('entity.manager') + ->getBundleInfo($entity_type)), + $container->get('language_manager'), $container->get('entity.manager'), $container->get('plugin.manager.field.field_type'), $container->get('state'), diff --git a/core/modules/config_translation/migration_templates/d6_i18n_block.yml b/core/modules/config_translation/migration_templates/d6_i18n_block.yml new file mode 100644 index 0000000..d9ad6c0 --- /dev/null +++ b/core/modules/config_translation/migration_templates/d6_i18n_block.yml @@ -0,0 +1,70 @@ +id: d6_i18n_block +label: i18n Blocks +migration_tags: + - Drupal 6 +source: + plugin: d6_i18n_block + constants: + dest_label: 'settings/label' +process: + langcode: language + property: constants/dest_label + translation: translation + id: + - + plugin: concat + source: + - module + - objectid + delimiter: _ + - + plugin: substr + length: 32 + plugin: + - + plugin: static_map + bypass: true + source: + - module + - delta + map: + book: + 0: book_navigation + comment: + 0: views_block:comments_recent-block_1 + forum: + 0: forum_active_block + 1: forum_new_block + locale: + 0: language_block + node: + 0: node_syndicate_block + search: + 0: search_form_block + statistics: + 0: statistics_popular_block + system: + 0: system_powered_by_block + user: + 0: user_login_block + 1: system_menu_block:tools + 2: views_block:who_s_new-block_1 + 3: views_block:who_s_online-who_s_online_block + - + plugin: block_plugin_id + - + plugin: skip_on_empty + method: row + theme: + plugin: block_theme + source: + - theme + - default_theme + - admin_theme +destination: + plugin: entity:block +migration_dependencies: + required: + - d6_block + + diff --git a/core/modules/config_translation/src/Plugin/migrate/process/I18nBlockSettings.php b/core/modules/config_translation/src/Plugin/migrate/process/I18nBlockSettings.php new file mode 100644 index 0000000..fbdd6d9 --- /dev/null +++ b/core/modules/config_translation/src/Plugin/migrate/process/I18nBlockSettings.php @@ -0,0 +1,35 @@ +getModuleSchemaVersion('system') >= 7000) { + $this->blockTable = 'block'; + } + else { + $this->blockTable = 'blocks'; + } + $query = $this->select('i18n_strings', 'i18n') + ->fields('i18n', ['lid', 'type', 'property', 'objectid']) + ->fields('lt', ['lid', 'language', 'translation']) + ->fields('b', ['bid', 'module', 'delta', 'theme']) + ->condition('i18n.type', 'block'); + $query->leftJoin($this->blockTable, 'b', 'b.bid = i18n.objectid'); + $query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid'); + return $query; + } + + /** + * {@inheritdoc} + */ + protected function initializeIterator() { + $this->defaultTheme = $this->variableGet('theme_default', 'Garland'); + $this->adminTheme = $this->variableGet('admin_theme', null); + return parent::initializeIterator(); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return [ + 'bid' => $this->t('The block numeric identifier.'), + 'module' => $this->t('The module providing the block.'), + 'delta' => $this->t('The block\'s delta.'), + 'theme' => $this->t('Which theme the block is placed in.'), + 'language' => $this->t('Language for this field.'), + 'property' => $this->t('Name of property being translated.'), + 'translation' => $this->t('Translation of either the title or explanation.' + )]; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['module']['type'] = 'string'; + $ids['delta']['type'] = 'string'; + $ids['theme']['type'] = 'string'; + $ids['language']['type'] = 'string'; + return $ids; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $row->setSourceProperty('default_theme', $this->defaultTheme); + $row->setSourceProperty('admin_theme', $this->adminTheme); + return parent::prepareRow($row); + } +} diff --git a/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateI18nBlockTest.php b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateI18nBlockTest.php new file mode 100644 index 0000000..1f183e3 --- /dev/null +++ b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateI18nBlockTest.php @@ -0,0 +1,67 @@ +installConfig(['block_content']); + $this->installEntitySchema('block_content'); + + // Set Bartik and Seven as the default public and admin theme. + $config = $this->config('system.theme'); + $config->set('default', 'bartik'); + $config->set('admin', 'seven'); + $config->save(); + + // Install one of D8's test themes. + \Drupal::service('theme_handler')->install(['test_theme']); + + $this->executeMigrations([ + 'd6_filter_format', + 'block_content_type', + 'block_content_body_field', + 'menu', + 'd6_custom_block', + 'd6_user_role', + 'd6_block', + 'd6_i18n_block', + ]); + } + + /** + * Tests the migration of block title translation. + */ + public function testI18nBlock() { + $config = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'block.block.user'); + $this->assertSame('fr - Static Block', $config->get('settings.label')); + $config = \Drupal::service('language_manager')->getLanguageConfigOverride('fr', 'block.block.user_1'); + $this->assertSame('Encore un bloc statique', $config->get('settings.label')); + } + +} diff --git a/core/modules/config_translation/tests/src/Unit/Plugin/migrate/source/d6/I18nBlockSourceTest.php b/core/modules/config_translation/tests/src/Unit/Plugin/migrate/source/d6/I18nBlockSourceTest.php new file mode 100644 index 0000000..db614a4 --- /dev/null +++ b/core/modules/config_translation/tests/src/Unit/Plugin/migrate/source/d6/I18nBlockSourceTest.php @@ -0,0 +1,161 @@ + 'id', + 'source' => [ + 'plugin' => 'test', + ], + ]; + + protected $blocks = [ + [ + 'bid' => 1, + 'module' => 'block', + 'delta' => '1', + 'theme' => 'garland', + 'status' => 1, + 'weight' => 0, + 'region' => 'left', + 'custom' => 0, + 'throttle' => 0, + 'visibility' => 1, + 'pages' => '', + 'title' => 'Test Title 01', + 'cache' => -1, + ], + [ + 'bid' => 2, + 'module' => 'block', + 'delta' => '2', + 'theme' => 'garland', + 'status' => 1, + 'weight' => 5, + 'region' => 'right', + 'custom' => 0, + 'throttle' => 0, + 'visibility' => 0, + 'pages' => '', + 'title' => 'Test Title 02', + 'cache' => -1, + ], + ]; + + protected $i18n_strings = [ + [ + 'lid' => 1, + 'objectid' => 1, + 'type' => 'block', + 'property' => 'title', + 'objectindex' => 0, + 'format' => 0, + ], + [ + 'lid' => 2, + 'objectid' => 1, + 'type' => 'block', + 'property' => 'body', + 'objectindex' => 0, + 'format' => 0, + ], + [ + 'lid' => 3, + 'objectid' => 2, + 'type' => 'block', + 'property' => 'body', + 'objectindex' => 0, + 'format' => 2, + ] + ]; + + protected $locales_target = [ + [ + 'lid' => 1, + 'language' => 'fr', + 'translation' => 'fr - title translation', + 'plid' => 0, + 'plural' => 0, + 'u18n_status' => 0, + ], + [ + 'lid' => 2, + 'language' => 'fr', + 'translation' => 'fr - description translation', + 'plid' => 0, + 'plural' => 0, + 'u18n_status' => 0, + ], + [ + 'lid' => 3, + 'language' => 'zu', + 'translation' => 'zu - description translation', + 'plid' => 0, + 'plural' => 0, + 'u18n_status' => 0, + ], + ]; + + protected $expectedResults = [ + [ + 'lid' => '1', + 'type' => 'block', + 'property' => 'title', + 'objectid' => '1', + 'lt_lid' => '1', + 'language' => 'fr', + 'translation' => 'fr - title translation', + 'bid' => '1', + 'module' => 'block', + 'delta' => '1', + ], + [ + 'lid' => '2', + 'type' => 'block', + 'property' => 'body', + 'objectid' => '1', + 'lt_lid' => '2', + 'language' => 'fr', + 'translation' => 'fr - description translation', + 'bid' => '1', + 'module' => 'block', + 'delta' => '1', + ], + [ + 'lid' => '3', + 'type' => 'block', + 'property' => 'body', + 'objectid' => '2', + 'lt_lid' => '3', + 'language' => 'zu', + 'translation' => 'zu - description translation', + 'bid' => '2', + 'module' => 'block', + 'delta' => '2', + ], + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + $this->databaseContents['blocks'] = $this->blocks; + $this->databaseContents['i18n_strings'] = $this->i18n_strings; + $this->databaseContents['locales_target'] = $this->locales_target; + + parent::setUp(); + } + +} + diff --git a/core/modules/content_translation/migration_templates/d6_i18n_custom_block.yml b/core/modules/content_translation/migration_templates/d6_i18n_custom_block.yml new file mode 100644 index 0000000..9534036 --- /dev/null +++ b/core/modules/content_translation/migration_templates/d6_i18n_custom_block.yml @@ -0,0 +1,27 @@ +id: d6_i18n_custom_block +label: Custom blocks +migration_tags: + - Drupal 6 +source: + plugin: d6_i18n_box + constants: + type: basic +process: + id: bid + langcode: language + type: 'constants/type' + info: info + 'body/format': + plugin: migration + migration: d6_filter_format + source: format + 'body/value': body +destination: + plugin: entity:block_content + no_stub: true + translations: true +migration_dependencies: + required: + - d6_filter_format + - block_content_body_field + - d6_custom_block diff --git a/core/modules/content_translation/src/Plugin/migrate/source/d6/I18nBox.php b/core/modules/content_translation/src/Plugin/migrate/source/d6/I18nBox.php new file mode 100644 index 0000000..1d5edf4 --- /dev/null +++ b/core/modules/content_translation/src/Plugin/migrate/source/d6/I18nBox.php @@ -0,0 +1,102 @@ +initializeIterator()->count(); + } + + /** + * {@inheritdoc} + */ + protected function initializeIterator() { + return new \ArrayIterator($this->values()); + } + + /** + * Merge the block body and info translations into a single row. + * + * @return array + */ + protected function values() { + $values = []; + $result = $this->prepareQuery()->execute()->FetchAll(); + $cnt = count($result); + for ($i = 0; $i < $cnt; $i++) { + if (isset($result[$i])) { + $j = $i + 1; + if (isset($result[$j])) { + // If the same bid and language, then this is the info. + if ($result[$i]['bid'] == $result[$j]['bid'] and + $result[$i]['language'] == $result[$j]['language'] + ) { + $result[$i]['info'] = $result[$j]['info']; + unset($result[$j]); + } + } + $values[] = $result[$i]; + } + } + return $values; + } + + /** + * {@inheritdoc} + */ + public function query() { + $query = $this->select('i18n_strings', 'i18n') + ->fields('i18n', ['lid', 'type', 'property', 'objectid']) + ->fields('lt', ['lid', 'language', 'translation']) + ->fields('b', ['bid', 'body', 'info', 'format']) + ->orderBy('bid') + ->orderBy('language') + ->orderBy('property') + ->condition('i18n.type', 'block'); + $query->addExpression(self::INFO, 'info'); + $query->addExpression(self::BODY, 'body'); + $query->leftJoin('boxes', 'b', 'b.bid = i18n.objectid'); + $query->leftJoin('locales_target', 'lt', 'lt.lid = i18n.lid'); + + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + return [ + 'bid' => $this->t('The block numeric identifier.'), + 'language' => $this->t('Language for this field.'), + 'body' => $this->t('The block/box content'), + 'info' => $this->t('Admin title of the block/box.'), + 'format' => $this->t('Input format of the custom block/box content.') + ]; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['bid']['type'] = 'integer'; + $ids['language']['type'] = 'string'; + return $ids; + } + +} diff --git a/core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateI18nBlockContentTest.php b/core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateI18nBlockContentTest.php new file mode 100644 index 0000000..82e4d44 --- /dev/null +++ b/core/modules/content_translation/tests/src/Kernel/Migrate/d6/MigrateI18nBlockContentTest.php @@ -0,0 +1,75 @@ +installConfig(['block_content']); + $this->installEntitySchema('block_content'); + ConfigurableLanguage::createFromLangcode('en')->save(); + ConfigurableLanguage::createFromLangcode('fr')->save(); + ConfigurableLanguage::createFromLangcode('zu')->save(); + $this->executeMigrations([ + 'd6_filter_format', + 'block_content_type', + 'block_content_body_field', + 'd6_custom_block', + 'd6_i18n_custom_block', + ]); + } + + /** + * Tests the Drupal 6 i18n custom block strings to Drupal 8 migration. + */ + public function testBlockMigration() { + /** @var BlockContent $block */ + $block = BlockContent::load(1)->getTranslation('fr'); + $this->assertSame('fr - Static Block', $block->label()); + $this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time()); + $this->assertSame('fr', $block->language()->getId()); + $this->assertSame('

fr - My first custom block body

', $block->body->value); + $this->assertSame('full_html', $block->body->format); + + $block = BlockContent::load(1)->getTranslation('zu'); + $this->assertSame('My block 1', $block->label()); + $this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time()); + $this->assertSame('zu', $block->language()->getId()); + $this->assertSame('

zu - My first custom block body

', $block->body->value); + $this->assertSame('full_html', $block->body->format); + + $block = BlockContent::load(2)->getTranslation('fr'); + $this->assertSame('Encore un bloc statique', $block->label()); + $this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time()); + $this->assertSame('fr', $block->language()->getId()); + $this->assertSame('Nom de vocabulaire beaucoup plus long que trente-deux caractères', $block->body->value); + $this->assertSame('full_html', $block->body->format); + + } + +} diff --git a/core/modules/content_translation/tests/src/Unit/Plugin/migrate/source/d6/I18nBoxTest.php b/core/modules/content_translation/tests/src/Unit/Plugin/migrate/source/d6/I18nBoxTest.php new file mode 100644 index 0000000..ee50d1d --- /dev/null +++ b/core/modules/content_translation/tests/src/Unit/Plugin/migrate/source/d6/I18nBoxTest.php @@ -0,0 +1,149 @@ + 'id', + 'source' => [ + 'plugin' => 'test', + ], + ]; + /** + * Sample block instance query results from the source. + */ + protected $boxes = [ + [ + 'bid' => 1, + 'body' => 'box 1 body', + 'info' => 'box 1 info', + 'format' => '2', + ], + [ + 'bid' => 2, + 'body' => 'box 2 body', + 'info' => 'box 2 info', + 'format' => '2', + ], + ]; + + protected $i18n_strings = [ + [ + 'lid' => 1, + 'objectid' => 1, + 'type' => 'block', + 'property' => 'title', + 'objectindex' => 0, + 'format' => 0, + ], + [ + 'lid' => 2, + 'objectid' => 1, + 'type' => 'block', + 'property' => 'body', + 'objectindex' => 0, + 'format' => 0, + ], + [ + 'lid' => 3, + 'objectid' => 2, + 'type' => 'block', + 'property' => 'body', + 'objectindex' => 0, + 'format' => 2, + ] + ]; + + protected $locales_target = [ + [ + 'lid' => 1, + 'language' => 'fr', + 'translation' => 'fr - info translation', + 'plid' => 0, + 'plural' => 0, + 'i18n_status' => 0, + ], + [ + 'lid' => 2, + 'language' => 'fr', + 'translation' => 'fr - body translation', + 'plid' => 0, + 'plural' => 0, + 'i18n_status' => 0, + ], + [ + 'lid' => 2, + 'language' => 'zu', + 'translation' => 'zu - body translation', + 'plid' => 0, + 'plural' => 0, + 'i18n_status' => 0, + ], + ]; + + protected $expectedResults = [ + [ + 'lid' => '2', + 'type' => 'block', + 'property' => 'body', + 'objectid' => '1', + 'lt_lid' => '2', + 'language' => 'fr', + 'translation' => 'fr - body translation', + 'bid' => '1', + 'body' => 'fr - body translation', + 'info' => 'fr - info translation', + 'format' => '2', + ], + [ + 'lid' => '2', + 'type' => 'block', + 'property' => 'body', + 'objectid' => '1', + 'lt_lid' => '2', + 'language' => 'zu', + 'translation' => 'zu - body translation', + 'bid' => '1', + 'body' => 'zu - body translation', + 'info' => 'box 1 info', + 'format' => '2', + ], + [ + 'lid' => '3', + 'type' => 'block', + 'property' => 'body', + 'objectid' => '2', + 'lt_lid' => Null, + 'language' => Null, + 'translation' => Null, + 'bid' => '2', + 'body' => Null, + 'info' => 'box 2 info', + 'format' => '2', + ], + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + $this->databaseContents['boxes'] = $this->boxes; + $this->databaseContents['i18n_strings'] = $this->i18n_strings; + $this->databaseContents['locales_target'] = $this->locales_target; + + parent::setUp(); + } + +} + diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php index 0cc00d6..57436dd 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php @@ -4,9 +4,14 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\language\ConfigurableLanguageManagerInterface; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Row; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Class for importing configuration entities. @@ -21,9 +26,55 @@ class EntityConfigBase extends Entity { /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + + /** + * Construct a new entity. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param MigrationInterface $migration + * The migration. + * @param EntityStorageInterface $storage + * The storage for this entity type. + * @param array $bundles + * The list of bundles this entity type has. + * @param LanguageManagerInterface $language_manager + * The language manager. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles); + $this->languageManager = $language_manager; + } + + /** * {@inheritdoc} */ - public function import(Row $row, array $old_destination_id_values = array()) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + $entity_type_id = static::getEntityTypeId($plugin_id); + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('entity.manager')->getStorage($entity_type_id), + array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)), + $container->get('language_manager') + ); + } + + /** + * {@inheritdoc} + */ + public function import(Row $row, array $old_destination_id_values = []) { if ($row->isStub()) { throw new MigrateException('Config entities can not be stubbed.'); } @@ -43,13 +94,13 @@ public function import(Row $row, array $old_destination_id_values = array()) { if (count($ids) > 1) { // This can only be a config entity, content entities have their ID key // and that's it. - $return = array(); + $return = []; foreach ($id_keys as $id_key) { $return[] = $entity->get($id_key); } return $return; } - return array($entity->id()); + return [$entity->id()]; } /** @@ -70,10 +121,18 @@ public function getIds() { * The row object to update from. */ protected function updateEntity(EntityInterface $entity, Row $row) { - foreach ($row->getRawDestination() as $property => $value) { - $this->updateEntityProperty($entity, explode(Row::PROPERTY_SEPARATOR, $property), $value); + if ($row->hasDestinationProperty('langcode') && ($this->languageManager instanceof ConfigurableLanguageManagerInterface)) { + // Then this is a row with a translation string. + $config = $entity->getConfigDependencyName(); + $config_override = $this->languageManager->getLanguageConfigOverride($row->getDestinationProperty('langcode'), $config); + $config_override->set(str_replace(Row::PROPERTY_SEPARATOR, '.', $row->getDestinationProperty('property')), $row->getDestinationProperty('translation')); + $config_override->save(); + } + else { + foreach ($row->getRawDestination() as $property => $value) { + $this->updateEntityProperty($entity, explode(Row::PROPERTY_SEPARATOR, $property), $value); + } } - $this->setRollbackAction($row->getIdMap()); } @@ -111,7 +170,7 @@ protected function updateEntityProperty(EntityInterface $entity, array $parents, * The generated entity ID. */ protected function generateId(Row $row, array $ids) { - $id_values = array(); + $id_values = []; foreach ($ids as $id) { $id_values[] = $row->getDestinationProperty($id); } diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php index 9da3de6..52b094c 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; +use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\TypedData\TranslatableInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\migrate\Plugin\MigrationInterface; @@ -21,6 +22,13 @@ class EntityContentBase extends Entity { /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + + /** * Entity manager. * * @var \Drupal\Core\Entity\EntityManagerInterface @@ -49,15 +57,18 @@ class EntityContentBase extends Entity { * The storage for this entity type. * @param array $bundles * The list of bundles this entity type has. + * @param LanguageManagerInterface $language_manager + * The language manager. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The field type plugin manager service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles); $this->entityManager = $entity_manager; $this->fieldTypeManager = $field_type_manager; + $this->languageManager = $language_manager; } /** @@ -71,7 +82,9 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $migration, $container->get('entity.manager')->getStorage($entity_type), - array_keys($container->get('entity.manager')->getBundleInfo($entity_type)), + array_keys($container->get('entity.manager') + ->getBundleInfo($entity_type)), + $container->get('language_manager'), $container->get('entity.manager'), $container->get('plugin.manager.field.field_type') ); @@ -80,7 +93,7 @@ public static function create(ContainerInterface $container, array $configuratio /** * {@inheritdoc} */ - public function import(Row $row, array $old_destination_id_values = array()) { + public function import(Row $row, array $old_destination_id_values = []) { $this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE; $entity = $this->getEntity($row, $old_destination_id_values); if (!$entity) { @@ -105,9 +118,9 @@ public function import(Row $row, array $old_destination_id_values = array()) { * @return array * An array containing the entity ID. */ - protected function save(ContentEntityInterface $entity, array $old_destination_id_values = array()) { + protected function save(ContentEntityInterface $entity, array $old_destination_id_values = []) { $entity->save(); - return array($entity->id()); + return [$entity->id()]; } /** diff --git a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php index 0ebc719..5028a87 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentBaseTest.php @@ -86,6 +86,7 @@ protected function createDestination(array $configuration) { $this->getMock(MigrationInterface::class), $this->storage, [], + $this->container->get('language_manager'), $this->container->get('entity.manager'), $this->container->get('plugin.manager.field.field_type') ); diff --git a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php index e5d63c4..3d48acc 100644 --- a/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php +++ b/core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\FieldTypePluginManagerInterface; +use Drupal\Core\Language\LanguageManagerInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; use Drupal\migrate\Plugin\MigrateIdMapInterface; @@ -43,6 +44,13 @@ class EntityContentBaseTest extends UnitTestCase { protected $entityManager; /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + + /** * {@inheritdoc} */ protected function setUp() { @@ -51,6 +59,7 @@ protected function setUp() { $this->migration = $this->prophesize(MigrationInterface::class); $this->storage = $this->prophesize(EntityStorageInterface::class); $this->entityManager = $this->prophesize(EntityManagerInterface::class); + $this->languageManager = $this->prophesize(LanguageManagerInterface::class); } /** @@ -64,6 +73,7 @@ public function testImport() { $this->migration->reveal(), $this->storage->reveal(), $bundles, + $this->languageManager->reveal(), $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal()); $entity = $this->prophesize(ContentEntityInterface::class); @@ -93,6 +103,7 @@ public function testImportEntityLoadFailure() { $this->migration->reveal(), $this->storage->reveal(), $bundles, + $this->languageManager->reveal(), $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal()); $destination->setEntity(FALSE); @@ -122,6 +133,7 @@ public function testUntranslatable() { $this->migration->reveal(), $this->storage->reveal(), [], + $this->languageManager->reveal(), $this->entityManager->reveal(), $this->prophesize(FieldTypePluginManagerInterface::class)->reveal() ); diff --git a/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php b/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php index 1886914..9c83b61 100644 --- a/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php +++ b/core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\LanguageManagerInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\migrate\destination\EntityRevision as RealEntityRevision; use Drupal\migrate\Row; @@ -42,6 +43,13 @@ class EntityRevisionTest extends UnitTestCase { */ protected $fieldTypeManager; + /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + protected function setUp() { parent::setUp(); @@ -50,6 +58,8 @@ protected function setUp() { $this->storage = $this->prophesize('\Drupal\Core\Entity\EntityStorageInterface'); $this->entityManager = $this->prophesize('\Drupal\Core\Entity\EntityManagerInterface'); $this->fieldTypeManager = $this->prophesize('\Drupal\Core\Field\FieldTypePluginManagerInterface'); + $this->languageManager = $this->prophesize(LanguageManagerInterface::class); + } /** @@ -190,6 +200,7 @@ protected function getEntityRevisionDestination(array $configuration = [], $plug $this->migration->reveal(), $this->storage->reveal(), [], + $this->languageManager->reveal(), $this->entityManager->reveal(), $this->fieldTypeManager->reveal() ); diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php index 169390a..2ca1fd1 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/destination/EntityFieldStorageConfig.php @@ -4,6 +4,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; +use Drupal\Core\Language\LanguageManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig as BaseEntityFieldStorageConfig; @@ -24,6 +25,13 @@ class EntityFieldStorageConfig extends BaseEntityFieldStorageConfig { /** + * The language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + + /** * The field type plugin manager. * * @var \Drupal\Core\Field\FieldTypePluginManagerInterface @@ -45,11 +53,14 @@ class EntityFieldStorageConfig extends BaseEntityFieldStorageConfig { * The storage for this entity type. * @param array $bundles * The list of bundles this entity type has. + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager * The field type plugin manager. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, FieldTypePluginManagerInterface $field_type_plugin_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles); + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, FieldTypePluginManagerInterface $field_type_plugin_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $language_manager); + $this->languageManager = $language_manager; $this->fieldTypePluginManager = $field_type_plugin_manager; } @@ -65,6 +76,7 @@ public static function create(ContainerInterface $container, array $configuratio $migration, $container->get('entity.manager')->getStorage($entity_type_id), array_keys($container->get('entity.manager')->getBundleInfo($entity_type_id)), + $container->get('language_manager'), $container->get('plugin.manager.field.field_type') ); } diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php index 90b0b61..8cd3332 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -82,6 +82,10 @@ class MigrateUpgradeForm extends ConfirmFormBase { 'source_module' => 'block', 'destination_module' => 'block_content', ], + 'd6_i18n_custom_block' => [ + 'source_module' => 'translation', + 'destination_module' => 'content_translation', + ], 'd7_custom_block' => [ 'source_module' => 'block', 'destination_module' => 'block_content', diff --git a/core/modules/user/src/Plugin/migrate/destination/EntityUser.php b/core/modules/user/src/Plugin/migrate/destination/EntityUser.php index b11d867..37a61a3 100644 --- a/core/modules/user/src/Plugin/migrate/destination/EntityUser.php +++ b/core/modules/user/src/Plugin/migrate/destination/EntityUser.php @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Field\Plugin\Field\FieldType\EmailItem; +use Drupal\Core\language\LanguageManagerInterface; use Drupal\Core\Password\PasswordInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\migrate\destination\EntityContentBase; @@ -43,6 +44,8 @@ class EntityUser extends EntityContentBase { * The storage for this entity type. * @param array $bundles * The list of bundles this entity type has. + * @param \Drupal\Core\language\LanguageManagerInterface $language_manager + * The language manager service. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager @@ -50,8 +53,8 @@ class EntityUser extends EntityContentBase { * @param \Drupal\Core\Password\PasswordInterface $password * The password service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, PasswordInterface $password) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager); + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, PasswordInterface $password) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $language_manager, $entity_manager, $field_type_manager); $this->password = $password; } @@ -67,6 +70,7 @@ public static function create(ContainerInterface $container, array $configuratio $migration, $container->get('entity.manager')->getStorage($entity_type), array_keys($container->get('entity.manager')->getBundleInfo($entity_type)), + $container->get('language_manager'), $container->get('entity.manager'), $container->get('plugin.manager.field.field_type'), $container->get('password')