function pwa_html_head_alter in Progressive Web App 7.2
Implements hook_html_head_alter().
Make sure a viewport meta exists. Necessary for Lighthouse 100%.
File
- ./
pwa.module, line 418
Code
function pwa_html_head_alter(&$head_elements) {
$has_viewport_meta = FALSE;
// Check if the viewport meta already exists, add it if it doesn't.
foreach ($head_elements as $key => $element) {
if (!empty($element['#tag']) && $element['#tag'] == 'meta' && (!empty($element['#attributes']['name']) && $element['#attributes']['name'] == 'viewport')) {
$has_viewport_meta = TRUE;
break;
}
}
if (!$has_viewport_meta) {
$head_elements['viewport'] = [
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => [
'name' => 'viewport',
'content' => 'width=device-width, initial-scale=1',
],
'#weight' => 10,
];
}
// Add Apple related meta tags, do it in the alter to avoid adding the link
// elements at the top of the page.
if (!variable_get('pwa_apple_meta_enable', TRUE)) {
return;
}
_pwa_apple_html_head_alter($head_elements);
}