Prepares variables for the page template.
Default template: page.html.twig.
Most themes utilize their own copy of page.html.twig. The default is located inside "modules/system/page.html.twig". Look in there for the full list of variables.
Uses the arg() function to generate a series of page template suggestions based on the current path.
Any changes to variables in this preprocessor should also be changed inside template_preprocess_maintenance_page() to keep all of them consistent.
function template_preprocess_page(&$variables) {
$language_interface = language(Language::TYPE_INTERFACE);
$site_config = config('system.site');
// Move some variables to the top level for themer convenience and template cleanliness.
$variables['show_messages'] = $variables['page']['#show_messages'];
foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
if (!isset($variables['page'][$region_key])) {
$variables['page'][$region_key] = array();
}
}
// Set up layout variable.
$variables['layout'] = 'none';
if (!empty($variables['page']['sidebar_first'])) {
$variables['layout'] = 'first';
}
if (!empty($variables['page']['sidebar_second'])) {
$variables['layout'] = $variables['layout'] == 'first' ? 'both' : 'second';
}
$variables['base_path'] = base_path();
$variables['front_page'] = url();
$variables['feed_icons'] = drupal_get_feeds();
$variables['language'] = $language_interface;
$variables['language']->dir = $language_interface->direction ? 'rtl' : 'ltr';
$variables['logo'] = theme_get_setting('logo.url');
$variables['main_menu'] = theme_get_setting('features.main_menu') ? menu_main_menu() : array();
$variables['secondary_menu'] = theme_get_setting('features.secondary_menu') ? menu_secondary_menu() : array();
$variables['action_links'] = menu_get_local_actions();
$variables['site_name'] = theme_get_setting('features.name') ? check_plain($site_config
->get('name')) : '';
$variables['site_slogan'] = theme_get_setting('features.slogan') ? filter_xss_admin($site_config
->get('slogan')) : '';
$variables['tabs'] = menu_local_tabs();
// Pass the main menu and secondary menu to the template as render arrays.
if (!empty($variables['main_menu'])) {
$variables['main_menu'] = array(
'#theme' => 'links__system_main_menu',
'#links' => $variables['main_menu'],
'#attributes' => array(
'id' => 'main-menu',
'class' => array(
'links',
'inline',
'clearfix',
),
),
'#heading' => array(
'text' => t('Main menu'),
'class' => array(
'element-invisible',
),
),
);
}
if (!empty($variables['secondary_menu'])) {
$variables['secondary_menu'] = array(
'#theme' => 'links__system_secondary_menu',
'#links' => $variables['secondary_menu'],
'#attributes' => array(
'id' => 'secondary-menu',
'class' => array(
'links',
'inline',
'clearfix',
),
),
'#heading' => array(
'text' => t('Secondary menu'),
'class' => array(
'element-invisible',
),
),
);
}
if ($node = menu_get_object()) {
$variables['node'] = $node;
}
// Populate the page template suggestions.
if ($suggestions = theme_get_suggestions(arg(), 'page')) {
$variables['theme_hook_suggestions'] = $suggestions;
}
}