Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / modules / theme_test / src / ThemeTestController.php
1 <?php
2
3 namespace Drupal\theme_test;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Symfony\Component\HttpFoundation\JsonResponse;
7
8 /**
9  * Controller routines for theme test routes.
10  */
11 class ThemeTestController extends ControllerBase {
12
13   /**
14    * A theme template that overrides a theme function.
15    *
16    * @return array
17    *   Render array containing a theme.
18    */
19   public function functionTemplateOverridden() {
20     return [
21       '#theme' => 'theme_test_function_template_override',
22     ];
23   }
24
25   /**
26    * Adds stylesheets to test theme .info.yml property processing.
27    *
28    * @return array
29    *   A render array containing custom stylesheets.
30    */
31   public function testInfoStylesheets() {
32     return [
33       '#attached' => [
34         'library' => [
35           'theme_test/theme_stylesheets_override_and_remove_test',
36         ],
37       ],
38     ];
39   }
40
41   /**
42    * Tests template overriding based on filename.
43    *
44    * @return array
45    *   A render array containing a theme override.
46    */
47   public function testTemplate() {
48     return ['#markup' => \Drupal::theme()->render('theme_test_template_test', [])];
49   }
50
51   /**
52    * Tests the inline template functionality.
53    *
54    * @return array
55    *   A render array containing an inline template.
56    */
57   public function testInlineTemplate() {
58     $element = [];
59     $element['test'] = [
60       '#type' => 'inline_template',
61       '#template' => 'test-with-context {{ llama }}',
62       '#context' => ['llama' => 'muuh'],
63     ];
64     return $element;
65   }
66
67   /**
68    * Calls a theme hook suggestion.
69    *
70    * @return string
71    *   An HTML string containing the themed output.
72    */
73   public function testSuggestion() {
74     return ['#markup' => \Drupal::theme()->render(['theme_test__suggestion', 'theme_test'], [])];
75   }
76
77   /**
78    * Tests themed output generated in a request listener.
79    *
80    * @return string
81    *   Content in theme_test_output GLOBAL.
82    */
83   public function testRequestListener() {
84     return ['#markup' => $GLOBALS['theme_test_output']];
85   }
86
87   /**
88    * Menu callback for testing suggestion alter hooks with template files.
89    */
90   public function suggestionProvided() {
91     return ['#theme' => 'theme_test_suggestion_provided'];
92   }
93
94   /**
95    * Menu callback for testing suggestion alter hooks with template files.
96    */
97   public function suggestionAlter() {
98     return ['#theme' => 'theme_test_suggestions'];
99   }
100
101   /**
102    * Menu callback for testing hook_theme_suggestions_alter().
103    */
104   public function generalSuggestionAlter() {
105     return ['#theme' => 'theme_test_general_suggestions'];
106   }
107
108   /**
109    * Menu callback for testing suggestion alter hooks with specific suggestions.
110    */
111   public function specificSuggestionAlter() {
112     return ['#theme' => 'theme_test_specific_suggestions__variant'];
113   }
114
115   /**
116    * Menu callback for testing suggestion alter hooks with theme functions.
117    */
118   public function functionSuggestionAlter() {
119     return ['#theme' => 'theme_test_function_suggestions'];
120   }
121
122   /**
123    * Menu callback for testing includes with suggestion alter hooks.
124    */
125   public function suggestionAlterInclude() {
126     return ['#theme' => 'theme_test_suggestions_include'];
127   }
128
129   /**
130    * Controller to ensure that no theme is initialized.
131    *
132    * @return \Symfony\Component\HttpFoundation\JsonResponse
133    *   The json response with the theme initialized information.
134    */
135   public function nonHtml() {
136     $theme_initialized = \Drupal::theme()->hasActiveTheme();
137     return new JsonResponse(['theme_initialized' => $theme_initialized]);
138   }
139
140   /**
141    * Controller for testing preprocess functions with theme suggestions.
142    */
143   public function preprocessSuggestions() {
144     return [
145       [
146         '#theme' => 'theme_test_preprocess_suggestions',
147         '#foo' => 'suggestion',
148       ],
149       [
150         '#theme' => 'theme_test_preprocess_suggestions',
151         '#foo' => 'kitten',
152       ],
153       [
154         '#theme' => 'theme_test_preprocess_suggestions',
155         '#foo' => 'monkey',
156       ],
157       ['#theme' => 'theme_test_preprocess_suggestions__kitten__flamingo'],
158     ];
159   }
160
161 }