function Importer::verifyNormalizedLanguage
Same name in other branches
- 11.x core/lib/Drupal/Core/DefaultContent/Importer.php \Drupal\Core\DefaultContent\Importer::verifyNormalizedLanguage()
Verifies that the site knows the default language of the normalized entity.
Will attempt to switch to an alternative translation or just import it with the site default language.
Parameters
array $data: The normalized entity data.
Return value
array The normalized entity data, possibly with altered default language and translations.
1 call to Importer::verifyNormalizedLanguage()
- Importer::toEntity in core/
lib/ Drupal/ Core/ DefaultContent/ Importer.php - Converts an array of content entity data to a content entity object.
File
-
core/
lib/ Drupal/ Core/ DefaultContent/ Importer.php, line 350
Class
- Importer
- A service for handling import of content.
Namespace
Drupal\Core\DefaultContentCode
private function verifyNormalizedLanguage(array $data) : array {
$default_langcode = $data['_meta']['default_langcode'];
$default_language = $this->languageManager
->getDefaultLanguage();
// Check the language. If the default language isn't known, import as one
// of the available translations if one exists with those values. If none
// exists, create the entity in the default language.
// During the installer, when installing with an alternative language,
// `en` is still the default when modules are installed so check the default language
// instead.
if (!$this->languageManager
->getLanguage($default_langcode) || InstallerKernel::installationAttempted() && $default_language->getId() !== $default_langcode) {
$use_default = TRUE;
foreach ($data['translations'] ?? [] as $langcode => $translation_data) {
if ($this->languageManager
->getLanguage($langcode)) {
$data['_meta']['default_langcode'] = $langcode;
$data['default'] = \array_merge($data['default'], $translation_data);
unset($data['translations'][$langcode]);
$use_default = FALSE;
break;
}
}
if ($use_default) {
$data['_meta']['default_langcode'] = $default_language->getId();
}
}
return $data;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.