diff --git a/core/authorize.php b/core/authorize.php index fe374fa..f1921cb 100644 --- a/core/authorize.php +++ b/core/authorize.php @@ -182,7 +182,7 @@ function authorize_access_allowed(Request $request) { } $bare_html_page_renderer = \Drupal::service('bare_html_page_renderer'); -$response = $bare_html_page_renderer->renderBarePage($content, $page_title, 'maintenance_page', array( +$response = $bare_html_page_renderer->renderBarePage($content, $page_title, 'page__maintenance', array( '#show_messages' => $show_messages, )); if (!$is_allowed) { diff --git a/core/includes/batch.inc b/core/includes/batch.inc index 0958c3a..d273929 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -138,7 +138,7 @@ function _batch_progress_page() { // it. While this causes invalid HTML, the same would be true if we didn't, // as content is not allowed to appear after anyway. $bare_html_page_renderer = \Drupal::service('bare_html_page_renderer'); - $response = $bare_html_page_renderer->renderBarePage(['#markup' => $fallback], $current_set['title'], 'maintenance_page', array( + $response = $bare_html_page_renderer->renderBarePage(['#markup' => $fallback], $current_set['title'], 'page__maintenance', array( '#show_messages' => FALSE, )); diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 36612ecf..0407647 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -984,7 +984,7 @@ function install_display_output($output, $install_state) { } $bare_html_page_renderer = \Drupal::service('bare_html_page_renderer'); - $response = $bare_html_page_renderer->renderBarePage($output, $output['#title'], 'install_page', $regions); + $response = $bare_html_page_renderer->renderBarePage($output, $output['#title'], 'page__maintenance__install', $regions); $default_headers = array( 'Expires' => 'Sun, 19 Nov 1978 05:00:00 GMT', 'Last-Modified' => gmdate(DATE_RFC1123, REQUEST_TIME), diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 2947eb9..a5f17f7 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1137,7 +1137,7 @@ function template_preprocess_maintenance_task_list(&$variables) { * See the @link themeable Default theme implementations topic @endlink for * details. */ -function template_preprocess(&$variables, $context) { +function template_preprocess(&$variables, $hook, $info) { // Merge in variables that don't depend on hook and don't change during a // single page request. // Use the advanced drupal_static() pattern, since this is called very often. @@ -1153,8 +1153,8 @@ function template_preprocess(&$variables, $context) { // When theming a render element, merge its #attributes into // $variables['attributes']. - if (isset($context['info']['render element'])) { - $key = $context['info']['render element']; + if (isset($info['render element'])) { + $key = $info['render element']; if (isset($variables[$key]['#attributes'])) { $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $variables[$key]['#attributes']); } @@ -1292,7 +1292,7 @@ function template_preprocess_html(&$variables) { * inside "modules/system/page.html.twig". Look in there for the full list of * variables. */ -function template_preprocess_page(&$variables, $context) { +function template_preprocess_page(&$variables) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); $site_config = \Drupal::config('system.site'); @@ -1334,11 +1334,6 @@ function template_preprocess_page(&$variables, $context) { if ($node = \Drupal::routeMatch()->getParameter('node')) { $variables['node'] = $node; } - - // @todo Remove once https://drupal.org/node/939462 is fixed. - if ($context['suggestion'] !== 'page' && function_exists($function = 'template_preprocess_' . $context['suggestion'])) { - $function($variables, $context); - } } /** @@ -1477,7 +1472,7 @@ function template_preprocess_region(&$variables) { * - attributes: A string containing the attributes for the wrapping div. * - title_attributes: A string containing the attributes for the title. */ -function template_preprocess_field(&$variables) { +function template_preprocess_field(&$variables, $hook) { $element = $variables['element']; // Creating variables for the template. @@ -1673,13 +1668,9 @@ function drupal_common_theme() { ), 'page__maintenance' => array( 'base hook' => 'page', - 'render element' => 'page', - 'template' => 'page--maintenance', ), 'page__maintenance__install' => array( 'base hook' => 'page', - 'render element' => 'page', - 'template' => 'page--maintenance--install', ), 'region' => array( 'render element' => 'elements', diff --git a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php index 92071da..bb2a215 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php @@ -106,7 +106,7 @@ public function onKernelRequestMaintenance(GetResponseEvent $event) { $content = Xss::filterAdmin(SafeMarkup::format($this->config->get('system.maintenance')->get('message'), array( '@site' => $this->config->get('system.site')->get('name'), ))); - $response = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $content], $this->t('Site under maintenance'), 'maintenance_page'); + $response = $this->bareHtmlPageRenderer->renderBarePage(['#markup' => $content], $this->t('Site under maintenance'), 'page__maintenance'); $response->setStatusCode(503); $event->setResponse($response); } diff --git a/core/lib/Drupal/Core/Render/BareHtmlPageRendererInterface.php b/core/lib/Drupal/Core/Render/BareHtmlPageRendererInterface.php index 9e1f8ee..7a85e64 100644 --- a/core/lib/Drupal/Core/Render/BareHtmlPageRendererInterface.php +++ b/core/lib/Drupal/Core/Render/BareHtmlPageRendererInterface.php @@ -38,9 +38,9 @@ * in a limited environment). * * Currently, there are two types of bare pages available: - * - Install (hook_preprocess_install_page(), install-page.html.twig). - * - Maintenance (hook_preprocess_maintenance_page(), - * maintenance-page.html.twig). + * - Install (hook_preprocess__page__maintenance__install(), page--maintenance--install.html.twig). + * - Maintenance (hook_preprocess_page__maintenance(), + * page--maintenance.html.twig). * * @see \Drupal\Core\Render\MainContent\HtmlRenderer */ diff --git a/core/lib/Drupal/Core/Render/theme.api.php b/core/lib/Drupal/Core/Render/theme.api.php index 7e00e38..e9144cf 100644 --- a/core/lib/Drupal/Core/Render/theme.api.php +++ b/core/lib/Drupal/Core/Render/theme.api.php @@ -483,32 +483,29 @@ function hook_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormSta * * @param $variables * The variables array (modify in place). - * @param $context - * The context for which this preprocess function is running. This includes: - * - hook: - * @todo Document this after figuring out what it is. It's not necessarily - * the same as what was passed to _theme() as $hook, nor is it - * necessarily the same as 'suggestion'. What is it? - * - suggestions: The array of theme hook suggestions that were searched in - * order to find one that was implemented via a template or function. - * - suggestion: The theme hook suggestion that was found and therefore - * will be rendered after variable processing is complete. - * - info: The theme registry information for the matching hook/suggestion. -*/ -function hook_preprocess(&$variables, $context) { + * @param $hook + * The name of the theme hook. + */ +function hook_preprocess(&$variables, $hook) { + static $hooks; + // Add contextual links to the variables, if the user has permission. if (!\Drupal::currentUser()->hasPermission('access contextual links')) { return; } + if (!isset($hooks)) { + $hooks = theme_get_registry(); + } + // Determine the primary theme function argument. - if (isset($context['info']['variables'])) { - $keys = array_keys($context['info']['variables']); + if (isset($hooks[$hook]['variables'])) { + $keys = array_keys($hooks[$hook]['variables']); $key = $keys[0]; } else { - $key = $context['info']['render element']; + $key = $hooks[$hook]['render element']; } if (isset($variables[$key])) { diff --git a/core/lib/Drupal/Core/Theme/ThemeManager.php b/core/lib/Drupal/Core/Theme/ThemeManager.php index c2b76fe..9958b56 100644 --- a/core/lib/Drupal/Core/Theme/ThemeManager.php +++ b/core/lib/Drupal/Core/Theme/ThemeManager.php @@ -287,15 +287,9 @@ public function render($hook, array $variables) { } } if (isset($info['preprocess functions'])) { - $context = array( - 'hook' => $hook, - 'suggestions' => $suggestions, - 'suggestion' => isset($suggestion) ? $suggestion : NULL, - 'info' => $info, - ); foreach ($info['preprocess functions'] as $preprocessor_function) { if (function_exists($preprocessor_function)) { - $preprocessor_function($variables, $context); + $preprocessor_function($variables, $hook, $info); } } // Allow theme preprocess functions to set $variables['#attached'] and @@ -359,13 +353,7 @@ public function render($hook, array $variables) { // adding some new variable to track that. if (!isset($variables['directory'])) { $default_template_variables = array(); - $context = array( - 'hook' => $hook, - 'suggestions' => $suggestions, - 'suggestion' => isset($suggestion) ? $suggestion : NULL, - 'info' => $info, - ); - template_preprocess($default_template_variables, $context); + template_preprocess($default_template_variables, $hook, $info); $variables += $default_template_variables; } if (!isset($default_attributes)) { diff --git a/core/modules/contextual/contextual.module b/core/modules/contextual/contextual.module index 088b998..a672e4e 100644 --- a/core/modules/contextual/contextual.module +++ b/core/modules/contextual/contextual.module @@ -101,14 +101,14 @@ function contextual_help($route_name, RouteMatchInterface $route_match) { * @see contextual_page_attachments() * @see \Drupal\contextual\ContextualController::render() */ -function contextual_preprocess(&$variables, $context) { +function contextual_preprocess(&$variables, $hook, $info) { // Determine the primary theme function argument. - if (!empty($context['info']['variables'])) { - $keys = array_keys($context['info']['variables']); + if (!empty($info['variables'])) { + $keys = array_keys($info['variables']); $key = $keys[0]; } - elseif (!empty($context['info']['render element'])) { - $key = $context['info']['render element']; + elseif (!empty($info['render element'])) { + $key = $info['render element']; } if (!empty($key) && isset($variables[$key])) { $element = $variables[$key]; diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index fa8104d..10f66b7 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -186,7 +186,7 @@ public function handle($op, Request $request) { } $title = isset($output['#title']) ? $output['#title'] : $this->t('Drupal database update'); - return $this->bareHtmlPageRenderer->renderBarePage($output, $title, 'maintenance_page', $regions); + return $this->bareHtmlPageRenderer->renderBarePage($output, $title, 'page__maintenance', $regions); } /** diff --git a/core/modules/system/templates/page--maintenance--install.html.twig b/core/modules/system/templates/page--maintenance--install.html.twig index 1d0e479..964821e 100644 --- a/core/modules/system/templates/page--maintenance--install.html.twig +++ b/core/modules/system/templates/page--maintenance--install.html.twig @@ -6,7 +6,7 @@ * All available variables are mirrored in page.html.twig. * Some may be blank but they are provided for consistency. * - * @see template_preprocess_install_page() + * @see template_preprocess_page__maintenance__install() * * @ingroup themeable */ diff --git a/core/modules/system/templates/page--maintenance.html.twig b/core/modules/system/templates/page--maintenance.html.twig index 748ed5a..6ca60fd 100644 --- a/core/modules/system/templates/page--maintenance.html.twig +++ b/core/modules/system/templates/page--maintenance.html.twig @@ -6,7 +6,7 @@ * All available variables are mirrored in page.html.twig. * Some may be blank but they are provided for consistency. * - * @see template_preprocess_maintenance_page() + * @see template_preprocess_page__maintenance() * * @ingroup themeable */ diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme index 759e193..7baf9ad 100644 --- a/core/themes/bartik/bartik.theme +++ b/core/themes/bartik/bartik.theme @@ -39,7 +39,7 @@ function bartik_preprocess_html(&$variables) { /** * Implements hook_preprocess_HOOK() for page templates. */ -function bartik_preprocess_page(&$variables, $context) { +function bartik_preprocess_page(&$variables) { // Set the options that apply to both page and maintenance page. _bartik_process_page($variables); @@ -59,11 +59,6 @@ function bartik_preprocess_page(&$variables, $context) { // Make sure the shortcut link is the first item in title_suffix. $variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100; } - - // @todo Remove once https://drupal.org/node/939462 is fixed. - if ($context['suggestion'] !== 'page' && function_exists($function = 'bartik_preprocess_' . $context['suggestion'])) { - $function($variables, $context); - } } /** @@ -73,7 +68,7 @@ function bartik_preprocess_page__maintenance(&$variables) { // By default, site_name is set to Drupal if no db connection is available // or during site installation. Setting site_name to an empty string makes // the site and update pages look cleaner. - // @see template_preprocess_maintenance_page + // @see template_preprocess_page__maintenance if (!$variables['db_is_active']) { $variables['site_name'] = ''; } diff --git a/core/themes/bartik/templates/page--maintenance.html.twig b/core/themes/bartik/templates/page--maintenance.html.twig index 3cd787b..f414e47 100644 --- a/core/themes/bartik/templates/page--maintenance.html.twig +++ b/core/themes/bartik/templates/page--maintenance.html.twig @@ -5,7 +5,7 @@ * * All available variables are mirrored in page.html.twig. * - * @see template_preprocess_maintenance_page() + * @see template_preprocess_page__maintenance() */ #}
diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme index b0f559b..b10be99 100644 --- a/core/themes/seven/seven.theme +++ b/core/themes/seven/seven.theme @@ -26,18 +26,13 @@ function seven_preprocess_html(&$variables) { /** * Implements hook_preprocess_HOOK() for page templates. */ -function seven_preprocess_page(&$variables, $context) { +function seven_preprocess_page(&$variables) { $variables['primary_local_tasks'] = $variables['tabs']; unset($variables['primary_local_tasks']['#secondary']); $variables['secondary_local_tasks'] = array( '#theme' => 'menu_local_tasks', '#secondary' => isset($variables['tabs']['#secondary']) ? $variables['tabs']['#secondary'] : '', ); - - // @todo Remove once https://drupal.org/node/939462 is fixed. - if ($context['suggestion'] !== 'page' && function_exists($function = 'seven_preprocess_' . $context['suggestion'])) { - $function($variables, $context); - } } /** diff --git a/core/themes/seven/templates/page--maintenance--install.html.twig b/core/themes/seven/templates/page--maintenance--install.html.twig index b501fb8..d8e28fa 100644 --- a/core/themes/seven/templates/page--maintenance--install.html.twig +++ b/core/themes/seven/templates/page--maintenance--install.html.twig @@ -6,7 +6,7 @@ * All available variables are mirrored in page.html.twig. * Some may be blank but they are provided for consistency. * - * @see template_preprocess_install_page() + * @see template_preprocess_page__maintenance__install() */ #}