test_theme.theme
Same filename in other branches
Theme to help test the Twig engine.
File
-
core/
modules/ system/ tests/ themes/ test_theme/ test_theme.theme
View source
<?php
/**
* @file
* Theme to help test the Twig engine.
*/
/**
* Implements THEME_preprocess_twig_theme_test_php_variables().
*/
function test_theme_preprocess_twig_theme_test_php_variables(&$variables) {
$variables['php_values'] = _test_theme_twig_php_values();
}
/**
* Implements hook_element_info_alter().
*/
function test_theme_element_info_alter(&$info) {
// Decrease the default size of textfields.
if (isset($info['textfield']['#size'])) {
$info['textfield']['#size'] = 40;
}
}
/**
* Implements hook_library_info_alter().
*/
function test_theme_library_info_alter(&$libraries, $extension) {
if ($extension === 'test_theme') {
$libraries['kitten']['js']['kittens.js'] = [];
}
}
/**
* Tests a theme implementing an alter hook.
*
* The confusing function name here is due to this being an implementation of
* the alter hook invoked when the 'theme_test' module calls
* \Drupal::moduleHandler->alter('theme_test_alter').
*/
function test_theme_theme_test_alter_alter(&$data) {
$data = 'test_theme_theme_test_alter_alter was invoked';
}
/**
* Implements hook_theme_suggestions_alter().
*/
function test_theme_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) {
\Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.');
// Theme alter hooks run after module alter hooks, so add this theme
// suggestion to the beginning of the array so that the suggestion added by
// the theme_suggestions_test module can be picked up when that module is
// enabled.
if ($hook == 'theme_test_general_suggestions') {
array_unshift($suggestions, 'theme_test_general_suggestions__' . 'theme_override');
$variables['theme_hook'] = 'test_theme_theme_suggestions_alter';
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function test_theme_theme_suggestions_theme_test_suggestions_alter(array &$suggestions, array $variables) {
\Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.');
// Theme alter hooks run after module alter hooks, so add this theme
// suggestion to the beginning of the array so that the suggestion added by
// the theme_suggestions_test module can be picked up when that module is
// enabled.
array_unshift($suggestions, 'theme_test_suggestions__' . 'theme_override');
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function test_theme_theme_suggestions_node_alter(array &$suggestions, array $variables) {
// Add an invalid suggestion to be tested.
$suggestions[] = 'invalid_theme_suggestions';
\Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.');
}
/**
* Implements hook_theme_registry_alter().
*/
function test_theme_theme_registry_alter(&$registry) {
$registry['theme_test_template_test']['variables']['additional'] = 'value';
}
/**
* Tests a theme overriding a default hook with a suggestion.
*
* Implements hook_preprocess_HOOK().
*/
function test_theme_preprocess_theme_test_preprocess_suggestions(&$variables) {
$variables['foo'] = 'Theme hook implementor=test_theme_preprocess_theme_test_preprocess_suggestions().';
}
/**
* Tests a theme overriding a default hook with a suggestion.
*/
function test_theme_preprocess_theme_test_preprocess_suggestions__suggestion(&$variables) {
$variables['foo'] = 'Suggestion';
}
/**
* Tests a theme overriding a default hook with a suggestion.
*/
function test_theme_preprocess_theme_test_preprocess_suggestions__kitten(&$variables) {
$variables['foo'] = 'Kitten';
}
/**
* Tests a theme overriding a default hook with a suggestion.
*/
function test_theme_preprocess_theme_test_preprocess_suggestions__kitten__flamingo(&$variables) {
$variables['bar'] = 'Flamingo';
}
/**
* Tests a preprocess function with suggestions.
*/
function test_theme_preprocess_theme_test_preprocess_suggestions__kitten__meerkat__tarsier__moose(&$variables) {
$variables['bar'] = 'Moose';
}
/**
* Tests that a class can be loaded within a .theme file.
*/
function test_theme_preprocess_theme_test_theme_class(&$variables) {
if (class_exists('\\Drupal\\test_theme\\ThemeClass')) {
$variables['message'] = 'Loading ThemeClass was successful.';
}
else {
$variables['message'] = 'Loading ThemeClass failed.';
}
}
Functions
Title | Deprecated | Summary |
---|---|---|
test_theme_element_info_alter | Implements hook_element_info_alter(). | |
test_theme_library_info_alter | Implements hook_library_info_alter(). | |
test_theme_preprocess_theme_test_preprocess_suggestions | Tests a theme overriding a default hook with a suggestion. | |
test_theme_preprocess_theme_test_preprocess_suggestions__kitten | Tests a theme overriding a default hook with a suggestion. | |
test_theme_preprocess_theme_test_preprocess_suggestions__kitten__flamingo | Tests a theme overriding a default hook with a suggestion. | |
test_theme_preprocess_theme_test_preprocess_suggestions__kitten__meerkat__tarsier__moose | Tests a preprocess function with suggestions. | |
test_theme_preprocess_theme_test_preprocess_suggestions__suggestion | Tests a theme overriding a default hook with a suggestion. | |
test_theme_preprocess_theme_test_theme_class | Tests that a class can be loaded within a .theme file. | |
test_theme_preprocess_twig_theme_test_php_variables | Implements THEME_preprocess_twig_theme_test_php_variables(). | |
test_theme_theme_registry_alter | Implements hook_theme_registry_alter(). | |
test_theme_theme_suggestions_alter | Implements hook_theme_suggestions_alter(). | |
test_theme_theme_suggestions_node_alter | Implements hook_theme_suggestions_HOOK_alter(). | |
test_theme_theme_suggestions_theme_test_suggestions_alter | Implements hook_theme_suggestions_HOOK_alter(). | |
test_theme_theme_test_alter_alter | Tests a theme implementing an alter hook. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.