MenuLinkTranslation.php in Drupal 10
File
core/modules/menu_link_content/src/Plugin/migrate/source/d7/MenuLinkTranslation.php
View source
<?php
namespace Drupal\menu_link_content\Plugin\migrate\source\d7;
use Drupal\content_translation\Plugin\migrate\source\I18nQueryTrait;
use Drupal\migrate\Row;
use Drupal\menu_link_content\Plugin\migrate\source\MenuLink;
class MenuLinkTranslation extends MenuLink {
use I18nQueryTrait;
public function query() {
$query = parent::query();
$query
->leftJoin('i18n_string', 'i18n', 'CAST([ml].[mlid] AS CHAR(255)) = [i18n].[objectid]');
$query
->fields('i18n', [
'lid',
'objectid',
'property',
'textgroup',
])
->condition('i18n.textgroup', 'menu')
->condition('i18n.type', 'item');
$query
->innerJoin('locales_target', 'lt', '[i18n].[lid] = [lt].[lid]');
$query
->addField('lt', 'language', 'lt_language');
$query
->fields('lt', [
'translation',
]);
$query
->isNotNull('lt.language');
return $query;
}
public function prepareRow(Row $row) {
if (!parent::prepareRow($row)) {
return FALSE;
}
$row
->setSourceProperty('language', $row
->getSourceProperty('lt_language'));
$property_in_row = $row
->getSourceProperty('property');
$this->i18nStringTable = 'i18n_string';
$property_not_in_row = $property_in_row == 'title' ? 'description' : 'title';
return $this
->getPropertyNotInRowTranslation($row, $property_not_in_row, 'mlid', $this->idMap);
}
public function fields() {
$fields = [
'title_translated' => $this
->t('Menu link title translation.'),
'description_translated' => $this
->t('Menu link description translation.'),
];
return parent::fields() + $fields;
}
public function getIds() {
$ids['language']['type'] = 'string';
$ids['language']['alias'] = 'lt';
return parent::getIds() + $ids;
}
}