Commit a20201a5 authored by catch's avatar catch

Issue #2914249 by maxocub, dillix, masipila, phenaproxima: Translated forum...

Issue #2914249 by maxocub, dillix, masipila, phenaproxima: Translated forum vocabulary migration creates duplicate forum vocabularies
parent 2c7b21d2
...@@ -45365,8 +45365,8 @@ ...@@ -45365,8 +45365,8 @@
)) ))
->values(array( ->values(array(
'vid' => '2', 'vid' => '2',
'name' => 'Forums', 'name' => 'Sujet de discussion',
'machine_name' => 'forums', 'machine_name' => 'sujet_de_discussion',
'description' => 'Forum navigation vocabulary', 'description' => 'Forum navigation vocabulary',
'hierarchy' => '1', 'hierarchy' => '1',
'module' => 'forum', 'module' => 'forum',
...@@ -15,6 +15,12 @@ process: ...@@ -15,6 +15,12 @@ process:
field: vid field: vid
length: 32 length: 32
migrated: true migrated: true
-
# This plugin checks if the vocabulary being migrated is the one used by
# Forum. If so, we use the machine name that Forum expects. Otherwise, we
# leave it unchanged.
plugin: forum_vocabulary
machine_name: forums
label: name label: name
name: name name: name
description: description description: description
......
...@@ -45,10 +45,11 @@ process: ...@@ -45,10 +45,11 @@ process:
plugin: substr plugin: substr
length: 32 length: 32
- -
# This plugin checks if the vocabulary being migrated is the one used for # This plugin checks if the vocabulary being migrated is the one used by
# forums. If it is, the field name is set to 'taxonomy_forums' as it is # Forum. If so, we use the machine name that Forum expects. Otherwise, we
# what the Forum module is expecting. Otherwise, it is left unchanged. # leave it unchanged.
plugin: forum_vocabulary plugin: forum_vocabulary
machine_name: taxonomy_forums
destination: destination:
plugin: component_entity_display plugin: component_entity_display
migration_dependencies: migration_dependencies:
......
...@@ -49,10 +49,11 @@ process: ...@@ -49,10 +49,11 @@ process:
plugin: substr plugin: substr
length: 32 length: 32
- -
# This plugin checks if the vocabulary being migrated is the one used for # This plugin checks if the vocabulary being migrated is the one used by
# forums. If it is, the field name is set to 'taxonomy_forums' as it is # Forum. If so, we use the machine name that Forum expects. Otherwise, we
# what the Forum module is expecting. Otherwise, it is left unchanged. # leave it unchanged.
plugin: forum_vocabulary plugin: forum_vocabulary
machine_name: taxonomy_forums
destination: destination:
plugin: component_entity_form_display plugin: component_entity_form_display
migration_dependencies: migration_dependencies:
......
...@@ -33,10 +33,11 @@ process: ...@@ -33,10 +33,11 @@ process:
plugin: substr plugin: substr
length: 32 length: 32
- -
# This plugin checks if the vocabulary being migrated is the one used for # This plugin checks if the vocabulary being migrated is the one used by
# forums. If it is, the field name is set to 'taxonomy_forums' as it is # Forum. If so, we use the machine name that Forum expects. Otherwise, we
# what the Forum module is expecting. Otherwise, it is left unchanged. # leave it unchanged.
plugin: forum_vocabulary plugin: forum_vocabulary
machine_name: taxonomy_forums
'settings/target_type': 'constants/target_entity_type' 'settings/target_type': 'constants/target_entity_type'
cardinality: cardinality cardinality: cardinality
destination: destination:
......
...@@ -40,10 +40,11 @@ process: ...@@ -40,10 +40,11 @@ process:
plugin: substr plugin: substr
length: 32 length: 32
- -
# This plugin checks if the vocabulary being migrated is the one used for # This plugin checks if the vocabulary being migrated is the one used by
# forums. If it is, the field name is set to 'taxonomy_forums' as it is # Forum. If so, we use the machine name that Forum expects. Otherwise, we
# what the Forum module is expecting. Otherwise, it is left unchanged. # leave it unchanged.
plugin: forum_vocabulary plugin: forum_vocabulary
machine_name: taxonomy_forums
label: name label: name
'settings/handler': 'constants/selection_handler' 'settings/handler': 'constants/selection_handler'
'settings/handler_settings/target_bundles/0': '@field_name' 'settings/handler_settings/target_bundles/0': '@field_name'
......
...@@ -15,6 +15,12 @@ process: ...@@ -15,6 +15,12 @@ process:
field: vid field: vid
length: 32 length: 32
migrated: true migrated: true
-
# This plugin checks if the vocabulary being migrated is the one used by
# Forum. If so, we use the machine name that Forum expects. Otherwise, we
# leave it unchanged.
plugin: forum_vocabulary
machine_name: forums
label: name label: name
name: name name: name
description: description description: description
......
...@@ -9,12 +9,24 @@ ...@@ -9,12 +9,24 @@
/** /**
* Checks if the vocabulary being migrated is the one used for forums. * Checks if the vocabulary being migrated is the one used for forums.
* *
* The forum module is expecting 'taxonomy_forums' as the field name for the * Drupal 8 Forum is expecting specific machine names for its field and
* forum nodes. The 'forum_vocabulary' source property is evaluated in * vocabulary names. This process plugin forces a given machine name to the
* Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary and is set to true if * field or vocabulary that is being migrated.
* the vocabulary vid being migrated is the same as the one in the *
* The 'forum_vocabulary' source property is evaluated in the
* d6_taxonomy_vocabulary or d7_taxonomy_vocabulary source plugins and is set to
* true if the vocabulary vid being migrated is the same as the one in the
* 'forum_nav_vocabulary' variable on the source site. * 'forum_nav_vocabulary' variable on the source site.
* *
* Example:
*
* @code
* process:
* field_name:
* plugin: forum_vocabulary
* machine_name: taxonomy_forums
* @endcode
*
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "forum_vocabulary" * id = "forum_vocabulary"
* ) * )
...@@ -25,8 +37,8 @@ class ForumVocabulary extends ProcessPluginBase { ...@@ -25,8 +37,8 @@ class ForumVocabulary extends ProcessPluginBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if ($row->getSourceProperty('forum_vocabulary')) { if ($row->getSourceProperty('forum_vocabulary') && !empty($this->configuration['machine_name'])) {
$value = 'taxonomy_forums'; $value = $this->configuration['machine_name'];
} }
return $value; return $value;
} }
......
...@@ -70,9 +70,9 @@ public function prepareRow(Row $row) { ...@@ -70,9 +70,9 @@ public function prepareRow(Row $row) {
$row->setSourceProperty('node_types', $node_types); $row->setSourceProperty('node_types', $node_types);
$row->setSourceProperty('cardinality', ($row->getSourceProperty('tags') == 1 || $row->getSourceProperty('multiple') == 1) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 1); $row->setSourceProperty('cardinality', ($row->getSourceProperty('tags') == 1 || $row->getSourceProperty('multiple') == 1) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 1);
// If the vid of the vocabulary being migrated is equal to the vid in the // If the vocabulary being migrated is the one defined in the
// 'forum_nav_vocabulary' variable, set the 'forum_vocabulary' source // 'forum_nav_vocabulary' variable, set the 'forum_vocabulary' source
// property to true so we can know this is the vocabulary used for forums. // property to true so we know this is the vocabulary used by Forum.
if ($this->variableGet('forum_nav_vocabulary', 0) == $row->getSourceProperty('vid')) { if ($this->variableGet('forum_nav_vocabulary', 0) == $row->getSourceProperty('vid')) {
$row->setSourceProperty('forum_vocabulary', TRUE); $row->setSourceProperty('forum_vocabulary', TRUE);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\taxonomy\Plugin\migrate\source\d7; namespace Drupal\taxonomy\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/** /**
...@@ -46,6 +47,20 @@ public function fields() { ...@@ -46,6 +47,20 @@ public function fields() {
]; ];
} }
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
// If the vocabulary being migrated is the one defined in the
// 'forum_nav_vocabulary' variable, set the 'forum_vocabulary' source
// property to true so we know this is the vocabulary used by Forum.
if ($this->variableGet('forum_nav_vocabulary', 0) == $row->getSourceProperty('vid')) {
$row->setSourceProperty('forum_vocabulary', TRUE);
}
return parent::prepareRow($row);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -55,7 +55,7 @@ protected function assertEntity($id, $expected_label, $expected_description, $ex ...@@ -55,7 +55,7 @@ protected function assertEntity($id, $expected_label, $expected_description, $ex
*/ */
public function testTaxonomyVocabulary() { public function testTaxonomyVocabulary() {
$this->assertEntity('tags', 'Tags', 'Use tags to group articles on similar topics into categories.', VocabularyInterface::HIERARCHY_DISABLED, 0); $this->assertEntity('tags', 'Tags', 'Use tags to group articles on similar topics into categories.', VocabularyInterface::HIERARCHY_DISABLED, 0);
$this->assertEntity('forums', 'Forums', 'Forum navigation vocabulary', VocabularyInterface::HIERARCHY_SINGLE, -10); $this->assertEntity('forums', 'Sujet de discussion', 'Forum navigation vocabulary', VocabularyInterface::HIERARCHY_SINGLE, -10);
$this->assertEntity('test_vocabulary', 'Test Vocabulary', 'This is the vocabulary description', VocabularyInterface::HIERARCHY_SINGLE, 0); $this->assertEntity('test_vocabulary', 'Test Vocabulary', 'This is the vocabulary description', VocabularyInterface::HIERARCHY_SINGLE, 0);
$this->assertEntity('vocabulary_name_much_longer_than', 'vocabulary name much longer than thirty two characters', 'description of vocabulary name much longer than thirty two characters', VocabularyInterface::HIERARCHY_SINGLE, 0); $this->assertEntity('vocabulary_name_much_longer_than', 'vocabulary name much longer than thirty two characters', 'description of vocabulary name much longer than thirty two characters', VocabularyInterface::HIERARCHY_SINGLE, 0);
} }
......
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