You are here

class TwigThemeTestController in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php \Drupal\twig_theme_test\TwigThemeTestController

Controller routines for Twig theme test routes.

Hierarchy

Expanded class hierarchy of TwigThemeTestController

File

core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php, line 16
Contains \Drupal\twig_theme_test\TwigThemeTestController.

Namespace

Drupal\twig_theme_test
View source
class TwigThemeTestController {

  /**
   * Menu callback for testing PHP variables in a Twig template.
   */
  public function phpVariablesRender() {
    return [
      '#markup' => \Drupal::theme()
        ->render('twig_theme_test_php_variables', array()),
    ];
  }

  /**
   * Menu callback for testing translation blocks in a Twig template.
   */
  public function transBlockRender() {
    return array(
      '#theme' => 'twig_theme_test_trans',
    );
  }

  /**
   * Controller for testing the twig placeholder filter outside of {% trans %}
   */
  public function placeholderOutsideTransRender() {
    return [
      '#theme' => 'twig_theme_test_placeholder_outside_trans',
      '#var' => '<script>alert(123);</script>',
    ];
  }

  /**
   * Renders for testing url_generator functions in a Twig template.
   */
  public function urlGeneratorRender() {
    return array(
      '#theme' => 'twig_theme_test_url_generator',
    );
  }

  /**
   * Renders for testing link_generator functions in a Twig template.
   */
  public function linkGeneratorRender() {
    return [
      '#theme' => 'twig_theme_test_link_generator',
      '#test_url' => new Url('user.register', [], [
        'absolute' => TRUE,
      ]),
      '#test_url_attribute' => new Url('user.register', [], [
        'attributes' => [
          'foo' => 'bar',
        ],
      ]),
      // Explicitly creating an Attribute object to avoid false positives when
      // testing Attribute object merging with the twig link() function.
      '#attributes' => new Attribute([
        'class' => [
          'llama',
          'kitten',
          'panda',
        ],
      ]),
    ];
  }

  /**
   * Renders a URL to a string.
   */
  public function urlToStringRender() {
    return [
      '#theme' => 'twig_theme_test_url_to_string',
      '#test_url' => Url::fromRoute('user.register'),
    ];
  }

  /**
   * Renders for testing file_url functions in a Twig template.
   */
  public function fileUrlRender() {
    return array(
      '#theme' => 'twig_theme_test_file_url',
    );
  }

  /**
   * Renders for testing attach_library functions in a Twig template.
   */
  public function attachLibraryRender() {
    return array(
      '#theme' => 'twig_theme_test_attach_library',
    );
  }

  /**
   * Menu callback for testing the Twig registry loader.
   */
  public function registryLoaderRender() {
    return array(
      '#theme' => 'twig_registry_loader_test',
    );
  }

  /**
   * Controller for testing a renderable inside a template.
   */
  public function renderable() {
    return [
      '#theme' => 'twig_theme_test_renderable',
      '#renderable' => new ExampleRenderable(),
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TwigThemeTestController::attachLibraryRender public function Renders for testing attach_library functions in a Twig template.
TwigThemeTestController::fileUrlRender public function Renders for testing file_url functions in a Twig template.
TwigThemeTestController::linkGeneratorRender public function Renders for testing link_generator functions in a Twig template.
TwigThemeTestController::phpVariablesRender public function Menu callback for testing PHP variables in a Twig template.
TwigThemeTestController::placeholderOutsideTransRender public function Controller for testing the twig placeholder filter outside of {% trans %}
TwigThemeTestController::registryLoaderRender public function Menu callback for testing the Twig registry loader.
TwigThemeTestController::renderable public function Controller for testing a renderable inside a template.
TwigThemeTestController::transBlockRender public function Menu callback for testing translation blocks in a Twig template.
TwigThemeTestController::urlGeneratorRender public function Renders for testing url_generator functions in a Twig template.
TwigThemeTestController::urlToStringRender public function Renders a URL to a string.