amp_toolbar.module in Accelerated Mobile Pages (AMP) 8.3
File
modules/amp_toolbar/amp_toolbar.moduleView source
<?php
/**
* Implements hook_preprocess_html().
*
* Reset toolbar classes and add sidebar toggle button to the header.
*/
function amp_toolbar_preprocess_html(&$variables) {
$amp_context = \Drupal::service('router.amp_context');
if ($amp_context
->isAmpRoute()) {
// Also change the toolbar page classes to from horizontal to vertical.
// A module can't do that, only the theme is run late enough, so invoke
// hook_preprocess_html in the theme.
// @see ampsubtheme_example.theme.
// Wrap the toolbar in an amp-sidebar element.
$toolbar = $variables['page_top']['toolbar'];
$variables['page_top']['toolbar']['#theme_wrappers'] = [
'amp_sidebar' => [
'#id' => 'sidebar-toolbar',
'#tabindex' => 0,
'#attributes' => [
'side' => 'left',
'layout' => 'nodisplay',
],
'#content_attributes' => [
'class' => [
'sidebar-close',
],
],
'#access' => $toolbar['#access'],
'#cache' => $toolbar['#cache'],
],
];
// Add hamburger button to toggle the sidebar.
// Added to the page top which all themes have. Any theme could move the
// whole thing to a different location using hook_preprocess_html().
// @see ampsubtheme_example.theme.
$variables['page_top']['sidebar-toolbar-toggle'] = [
'#theme' => 'amp_sidebar_toggle',
'#sidebarid' => 'sidebar-toolbar',
'#tabindex' => 0,
'#title' => t('Toolbar'),
'#attributes' => [
'class' => [
'sidebar-toggle-left',
],
],
'#access' => $toolbar['#access'],
];
}
}
Functions
Name![]() |
Description |
---|---|
amp_toolbar_preprocess_html | Implements hook_preprocess_html(). |