Issue #3193189 by quietone, jibran: Get only translations for localized vocabularies d6/TermLocalizedTranslation.php

(cherry picked from commit eddba9a366)
merge-requests/674/head
catch 2021-05-13 15:21:43 +01:00
parent 4e9fc2935c
commit a764279e56
2 changed files with 66 additions and 0 deletions

View File

@ -37,6 +37,7 @@ class TermLocalizedTranslation extends Term {
// Add in the property, which is either name or description.
// Cast td.tid as char for PostgreSQL compatibility.
$query->leftJoin('i18n_strings', 'i18n', 'CAST([td].[tid] AS CHAR(255)) = [i18n].[objectid]');
$query->condition('i18n.type', 'term');
$query->addField('i18n', 'lid');
$query->addField('i18n', 'property');
@ -69,6 +70,7 @@ class TermLocalizedTranslation extends Term {
$other_property = ($property == 'name') ? 'description' : 'name';
$query = $this->select('i18n_strings', 'i18n')
->fields('i18n', ['lid'])
->condition('i18n.type', 'term')
->condition('i18n.property', $other_property)
->condition('i18n.objectid', $tid);
$query->leftJoin('locales_target', 'lt', '[i18n].[lid] = [lt].[lid]');

View File

@ -181,6 +181,70 @@ class TermLocalizedTranslationTest extends MigrateSqlSourceTestBase {
// Empty configuration will return terms for all vocabularies.
$tests[0]['configuration'] = [];
// Test that only i18n_strings of type 'term' are returned.
$tests[1] = $tests[0];
$tests[0]['source_data']['i18n_strings'] = [
[
'lid' => 6,
'objectid' => 1,
'type' => 'term',
'property' => 'name',
'objectindex' => '1',
'format' => 0,
],
[
'lid' => 7,
'objectid' => 1,
'type' => 'term',
'property' => 'description',
'objectindex' => '1',
'format' => 0,
],
[
'lid' => 8,
'objectid' => 3,
'type' => 'not term',
'property' => 'name',
'objectindex' => '3',
'format' => 0,
],
[
'lid' => 9,
'objectid' => 4,
'type' => 'term',
'property' => 'description',
'objectindex' => '4',
'format' => 0,
],
];
// The expected results.
$tests[0]['expected_data'] = [
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
'parent' => [0],
'property' => 'name',
'language' => 'fr',
'name_translated' => 'fr - name value 1 translation',
'description_translated' => 'fr - description value 1 translation',
],
[
'tid' => 1,
'vid' => 5,
'name' => 'name value 1',
'description' => 'description value 1',
'weight' => 0,
'parent' => [0],
'property' => 'description',
'language' => 'fr',
'name_translated' => 'fr - name value 1 translation',
'description_translated' => 'fr - description value 1 translation',
],
];
return $tests;
}