theme_legacy_test.module

Same filename in other branches
  1. 8.9.x core/modules/system/tests/modules/theme_legacy_test/theme_legacy_test.module

Test module for legacy theme functions.

@todo Remove in https://www.drupal.org/project/drupal/issues/3097889

File

core/modules/system/tests/modules/theme_legacy_test/theme_legacy_test.module

View source
<?php


/**
 * @file
 * Test module for legacy theme functions.
 *
 * @todo Remove in https://www.drupal.org/project/drupal/issues/3097889
 */

/**
 * Implements hook_theme().
 */
function theme_legacy_test_theme($existing, $type, $theme, $path) {
    $items['theme_test'] = [
        'file' => 'theme_legacy_test.inc',
        'variables' => [
            'foo' => '',
        ],
        'function' => 'theme_theme_test',
    ];
    $items['theme_test_function_suggestions'] = [
        'variables' => [],
        'function' => 'theme_theme_test_function_suggestions',
    ];
    $items['theme_test_suggestions_include'] = [
        'variables' => [],
        'function' => 'theme_theme_test_suggestions_include',
    ];
    $items['theme_test_foo'] = [
        'variables' => [
            'foo' => NULL,
        ],
        'function' => 'theme_theme_test_foo',
    ];
    $items['theme_test_render_element_children'] = [
        'render element' => 'element',
        'function' => 'theme_theme_test_render_element_children',
    ];
    $items['theme_test_function_template_override'] = [
        'variables' => [],
        'function' => 'theme_theme_test_function_template_override',
    ];
    $info['test_theme_not_existing_function'] = [
        'function' => 'test_theme_not_existing_function',
    ];
    return $items;
}

/**
 * Implements template_preprocess_HOOK() for theme_test_function_suggestions theme functions.
 */
function template_preprocess_theme_test_function_suggestions(&$variables) {
}

/**
 * Theme function for hook theme_test_foo.
 */
function theme_theme_test_foo($variables) {
    return $variables['foo'];
}

/**
 * Theme function for hook theme_test_function_template_override.
 */
function theme_theme_test_function_template_override($variables) {
    return 'theme_test_function_template_override test failed.';
}

/**
 * Theme function for testing rendering of child elements.
 *
 * Theme hooks defining a 'render element' add an internal '#render_children'
 * property. When this property is found, \Drupal::service('renderer')->render()
 * avoids calling the 'theme.manager' service's ThemeManagerInterface::render()
 * method on the top-level element to prevent infinite recursion.
 *
 * @param array $variables
 *   An associative array containing:
 *   - element: An associative array containing the properties of the element.
 */
function theme_theme_test_render_element_children($variables) {
    return \Drupal::service('renderer')->render($variables['element']);
}

/**
 * Returns HTML for a theme function suggestion test.
 */
function theme_theme_test_function_suggestions($variables) {
    return 'Original theme function.';
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function theme_legacy_test_theme_suggestions_theme_test_suggestion_provided(array $variables) {
    return [
        'theme_test_suggestion_provided__foo',
    ];
}

/**
 * Implements hook_theme_suggestions_alter().
 */
function theme_legacy_test_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
    \Drupal::messenger()->addStatus(__FUNCTION__ . '() executed for ' . $hook . '.');
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function theme_legacy_test_theme_suggestions_theme_test_suggestions_alter(array &$suggestions, array $variables) {
    \Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.');
}

/**
 * Returns HTML for a theme function include test.
 */
function theme_theme_test_suggestions_include($variables) {
    return 'Original function before altering theme suggestions.';
}

Functions

Title Deprecated Summary
template_preprocess_theme_test_function_suggestions Implements template_preprocess_HOOK() for theme_test_function_suggestions theme functions.
theme_legacy_test_theme Implements hook_theme().
theme_legacy_test_theme_suggestions_alter Implements hook_theme_suggestions_alter().
theme_legacy_test_theme_suggestions_theme_test_suggestions_alter Implements hook_theme_suggestions_HOOK_alter().
theme_legacy_test_theme_suggestions_theme_test_suggestion_provided Implements hook_theme_suggestions_HOOK().
theme_theme_test_foo Theme function for hook theme_test_foo.
theme_theme_test_function_suggestions Returns HTML for a theme function suggestion test.
theme_theme_test_function_template_override Theme function for hook theme_test_function_template_override.
theme_theme_test_render_element_children Theme function for testing rendering of child elements.
theme_theme_test_suggestions_include Returns HTML for a theme function include test.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.