ThemeTestController.php 3.31 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 12 13 14

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

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

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

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

  /**
   * Calls a theme hook suggestion.
   *
   * @return string
   *   An HTML string containing the themed output.
   */
  public function testSuggestion() {
68
    return _theme(array('theme_test__suggestion', 'theme_test'), array());
69 70 71 72
  }

/**
 * This is for testing that the theme can have hook_*_alter() implementations
73
 * that run during page callback execution, even before _theme() is called for
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
 * the first time.
 *
 * @return string
 *   A string containing the altered data.
 */
  public function testAlter() {
    $data = 'foo';
    $this->moduleHandler()->alter('theme_test_alter', $data);
    return "The altered data is $data.";
  }

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

95 96 97 98 99 100 101 102 103 104 105 106 107 108
  /**
   * 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');
  }

109 110 111 112 113 114 115
  /**
   * Menu callback for testing hook_theme_suggestions_alter().
   */
  function generalSuggestionAlter() {
    return array('#theme' => 'theme_test_general_suggestions');
  }

116 117 118 119 120 121 122 123 124 125 126 127 128 129
  /**
   * 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');
  }

130 131 132 133 134 135 136 137

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

138
}