ThemeTestController.php 3.33 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Contains \Drupal\theme_test\ThemeTestController.
 */

namespace Drupal\theme_test;

10
use Drupal\Core\Controller\ControllerBase;
11
use Symfony\Component\HttpFoundation\JsonResponse;
12 13 14 15

/**
 * Controller routines for theme test routes.
 */
16
class ThemeTestController extends ControllerBase {
17 18

  /**
19 20 21 22
   * A theme template that overrides a theme function.
   *
   * @return array
   *   Render array containing a theme.
23
   */
24 25 26 27
  public function functionTemplateOverridden() {
    return array(
      '#theme' => 'theme_test_function_template_override',
    );
28 29 30
  }

  /**
31 32 33 34
   * Adds stylesheets to test theme .info.yml property processing.
   *
   * @return array
   *   A render array containing custom stylesheets.
35
   */
36 37
  public function testInfoStylesheets() {
    $path = drupal_get_path('module', 'theme_test');
38
    return array(
39 40 41 42 43 44 45 46 47 48
      '#attached' => array(
        'css' => array(
          "$path/css/base-override.css",
          "$path/css/base-override.sub-remove.css",
          "$path/css/base-remove.css",
          "$path/css/base-remove.sub-override.css",
          "$path/css/sub-override.css",
          "$path/css/sub-remove.css",
        ),
      ),
49 50 51
    );
  }

52 53 54 55 56 57 58
  /**
   * Tests template overridding based on filename.
   *
   * @return array
   *   A render array containing a theme override.
   */
  public function testTemplate() {
59
    return _theme('theme_test_template_test');
60 61 62 63 64 65 66 67 68
  }

  /**
   * Calls a theme hook suggestion.
   *
   * @return string
   *   An HTML string containing the themed output.
   */
  public function testSuggestion() {
69
    return _theme(array('theme_test__suggestion', 'theme_test'), array());
70 71 72 73 74 75 76 77 78 79 80 81
  }

  /**
   * Tests themed output generated in a request listener.
   *
   * @return string
   *   Content in theme_test_output GLOBAL.
   */
  public function testRequestListener() {
    return $GLOBALS['theme_test_output'];
  }

82 83 84 85 86 87 88 89 90 91 92 93 94 95
  /**
   * Menu callback for testing suggestion alter hooks with template files.
   */
  function suggestionProvided() {
    return array('#theme' => 'theme_test_suggestion_provided');
  }

  /**
   * Menu callback for testing suggestion alter hooks with template files.
   */
  function suggestionAlter() {
    return array('#theme' => 'theme_test_suggestions');
  }

96 97 98 99 100 101 102
  /**
   * Menu callback for testing hook_theme_suggestions_alter().
   */
  function generalSuggestionAlter() {
    return array('#theme' => 'theme_test_general_suggestions');
  }

103 104 105 106 107 108 109 110 111 112 113 114 115 116
  /**
   * Menu callback for testing suggestion alter hooks with specific suggestions.
   */
  function specificSuggestionAlter() {
    return array('#theme' => 'theme_test_specific_suggestions__variant');
  }

  /**
   * Menu callback for testing suggestion alter hooks with theme functions.
   */
  function functionSuggestionAlter() {
    return array('#theme' => 'theme_test_function_suggestions');
  }

117 118 119 120 121 122 123 124

  /**
   * Menu callback for testing includes with suggestion alter hooks.
   */
  function suggestionAlterInclude() {
    return array('#theme' => 'theme_test_suggestions_include');
  }

125 126 127 128 129 130 131 132 133 134 135
  /**
   * Controller to ensure that no theme is initialized.
   *
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   *   The json response with the theme initialized information.
   */
  public function nonHtml() {
    $theme_initialized = \Drupal::theme()->hasActiveTheme();
    return new JsonResponse(['theme_initialized' => $theme_initialized]);
  }

136
}