From 3fd8e9ef585926912d47effcd8055f43c7bcbf3b Mon Sep 17 00:00:00 2001 From: Mark Carver Date: Fri, 19 Jul 2013 13:37:41 -0500 Subject: Issue #1843650 by Mark Carver, jenlampton, Cottser: [meta] Remove the process layer --- core/includes/theme.inc | 153 ++++++++------------- .../search/templates/search-result.html.twig | 2 +- core/modules/system/templates/html.html.twig | 1 - core/modules/system/templates/page.html.twig | 2 +- core/modules/system/theme.api.php | 58 -------- core/modules/user/user.module | 3 - .../bartik/templates/maintenance-page.html.twig | 1 - core/themes/bartik/templates/page.html.twig | 3 +- core/themes/seven/templates/page.html.twig | 2 +- 9 files changed, 65 insertions(+), 160 deletions(-) diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 7bff76e..77dba8b 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -426,7 +426,6 @@ function drupal_theme_rebuild() { * 'render element' is not specified in a later one, then the previous * definition is kept. * - 'preprocess functions': See theme() for detailed documentation. - * - 'process functions': See theme() for detailed documentation. * @param $name * The name of the module, theme engine, base theme engine, theme or base * theme implementing hook_theme(). @@ -450,11 +449,8 @@ function drupal_theme_rebuild() { function _theme_process_registry(&$cache, $name, $type, $theme, $path) { $result = array(); - // Processor functions work in two distinct phases with the process - // functions always being executed after the preprocess functions. $variable_process_phases = array( 'preprocess functions' => 'preprocess', - 'process functions' => 'process', ); $hook_defaults = array( @@ -466,7 +462,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { $module_list = array_keys(Drupal::moduleHandler()->getModuleList()); - // Invoke the hook_theme() implementation, process what is returned, and + // Invoke the hook_theme() implementation, preprocess what is returned, and // merge it into $cache. $function = $name . '_theme'; if (function_exists($function)) { @@ -517,24 +513,24 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { } } - // Allow variable processors for all theming hooks, whether the hook is + // Allow variable preprocessors for all theming hooks, whether the hook is // implemented as a template or as a function. foreach ($variable_process_phases as $phase_key => $phase) { - // Check for existing variable processors. Ensure arrayness. + // Check for existing variable preprocessors. Ensure arrayness. if (!isset($info[$phase_key]) || !is_array($info[$phase_key])) { $info[$phase_key] = array(); $prefixes = array(); if ($type == 'module') { - // Default variable processor prefix. + // Default variable preprocessor prefix. $prefixes[] = 'template'; // Add all modules so they can intervene with their own variable - // processors. This allows them to provide variable processors even - // if they are not the owner of the current hook. + // preprocessors. This allows them to provide variable preprocessors + // even if they are not the owner of the current hook. $prefixes = array_merge($prefixes, $module_list); } elseif ($type == 'theme_engine' || $type == 'base_theme_engine') { // Theme engines get an extra set that come before the normally - // named variable processors. + // named variable preprocessors. $prefixes[] = $name . '_engine'; // The theme engine registers on behalf of the theme using the // theme's name. @@ -542,12 +538,12 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { } else { // This applies when the theme manually registers their own variable - // processors. + // preprocessors. $prefixes[] = $name; } foreach ($prefixes as $prefix) { - // Only use non-hook-specific variable processors for theming hooks - // implemented as templates. See theme(). + // Only use non-hook-specific variable preprocessors for theming + // hooks implemented as templates. See theme(). if (isset($info['template']) && function_exists($prefix . '_' . $phase)) { $info[$phase_key][] = $prefix . '_' . $phase; } @@ -557,8 +553,8 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { } } // Check for the override flag and prevent the cached variable - // processors from being used. This allows themes or theme engines to - // remove variable processors set earlier in the registry build. + // preprocessors from being used. This allows themes or theme engines + // to remove variable preprocessors set earlier in the registry build. if (!empty($info['override ' . $phase_key])) { // Flag not needed inside the registry. unset($result[$hook]['override ' . $phase_key]); @@ -574,7 +570,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { $cache = $result + $cache; } - // Let themes have variable processors even if they didn't register a + // Let themes have variable preprocessors even if they didn't register a // template. if ($type == 'theme' || $type == 'base_theme') { foreach ($cache as $hook => $info) { @@ -584,7 +580,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { if (!isset($info[$phase_key])) { $cache[$hook][$phase_key] = array(); } - // Only use non-hook-specific variable processors for theming hooks + // Only use non-hook-specific variable preprocessors for theme hooks // implemented as templates. See theme(). if (isset($info['template']) && function_exists($name . '_' . $phase)) { $cache[$hook][$phase_key][] = $name . '_' . $phase; @@ -614,7 +610,7 @@ function _theme_process_registry(&$cache, $name, $type, $theme, $path) { */ function _theme_build_registry($theme, $base_theme, $theme_engine) { $cache = array(); - // First, process the theme hooks advertised by modules. This will + // First, preprocess the theme hooks advertised by modules. This will // serve as the basic registry. Since the list of enabled modules is the same // regardless of the theme used, this is cached in its own entry to save // building it for every theme. @@ -654,7 +650,7 @@ function _theme_build_registry($theme, $base_theme, $theme_engine) { // Optimize the registry to not have empty arrays for functions. foreach ($cache as $hook => $info) { - foreach (array('preprocess functions', 'process functions') as $phase) { + foreach (array('preprocess functions') as $phase) { if (empty($info[$phase])) { unset($cache[$hook][$phase]); } @@ -839,21 +835,21 @@ function drupal_find_base_themes($themes, $key, $used_keys = array()) { * containing a 'page.html.twig' file within its folder structure). * * @subsection sub_preprocess_templates Preprocessing for Template Files - * If the implementation is a template file, several functions are called - * before the template file is invoked, to modify the $variables array. These - * fall into the "preprocessing" phase and the "processing" phase, and are - * executed (if they exist), in the following order (note that in the following - * list, HOOK indicates the theme hook name, MODULE indicates a module name, - * THEME indicates a theme name, and ENGINE indicates a theme engine name): - * - template_preprocess(&$variables, $hook): Creates a default set of - * variables for all theme hooks with template implementations. + * If the implementation is a template file, several functions are called before + * the template file is invoked to modify the $variables array. These make up + * the "preprocessing" phase, and are executed (if they exist), in the following + * order (note that in the following list, HOOK indicates the theme hook name, + * MODULE indicates a module name, THEME indicates a theme name, and ENGINE + * indicates a theme engine name): + * - template_preprocess(&$variables, $hook): Creates a default set of variables + * for all theme hooks with template implementations. * - template_preprocess_HOOK(&$variables): Should be implemented by the module * that registers the theme hook, to set up default variables. * - MODULE_preprocess(&$variables, $hook): hook_preprocess() is invoked on all * implementing modules. * - MODULE_preprocess_HOOK(&$variables): hook_preprocess_HOOK() is invoked on - * all implementing modules, so that modules that didn't define the theme - * hook can alter the variables. + * all implementing modules, so that modules that didn't define the theme hook + * can alter the variables. * - ENGINE_engine_preprocess(&$variables, $hook): Allows the theme engine to * set necessary variables for all theme hooks with template implementations. * - ENGINE_engine_preprocess_HOOK(&$variables): Allows the theme engine to set @@ -862,50 +858,26 @@ function drupal_find_base_themes($themes, $key, $used_keys = array()) { * variables for all theme hooks with template implementations. * - THEME_preprocess_HOOK(&$variables): Allows the theme to set necessary * variables specific to the particular theme hook. - * - template_process(&$variables, $hook): Creates an additional set of default - * variables for all theme hooks with template implementations. The variables - * created in this function are derived from ones created by - * template_preprocess(), but potentially altered by the other preprocess - * functions listed above. For example, any preprocess function can add to or - * modify the $variables['attributes'] variable, and after all of them - * have finished executing, template_process() flattens it into a - * $variables['attributes'] string for convenient use by templates. - * - template_process_HOOK(&$variables): Should be implemented by the module - * that registers the theme hook, if it needs to perform additional variable - * processing after all preprocess functions have finished. - * - MODULE_process(&$variables, $hook): hook_process() is invoked on all - * implementing modules. - * - MODULE_process_HOOK(&$variables): hook_process_HOOK() is invoked on - * on all implementing modules, so that modules that didn't define the theme - * hook can alter the variables. - * - ENGINE_engine_process(&$variables, $hook): Allows the theme engine to - * process variables for all theme hooks with template implementations. - * - ENGINE_engine_process_HOOK(&$variables): Allows the theme engine to process - * the variables specific to the theme hook. - * - THEME_process(&$variables, $hook): Allows the theme to process the - * variables for all theme hooks with template implementations. - * - THEME_process_HOOK(&$variables): Allows the theme to process the - * variables specific to the theme hook. * * @subsection sub_preprocess_theme_funcs Preprocessing for Theme Functions * If the implementation is a function, only the theme-hook-specific preprocess - * and process functions (the ones ending in _HOOK) are called from the - * list above. This is because theme hooks with function implementations - * need to be fast, and calling the non-theme-hook-specific preprocess and - * process functions for them would incur a noticeable performance penalty. + * functions (the ones ending in _HOOK) are called from the list above. This is + * because theme hooks with function implementations need to be fast, and + * calling the non-theme-hook-specific preprocess functions for them would incur + * a noticeable performance penalty. * * @subsection sub_alternate_suggestions Suggesting Alternate Hooks - * There are two special variables that these preprocess and process functions - * can set: 'theme_hook_suggestion' and 'theme_hook_suggestions'. These will be - * merged together to form a list of 'suggested' alternate theme hooks to use, - * in reverse order of priority. theme_hook_suggestion will always be a higher - * priority than items in theme_hook_suggestions. theme() will use the - * highest priority implementation that exists. If none exists, theme() will - * use the implementation for the theme hook it was called with. These - * suggestions are similar to and are used for similar reasons as calling - * theme() with an array as the $hook parameter (see below). The difference - * is whether the suggestions are determined by the code that calls theme() or - * by a preprocess or process function. + * There are two special variables that these preprocess functions can set: + * 'theme_hook_suggestion' and 'theme_hook_suggestions'. These will be merged + * together to form a list of 'suggested' alternate theme hooks to use, in + * reverse order of priority. theme_hook_suggestion will always be a higher + * priority than items in theme_hook_suggestions. theme() will use the highest + * priority implementation that exists. If none exists, theme() will use the + * implementation for the theme hook it was called with. These suggestions are + * similar to, and are used for similar reasons as, calling theme() with an + * array as the $hook parameter (see below). The difference is whether the + * suggestions are determined by the code that calls theme() or by a preprocess + * function. * * @param $hook * The name of the theme hook to call. If the name contains a @@ -927,11 +899,10 @@ function drupal_find_base_themes($themes, $key, $used_keys = array()) { * convention is not desired or is insufficient. * @param $variables * An associative array of variables to merge with defaults from the theme - * registry, pass to preprocess and process functions for modification, and - * finally, pass to the function or template implementing the theme hook. - * Alternatively, this can be a renderable array, in which case, its - * properties are mapped to variables expected by the theme hook - * implementations. + * registry, pass to preprocess functions for modification, and finally, pass + * to the function or template implementing the theme hook. Alternatively, + * this can be a renderable array, in which case, its properties are mapped to + * variables expected by the theme hook implementations. * * @return string|false * An HTML string representing the themed output or FALSE if the passed $hook @@ -940,7 +911,6 @@ function drupal_find_base_themes($themes, $key, $used_keys = array()) { * @see themeable * @see hook_theme() * @see template_preprocess() - * @see template_process() */ function theme($hook, $variables = array()) { static $default_attributes; @@ -997,7 +967,7 @@ function theme($hook, $variables = array()) { // point path_to_theme() to the currently used theme path: $theme_path = $info['theme path']; - // Include a file if the theme function or variable processor is held + // Include a file if the theme function or variable preprocessor is held // elsewhere. if (!empty($info['includes'])) { foreach ($info['includes'] as $include_file) { @@ -1036,30 +1006,30 @@ function theme($hook, $variables = array()) { 'theme_hook_original' => $original_hook, ); - // Invoke the variable processors, if any. The processors may specify + // Invoke the variable preprocessors, if any. The preprocessors may specify // alternate suggestions for which hook's template/function to use. If the - // hook is a suggestion of a base hook, invoke the variable processors of + // hook is a suggestion of a base hook, invoke the variable preprocessors of // the base hook, but retain the suggestion as a high priority suggestion to - // be used unless overridden by a variable processor function. + // be used unless overridden by a variable preprocessor function. if (isset($info['base hook'])) { $base_hook = $info['base hook']; $base_hook_info = $hooks[$base_hook]; - // Include files required by the base hook, since its variable processors + // Include files required by the base hook, since its variable preprocessors // might reside there. if (!empty($base_hook_info['includes'])) { foreach ($base_hook_info['includes'] as $include_file) { include_once DRUPAL_ROOT . '/' . $include_file; } } - if (isset($base_hook_info['preprocess functions']) || isset($base_hook_info['process functions'])) { + if (isset($base_hook_info['preprocess functions'])) { $variables['theme_hook_suggestion'] = $hook; $hook = $base_hook; $info = $base_hook_info; } } - if (isset($info['preprocess functions']) || isset($info['process functions'])) { + if (isset($info['preprocess functions'])) { $variables['theme_hook_suggestions'] = array(); - foreach (array('preprocess functions', 'process functions') as $phase) { + foreach (array('preprocess functions') as $phase) { if (!empty($info[$phase])) { foreach ($info[$phase] as $processor_function) { if (function_exists($processor_function)) { @@ -1068,10 +1038,10 @@ function theme($hook, $variables = array()) { } } } - // If the preprocess/process functions specified hook suggestions, and the + // If the preprocess functions specified hook suggestions, and the // suggestion exists in the theme registry, use it instead of the hook that - // theme() was called with. This allows the preprocess/process step to - // route to a more specific theme hook. For example, a function may call + // theme() was called with. This allows the preprocess step to route to a + // more specific theme hook. For example, a function may call // theme('node', ...), but a preprocess function can add 'node__article' as // a suggestion, enabling a theme to have an alternate template file for // article nodes. Suggestions are checked in the following order: @@ -2245,7 +2215,7 @@ function theme_mark($variables) { * * @param array $variables * An associative array containing theme variables for theme_item_list(). - * 'items' in variables will be processed to automatically inherit the + * 'items' in variables will be preprocessed to automatically inherit the * variables of this list to any possibly contained nested lists that do not * specify custom render properties. This allows callers to specify larger * nested lists, without having to explicitly specify and repeat the render @@ -2485,16 +2455,15 @@ function _theme_table_cell($cell, $header = FALSE) { } /** - * Adds a default set of helper variables for variable processors and templates. + * Adds a default set of helper variables for preprocessors and templates. * * This function is called for theme hooks implemented as templates only, not * for theme hooks implemented as functions. This preprocess function is the - * first in the sequence of preprocessing and processing functions that is - * called when preparing variables for a template. See theme() for more details - * about the full sequence. + * first in the sequence of preprocessing functions that are called when + * preparing variables for a template. See theme() for more details about the + * full sequence. * * @see theme() - * @see template_process() */ function template_preprocess(&$variables, $hook, $info) { // Tell all templates where they are located. diff --git a/core/modules/search/templates/search-result.html.twig b/core/modules/search/templates/search-result.html.twig index 9431cca..535ee8e 100644 --- a/core/modules/search/templates/search-result.html.twig +++ b/core/modules/search/templates/search-result.html.twig @@ -53,7 +53,7 @@ * @endcode * * @see template_preprocess_search_result() - * @see template_process() + * @see template_preprocess() * * @ingroup themeable */ diff --git a/core/modules/system/templates/html.html.twig b/core/modules/system/templates/html.html.twig index f2d094e..6bdbe87 100644 --- a/core/modules/system/templates/html.html.twig +++ b/core/modules/system/templates/html.html.twig @@ -22,7 +22,6 @@ * in the head. * * @see template_preprocess_html() - * @see template_process_html() * * @ingroup themeable */ diff --git a/core/modules/system/templates/page.html.twig b/core/modules/system/templates/page.html.twig index b072919..3359932 100644 --- a/core/modules/system/templates/page.html.twig +++ b/core/modules/system/templates/page.html.twig @@ -58,7 +58,7 @@ * - page.footer: Items for the footer region. * * @see template_preprocess_page() - * @see template_process() + * @see template_preprocess() * @see html.html.twig * * @ingroup themeable diff --git a/core/modules/system/theme.api.php b/core/modules/system/theme.api.php index aedc6b0..ebda671 100644 --- a/core/modules/system/theme.api.php +++ b/core/modules/system/theme.api.php @@ -158,64 +158,6 @@ function hook_preprocess_HOOK(&$variables) { } /** - * Process theme variables for templates. - * - * This hook allows modules to process theme variables for theme templates. It - * is called for all theme hooks implemented as templates, but not for theme - * hooks implemented as functions. hook_process_HOOK() can be used to process - * variables for a specific theme hook, whether implemented as a template or - * function. - * - * For more detailed information, see theme(). - * - * @param $variables - * The variables array (modify in place). - * @param $hook - * The name of the theme hook. - * - * @deprecated as of Drupal 8.0, the process layer will be removed. Use - * preprocess instead and pass render arrays or objects with __toString() - * methods to templates and theme functions. - */ -function hook_process(&$variables, $hook) { - // Wraps variables in RDF wrappers. - if (!empty($variables['rdf_template_variable_attributes'])) { - foreach ($variables['rdf_template_variable_attributes'] as $variable_name => $attributes) { - $context = array( - 'hook' => $hook, - 'variable_name' => $variable_name, - 'variables' => $variables, - ); - $variables[$variable_name] = theme('rdf_template_variable_wrapper', array('content' => $variables[$variable_name], 'attributes' => $attributes, 'context' => $context)); - } - } -} - -/** - * Process theme variables for a specific theme hook. - * - * This hook allows modules to process theme variables for a specific theme - * hook. It should only be used if a module needs to override or add to the - * theme processing for a theme hook it didn't define. - * - * For more detailed information, see theme(). - * - * @param $variables - * The variables array (modify in place). - * - * @deprecated as of Drupal 8.0, the process layer will be removed. Use - * preprocess instead and pass render arrays or objects with __toString() - * methods to templates and theme functions. - */ -function hook_process_HOOK(&$variables) { - // @todo There are no use-cases in Drupal core for this hook. Find one from a - // contributed module, or come up with a good example. Coming up with a good - // example might be tough, since the intent is for nearly everything to be - // achievable via preprocess functions, and for process functions to only be - // used when requiring the later execution time. -} - -/** * Respond to themes being enabled. * * @param array $theme_list diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 5127a4c..348ded4 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -686,8 +686,6 @@ function user_template_preprocess_default_variables_alter(&$variables) { * Modules that make any changes to variables like 'name' or 'extra' must ensure * that the final string is safe to include directly in the output by using * check_plain() or filter_xss(). - * - * @see template_process_username() */ function template_preprocess_username(&$variables) { $account = $variables['account'] ?: drupal_anonymous_user(); @@ -748,7 +746,6 @@ function template_preprocess_username(&$variables) { * Drupal\Core\Template\Attribute class if not linking to the user's page. * * @see template_preprocess_username() - * @see template_process_username() */ function theme_username($variables) { if (isset($variables['link_path'])) { diff --git a/core/themes/bartik/templates/maintenance-page.html.twig b/core/themes/bartik/templates/maintenance-page.html.twig index 1e44d52..4aaa0a5 100644 --- a/core/themes/bartik/templates/maintenance-page.html.twig +++ b/core/themes/bartik/templates/maintenance-page.html.twig @@ -6,7 +6,6 @@ * All of the available variables are mirrored in page.html.twig. * * @see template_preprocess_maintenance_page() - * @see bartik_process_maintenance_page() * * @ingroup themeable */ diff --git a/core/themes/bartik/templates/page.html.twig b/core/themes/bartik/templates/page.html.twig index 35c7102..3134ed2 100644 --- a/core/themes/bartik/templates/page.html.twig +++ b/core/themes/bartik/templates/page.html.twig @@ -72,10 +72,9 @@ * - page.footer_fourthcolumn: Items for the fourth footer column. * - page.footer: Items for the footer region. * + * @see template_preprocess() * @see template_preprocess_page() * @see bartik_preprocess_page() - * @see template_process() - * @see bartik_process_page() * @see html.html.twig * * @ingroup themeable diff --git a/core/themes/seven/templates/page.html.twig b/core/themes/seven/templates/page.html.twig index aa8fd01..29d033b 100644 --- a/core/themes/seven/templates/page.html.twig +++ b/core/themes/seven/templates/page.html.twig @@ -59,8 +59,8 @@ * - page.footer: Items for the footer region. * * @see template_preprocess_page() + * @see template_preprocess() * @see seven_preprocess_page() - * @see template_process() * @see html.html.twig * * @ingroup themeable -- 1.8.2