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 @@
))
->values(array(
'vid' => '2',
'name' => 'Forums',
'machine_name' => 'forums',
'name' => 'Sujet de discussion',
'machine_name' => 'sujet_de_discussion',
'description' => 'Forum navigation vocabulary',
'hierarchy' => '1',
'module' => 'forum',
......@@ -15,6 +15,12 @@ process:
field: vid
length: 32
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
name: name
description: description
......
......@@ -45,10 +45,11 @@ process:
plugin: substr
length: 32
-
# This plugin checks if the vocabulary being migrated is the one used for
# forums. If it is, the field name is set to 'taxonomy_forums' as it is
# what the Forum module is expecting. Otherwise, it is left unchanged.
# 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: taxonomy_forums
destination:
plugin: component_entity_display
migration_dependencies:
......
......@@ -49,10 +49,11 @@ process:
plugin: substr
length: 32
-
# This plugin checks if the vocabulary being migrated is the one used for
# forums. If it is, the field name is set to 'taxonomy_forums' as it is
# what the Forum module is expecting. Otherwise, it is left unchanged.
# 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: taxonomy_forums
destination:
plugin: component_entity_form_display
migration_dependencies:
......
......@@ -33,10 +33,11 @@ process:
plugin: substr
length: 32
-
# This plugin checks if the vocabulary being migrated is the one used for
# forums. If it is, the field name is set to 'taxonomy_forums' as it is
# what the Forum module is expecting. Otherwise, it is left unchanged.
# 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: taxonomy_forums
'settings/target_type': 'constants/target_entity_type'
cardinality: cardinality
destination:
......
......@@ -40,10 +40,11 @@ process:
plugin: substr
length: 32
-
# This plugin checks if the vocabulary being migrated is the one used for
# forums. If it is, the field name is set to 'taxonomy_forums' as it is
# what the Forum module is expecting. Otherwise, it is left unchanged.
# 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: taxonomy_forums
label: name
'settings/handler': 'constants/selection_handler'
'settings/handler_settings/target_bundles/0': '@field_name'
......
......@@ -15,6 +15,12 @@ process:
field: vid
length: 32
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
name: name
description: description
......
......@@ -9,12 +9,24 @@
/**
* 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
* forum nodes. The 'forum_vocabulary' source property is evaluated in
* Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary and is set to true if
* the vocabulary vid being migrated is the same as the one in the
* Drupal 8 Forum is expecting specific machine names for its field and
* vocabulary names. This process plugin forces a given machine name to the
* field or vocabulary that is being migrated.
*
* 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.
*
* Example:
*
* @code
* process:
* field_name:
* plugin: forum_vocabulary
* machine_name: taxonomy_forums
* @endcode
*
* @MigrateProcessPlugin(
* id = "forum_vocabulary"
* )
......@@ -25,8 +37,8 @@ class ForumVocabulary extends ProcessPluginBase {
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if ($row->getSourceProperty('forum_vocabulary')) {
$value = 'taxonomy_forums';
if ($row->getSourceProperty('forum_vocabulary') && !empty($this->configuration['machine_name'])) {
$value = $this->configuration['machine_name'];
}
return $value;
}
......
......@@ -70,9 +70,9 @@ public function prepareRow(Row $row) {
$row->setSourceProperty('node_types', $node_types);
$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
// 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')) {
$row->setSourceProperty('forum_vocabulary', TRUE);
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\taxonomy\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
......@@ -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}
*/
......
......@@ -55,7 +55,7 @@ protected function assertEntity($id, $expected_label, $expected_description, $ex
*/
public function testTaxonomyVocabulary() {
$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('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