protected function InstallHelper::readMultilingualContent in Drupal 8
Same name and namespace in other branches
- 9 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::readMultilingualContent()
Read multilingual content.
Parameters
string $filename: Filename to import.
Return value
array An array of two items: 1. All multilingual content that was read from the files. 2. List of language codes that need to be imported.
1 call to InstallHelper::readMultilingualContent()
- InstallHelper::importContentFromFile in core/
profiles/ demo_umami/ modules/ demo_umami_content/ src/ InstallHelper.php - Imports content.
File
- core/
profiles/ demo_umami/ modules/ demo_umami_content/ src/ InstallHelper.php, line 180
Class
- InstallHelper
- Defines a helper class for importing default content.
Namespace
Drupal\demo_umami_contentCode
protected function readMultilingualContent($filename) {
$default_content_path = $this->module_path . "/default_content/languages/";
// Get all enabled languages.
$translated_languages = $this->enabledLanguages;
// Load all the content from any CSV files that exist for enabled languages.
foreach ($translated_languages as $language) {
if (file_exists($default_content_path . "{$language}/{$filename}") && ($handle = fopen($default_content_path . "{$language}/{$filename}", 'r')) !== FALSE) {
$header = fgetcsv($handle);
$line_counter = 0;
while (($content = fgetcsv($handle)) !== FALSE) {
$keyed_content[$language][$line_counter] = array_combine($header, $content);
$line_counter++;
}
fclose($handle);
}
else {
// Language directory exists, but the file in this language was not found,
// remove that language from list list of languages to be translated.
$key = array_search($language, $translated_languages);
unset($translated_languages[$key]);
}
}
return [
$keyed_content,
$translated_languages,
];
}