postoffice-1.0.x-dev/extensions/postoffice_skel/postoffice_skel.module
extensions/postoffice_skel/postoffice_skel.module
<?php
/**
* @file
* Primary module hooks for Postoffice skel module.
*/
use Drupal\Core\Template\Attribute;
use Drupal\postoffice\Email\LocalizedEmailInterface;
/**
* Implements hook_theme().
*/
function postoffice_skel_theme() {
return [
'postoffice_skel' => [
'variables' => [
'email' => NULL,
],
],
];
}
/**
* Prepares variables for postoffice skeleton templates.
*
* Default template: postoffice-skel.html.twig.
*
* @param array $variables
* An associative array containing:
* - email: The symfony mime email object.
*/
function template_preprocess_postoffice_skel(array &$variables) {
$languageManager = \Drupal::languageManager();
$email = $variables['email'];
if (
$email instanceof LocalizedEmailInterface &&
$languageManager->getLanguage($email->getLangcode())
) {
$language = $languageManager->getLanguage($email->getLangcode());
}
else {
$language = $languageManager->getCurrentLanguage();
}
// HTML element attributes.
$attributes = [];
$attributes['lang'] = $language->getId();
$attributes['dir'] = $language->getDirection();
$variables['html_attributes'] = new Attribute($attributes);
// Langcode.
$variables['langcode'] = $language->getId();
}
