function asset_injector_preprocess_page in Asset Injector 8.2
Implements hook_preprocess_page().
Insert <noscript> code into page region.
File
- ./
asset_injector.module, line 216 - Contains module asset_injector.
Code
function asset_injector_preprocess_page(&$vars) {
foreach (asset_injector_get_assets(TRUE, [
'asset_injector_js',
]) as $asset) {
if (empty($asset->noscript)) {
continue;
}
$active_theme = \Drupal::service('theme.manager')
->getActiveTheme()
->getName();
// Support legacy code where region was a string vs an array.
$no_script_regions = is_array($asset->noscriptRegion) ? $asset->noscriptRegion : [
$active_theme => $asset->noscriptRegion,
];
if (!empty($no_script_regions[$active_theme])) {
$region = $no_script_regions[$active_theme];
$vars['page'][$region][$asset->id . '-noscript'] = [
'#type' => 'inline_template',
'#template' => '<noscript>{{ code | raw }}</noscript>',
'#context' => [
'code' => $asset->noscript,
],
];
}
}
}