3 namespace Drupal\theme_test;
5 use Drupal\Core\Controller\ControllerBase;
6 use Symfony\Component\HttpFoundation\JsonResponse;
9 * Controller routines for theme test routes.
11 class ThemeTestController extends ControllerBase {
14 * A theme template that overrides a theme function.
17 * Render array containing a theme.
19 public function functionTemplateOverridden() {
21 '#theme' => 'theme_test_function_template_override',
26 * Adds stylesheets to test theme .info.yml property processing.
29 * A render array containing custom stylesheets.
31 public function testInfoStylesheets() {
35 'theme_test/theme_stylesheets_override_and_remove_test',
42 * Tests template overriding based on filename.
45 * A render array containing a theme override.
47 public function testTemplate() {
48 return ['#markup' => \Drupal::theme()->render('theme_test_template_test', [])];
52 * Tests the inline template functionality.
55 * A render array containing an inline template.
57 public function testInlineTemplate() {
60 '#type' => 'inline_template',
61 '#template' => 'test-with-context {{ llama }}',
62 '#context' => ['llama' => 'muuh'],
68 * Calls a theme hook suggestion.
71 * An HTML string containing the themed output.
73 public function testSuggestion() {
74 return ['#markup' => \Drupal::theme()->render(['theme_test__suggestion', 'theme_test'], [])];
78 * Tests themed output generated in a request listener.
81 * Content in theme_test_output GLOBAL.
83 public function testRequestListener() {
84 return ['#markup' => $GLOBALS['theme_test_output']];
88 * Menu callback for testing suggestion alter hooks with template files.
90 public function suggestionProvided() {
91 return ['#theme' => 'theme_test_suggestion_provided'];
95 * Menu callback for testing suggestion alter hooks with template files.
97 public function suggestionAlter() {
98 return ['#theme' => 'theme_test_suggestions'];
102 * Menu callback for testing hook_theme_suggestions_alter().
104 public function generalSuggestionAlter() {
105 return ['#theme' => 'theme_test_general_suggestions'];
109 * Menu callback for testing suggestion alter hooks with specific suggestions.
111 public function specificSuggestionAlter() {
112 return ['#theme' => 'theme_test_specific_suggestions__variant'];
116 * Menu callback for testing suggestion alter hooks with theme functions.
118 public function functionSuggestionAlter() {
119 return ['#theme' => 'theme_test_function_suggestions'];
124 * Menu callback for testing includes with suggestion alter hooks.
126 public function suggestionAlterInclude() {
127 return ['#theme' => 'theme_test_suggestions_include'];
131 * Controller to ensure that no theme is initialized.
133 * @return \Symfony\Component\HttpFoundation\JsonResponse
134 * The json response with the theme initialized information.
136 public function nonHtml() {
137 $theme_initialized = \Drupal::theme()->hasActiveTheme();
138 return new JsonResponse(['theme_initialized' => $theme_initialized]);
142 * Controller for testing preprocess functions with theme suggestions.
144 public function preprocessSuggestions() {
147 '#theme' => 'theme_test_preprocess_suggestions',
148 '#foo' => 'suggestion',
151 '#theme' => 'theme_test_preprocess_suggestions',
155 '#theme' => 'theme_test_preprocess_suggestions',
158 ['#theme' => 'theme_test_preprocess_suggestions__kitten__flamingo'],