You are here

theme_legacy_test.module in Drupal 9

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 via drupal_render().
 *
 * Theme hooks defining a 'render element' add an internal '#render_children'
 * property. When this property is found, drupal_render() avoids calling
 * the 'theme.manager' service '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

Namesort descending Description
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 via drupal_render().
theme_theme_test_suggestions_include Returns HTML for a theme function include test.