theme_test.module
Same filename in other branches
File
-
core/
modules/ system/ tests/ modules/ theme_test/ theme_test.module
View source
<?php
/**
* @file
* Test module.
*/
declare (strict_types=1);
/**
* Implements hook_preprocess_HOOK() for HTML document templates.
*/
function theme_test_preprocess_html(&$variables) : void {
$variables['html_attributes']['theme_test_html_attribute'] = 'theme test html attribute value';
$variables['attributes']['theme_test_body_attribute'] = 'theme test body attribute value';
$variables['attributes']['theme_test_page_variable'] = 'Page variable is an array.';
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function theme_test_theme_suggestions_theme_test_preprocess_suggestions($variables) {
return [
'theme_test_preprocess_suggestions__' . $variables['foo'],
];
}
/**
* Implements hook_preprocess_HOOK().
*/
function theme_test_preprocess_theme_test_preprocess_suggestions(&$variables) : void {
$variables['foo'] = 'Theme hook implementor=theme_theme_test_preprocess_suggestions().';
}
/**
* Tests a module overriding a default hook with a suggestion.
*/
function theme_test_preprocess_theme_test_preprocess_suggestions__monkey(&$variables) : void {
$variables['foo'] = 'Monkey';
}
/**
* Prepares variables for test render element templates.
*
* Default template: theme-test-render-element.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the properties of the element.
*/
function template_preprocess_theme_test_render_element(&$variables) : void {
$variables['attributes']['data-variables-are-preprocessed'] = TRUE;
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function theme_test_theme_suggestions_theme_test_suggestion_provided(array $variables) {
return [
'theme_test_suggestion_provided__foo',
];
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function theme_test_theme_suggestions_node(array $variables) {
$xss = '<script type="text/javascript">alert(\'yo\');</script>';
$suggestions[] = 'node__' . $xss;
return $suggestions;
}
/**
* Implements template_preprocess_HOOK() for theme_test_registered_by_module.
*/
function template_preprocess_theme_test_registered_by_module() : void {
}
/**
* Implements template_preprocess_HOOK() for theme_test_deprecations_preprocess.
*
* Default template: theme-test-deprecations-preprocess.html.twig.
*
* @param array $variables
* An associative array of variables.
*/
function template_preprocess_theme_test_deprecations_preprocess(array &$variables) : void {
$variables = array_merge($variables, \Drupal::state()->get('theme_test.theme_test_deprecations_preprocess'));
}
Functions
Title | Deprecated | Summary |
---|---|---|
template_preprocess_theme_test_deprecations_preprocess | Implements template_preprocess_HOOK() for theme_test_deprecations_preprocess. | |
template_preprocess_theme_test_registered_by_module | Implements template_preprocess_HOOK() for theme_test_registered_by_module. | |
template_preprocess_theme_test_render_element | Prepares variables for test render element templates. | |
theme_test_preprocess_html | Implements hook_preprocess_HOOK() for HTML document templates. | |
theme_test_preprocess_theme_test_preprocess_suggestions | Implements hook_preprocess_HOOK(). | |
theme_test_preprocess_theme_test_preprocess_suggestions__monkey | Tests a module overriding a default hook with a suggestion. | |
theme_test_theme_suggestions_node | Implements hook_theme_suggestions_HOOK(). | |
theme_test_theme_suggestions_theme_test_preprocess_suggestions | Implements hook_theme_suggestions_HOOK(). | |
theme_test_theme_suggestions_theme_test_suggestion_provided | Implements hook_theme_suggestions_HOOK(). |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.