function I18nQueryTrait::getPropertyNotInRowTranslation
Same name in other branches
- 9 core/modules/content_translation/src/Plugin/migrate/source/I18nQueryTrait.php \Drupal\content_translation\Plugin\migrate\source\I18nQueryTrait::getPropertyNotInRowTranslation()
- 8.9.x core/modules/content_translation/src/Plugin/migrate/source/I18nQueryTrait.php \Drupal\content_translation\Plugin\migrate\source\I18nQueryTrait::getPropertyNotInRowTranslation()
- 11.x core/modules/content_translation/src/Plugin/migrate/source/I18nQueryTrait.php \Drupal\content_translation\Plugin\migrate\source\I18nQueryTrait::getPropertyNotInRowTranslation()
Gets the translation for the property not already in the row.
For some i18n migrations there are two translation values, such as a translated title and a translated description, that need to be retrieved. Since these values are stored in separate rows of the i18nStringTable table we get them individually, one in the source plugin query() and the other in prepareRow(). The names of the properties varies, for example, in BoxTranslation they are 'body' and 'title' whereas in MenuLinkTranslation they are 'title' and 'description'. This will save both translations to the row.
Parameters
\Drupal\migrate\Row $row: The current migration row which must include both a 'language' property and an 'objectid' property. The 'objectid' is the value for the 'objectid' field in the i18n_string table.
string $property_not_in_row: The name of the property to get the translation for.
string $object_id_name: The value of the objectid in the i18n table.
\Drupal\migrate\Plugin\MigrateIdMapInterface $id_map: The ID map.
Return value
bool FALSE if the property has already been migrated.
Throws
\Drupal\migrate\MigrateException
4 calls to I18nQueryTrait::getPropertyNotInRowTranslation()
- BlockCustomTranslation::prepareRow in core/
modules/ block_content/ src/ Plugin/ migrate/ source/ d7/ BlockCustomTranslation.php - Adds additional data to the row.
- MenuLinkTranslation::prepareRow in core/
modules/ menu_link_content/ src/ Plugin/ migrate/ source/ d6/ MenuLinkTranslation.php - Adds additional data to the row.
- MenuLinkTranslation::prepareRow in core/
modules/ menu_link_content/ src/ Plugin/ migrate/ source/ d7/ MenuLinkTranslation.php - Adds additional data to the row.
- TermLocalizedTranslation::prepareRow in core/
modules/ taxonomy/ src/ Plugin/ migrate/ source/ d7/ TermLocalizedTranslation.php - Adds additional data to the row.
File
-
core/
modules/ content_translation/ src/ Plugin/ migrate/ source/ I18nQueryTrait.php, line 51
Class
- I18nQueryTrait
- Gets an i18n translation from the source database.
Namespace
Drupal\content_translation\Plugin\migrate\sourceCode
protected function getPropertyNotInRowTranslation(Row $row, $property_not_in_row, $object_id_name, MigrateIdMapInterface $id_map) {
$language = $row->getSourceProperty('language');
if (!$language) {
throw new MigrateException('No language found.');
}
$object_id = $row->getSourceProperty($object_id_name);
if (!$object_id) {
throw new MigrateException('No objectid found.');
}
// If this row has been migrated it is a duplicate so skip it.
if ($id_map->lookupDestinationIds([
$object_id_name => $object_id,
'language' => $language,
])) {
return FALSE;
}
// Save the translation for the property already in the row.
$property_in_row = $row->getSourceProperty('property');
$row->setSourceProperty($property_in_row . '_translated', $row->getSourceProperty('translation'));
// Get the translation, if one exists, for the property not already in the
// row.
$query = $this->select($this->i18nStringTable, 'i18n')
->fields('i18n', [
'lid',
])
->condition('i18n.property', $property_not_in_row)
->condition('i18n.objectid', $object_id);
$query->leftJoin('locales_target', 'lt', '[i18n].[lid] = [lt].[lid]');
$query->condition('lt.language', $language);
$query->addField('lt', 'translation');
$results = $query->execute()
->fetchAssoc();
if (!$results) {
$row->setSourceProperty($property_not_in_row . '_translated', NULL);
}
else {
$row->setSourceProperty($property_not_in_row . '_translated', $results['translation']);
}
return TRUE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.