Drupal  8.3.5
APl Documentation
Theme system overview


 template_preprocess_system_modules_uninstall (&$variables)

Detailed Description

Functions and templates for the user interface that themes can override.

Drupal's theme system allows a theme to have nearly complete control over the appearance of the site, which includes both the markup and the CSS used to style the markup. For this system to work, modules, instead of writing HTML markup directly, need to return "render arrays", which are structured hierarchical arrays that include the data to be rendered into HTML (or XML or another output format), and options that affect the markup. Render arrays are ultimately rendered into HTML or other output formats by recursive calls to drupal_render(), traversing the depth of the render array hierarchy. At each level, the theme system is invoked to do the actual rendering. See the documentation of drupal_render() and the Theme system and Render API topic for more information about render arrays and rendering.

Twig Templating Engine

Drupal 8 uses the templating engine Twig. Twig offers developers a fast, secure, and flexible method for building templates for Drupal 8 sites. Twig also offers substantial usability improvements over PHPTemplate, and does not require front-end developers to know PHP to build and manipulate Drupal 8 themes.

For further information on theming in Drupal 8 see https://www.drupal.org/docs/8/theming

For further Twig documentation see http://twig.sensiolabs.org/doc/templates.html

Theme Hooks

The theme system is invoked in doRender() by calling the render() function, which operates on the concept of "theme hooks". Theme hooks define how a particular type of data should be rendered. They are registered by modules by implementing hook_theme(), which specifies the name of the hook, the input "variables" used to provide data and options, and other information. Modules implementing hook_theme() also need to provide a default implementation for each of their theme hooks, normally in a Twig file, and they may also provide preprocessing functions. For example, the core Search module defines a theme hook for a search result item in search_theme():

return array(
'search_result' => array(
'variables' => array(
'result' => NULL,
'plugin_id' => NULL,
'file' => 'search.pages.inc',

Given this definition, the template file with the default implementation is search-result.html.twig, which can be found in the core/modules/search/templates directory, and the variables for rendering are the search result and the plugin ID. In addition, there is a function template_preprocess_search_result(), located in file search.pages.inc, which preprocesses the information from the input variables so that it can be rendered by the Twig template; the processed variables that the Twig template receives are documented in the header of the default Twig template file.

hook_theme() implementations can also specify that a theme hook implementation is a theme function, but that is uncommon and not recommended. Note that while Twig templates will auto-escape variables, theme functions must explicitly escape any variables by using theme_render_and_autoescape(). Failure to do so is likely to result in security vulnerabilities. Theme functions are deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.x. Use Twig templates instead.

Overriding Theme Hooks

Themes may register new theme hooks within a hook_theme() implementation, but it is more common for themes to override default implementations provided by modules than to register entirely new theme hooks. Themes can override a default implementation by creating a template file with the same name as the default implementation; for example, to override the display of search results, a theme would add a file called search-result.html.twig to its templates directory. A good starting point for doing this is normally to copy the default implementation template, and then modifying it as desired.

In the uncommon case that a theme hook uses a theme function instead of a template file, a module would provide a default implementation function called theme_HOOK, where HOOK is the name of the theme hook (for example, theme_search_result() would be the name of the function for search result theming). In this case, a theme can override the default implementation by defining a function called THEME_HOOK() in its THEME.theme file, where THEME is the machine name of the theme (for example, 'bartik' is the machine name of the core Bartik theme, and it would define a function called bartik_search_result() in the bartik.theme file, if the search_result hook implementation was a function instead of a template). Normally, copying the default function is again a good starting point for overriding its behavior. Again, note that theme functions (unlike templates) must explicitly escape variables using theme_render_and_autoescape() or risk security vulnerabilities. Theme functions are deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.x. Use Twig templates instead.

Preprocessing for Template Files

If the theme implementation is a template file, several functions are called before the template file is invoked to modify the variables that are passed to the template. 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 hook being called or a less specific hook. For example, if 'theme' => 'node__article' is called, hook is node__article and node. MODULE indicates a module name, THEME indicates a theme name, and ENGINE indicates a theme engine name). Modules, themes, and theme engines can provide these functions to modify how the data is preprocessed, before it is passed to the theme template:

Preprocessing for Theme Functions

If the theming implementation is a function, only the theme-hook-specific preprocess 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.

Theme hook suggestions

In some cases, instead of calling the base theme hook implementation (either the default provided by the module that defined the hook, or the override provided by the theme), the theme system will instead look for "suggestions" of other hook names to look for. Suggestions can be specified in several ways:

For further information on overriding theme hooks see https://www.drupal.org/node/2186401

Altering theme hook suggestions

Modules can also alter the theme suggestions provided using the mechanisms of the previous section. There are two hooks for this: the theme-hook-specific hook_theme_suggestions_HOOK_alter() and the generic hook_theme_suggestions_alter(). These hooks get the current list of suggestions as input, and can change this array (adding suggestions and removing them).


We can distinguish between three types of assets:

See also
Render API overview

Function Documentation

◆ template_preprocess_system_modules_uninstall()

template_preprocess_system_modules_uninstall ( $variables)

Prepares variables for module uninstall templates.

Default template: system-modules-uninstall.html.twig.

$variablesAn associative array containing:
  • form: A render element representing the form. Child elements of the form are individual modules. Each module is an associative array containing the following elements:
    • #module_name: The name of the module as a string.
    • name: The name of the module in a renderable array.
    • description: A description of the module.
    • #required_by: (optional) A list of modules that require the module.
    • #validation_reasons: (optional) Additional reasons why the module cannot be uninstalled.
    • attributes: A list of attributes for the module wrapper.

Definition at line 206 of file system.admin.inc.