MenuLinkLocalized.php in Drupal 10
File
core/modules/menu_link_content/src/Plugin/migrate/source/d7/MenuLinkLocalized.php
View source
<?php
namespace Drupal\menu_link_content\Plugin\migrate\source\d7;
use Drupal\menu_link_content\Plugin\migrate\source\MenuLink;
use Drupal\migrate\Row;
class MenuLinkLocalized extends MenuLink {
public function query() {
$query = parent::query();
$query
->condition('ml.i18n_tsid', '0', '<>');
$query
->orderBy('ml.i18n_tsid');
return $query;
}
public function fields() {
$fields = [
'ml_language' => $this
->t('Menu link ID of the source language menu link.'),
'skip_source_translation' => $this
->t('Menu link description translation.'),
];
return parent::fields() + $fields;
}
public function prepareRow(Row $row) {
$row
->setSourceProperty('skip_source_translation', TRUE);
$source_mlid = $this
->select('menu_links', 'ml')
->fields('ml', [
'mlid',
])
->condition('i18n_tsid', $row
->getSourceProperty('i18n_tsid'))
->orderBy('mlid')
->range(0, 1)
->execute()
->fetchField();
if ($source_mlid == $row
->getSourceProperty('mlid')) {
$row
->setSourceProperty('skip_source_translation', FALSE);
}
$row
->setSourceProperty('mlid', $source_mlid);
return parent::prepareRow($row);
}
public function getIds() {
$ids['language']['type'] = 'string';
$ids['language']['alias'] = 'ml';
return parent::getIds() + $ids;
}
}