function template_preprocess_languageicons_link_content in Language Icons 8
Prepares variables for rendering the content of a language link.
Default template: languageicons-link-content.html.twig.
Parameters
array $variables: An associative array containing:
- language: The language.
- separator: The separator between icon and link text.
- text: The text shown in the link.
- title: The image title for the icon.
Throws
\Exception Thrown when the path to the language icon images is not set.
File
- ./
languageicons.module, line 102 - Main functions and hook implementations for the Language Icons module.
Code
function template_preprocess_languageicons_link_content(&$variables) {
/** @var \Drupal\language\Entity\ConfigurableLanguage $language */
$language = $variables['language'];
$title = $variables['title'] ? $variables['title'] : $language
->getName();
$size = \Drupal::config('languageicons.settings')
->get('size');
list($width, $height) = explode('x', $size);
if ($path = \Drupal::config('languageicons.settings')
->get('path')) {
$variables['icon'] = [
'#theme' => 'image',
'#uri' => str_replace('*', $language
->getId(), Html::escape($path)),
'#alt' => $title,
'#title' => $title,
'#width' => $width,
'#height' => $height,
'#attributes' => [
'class' => [
'language-icon',
],
],
];
}
else {
throw new \Exception('Path to language icons is not defined.');
}
$variables['placement'] = \Drupal::config('languageicons.settings')
->get('placement');
}