You are here

class RenderAttachedTestController in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/render_attached_test/src/Controller/RenderAttachedTestController.php \Drupal\render_attached_test\Controller\RenderAttachedTestController
  2. 10 core/modules/system/tests/modules/render_attached_test/src/Controller/RenderAttachedTestController.php \Drupal\render_attached_test\Controller\RenderAttachedTestController

Controller for various permutations of #attached in the render array.

Hierarchy

Expanded class hierarchy of RenderAttachedTestController

1 file declares its use of RenderAttachedTestController
AttachedRenderingBlock.php in core/modules/system/tests/modules/render_attached_test/src/Plugin/Block/AttachedRenderingBlock.php

File

core/modules/system/tests/modules/render_attached_test/src/Controller/RenderAttachedTestController.php, line 8

Namespace

Drupal\render_attached_test\Controller
View source
class RenderAttachedTestController {

  /**
   * Test special header and status code rendering.
   *
   * @return array
   *   A render array using features of the 'http_header' directive.
   */
  public function teapotHeaderStatus() {
    $render = [];
    $render['#attached']['http_header'][] = [
      'Status',
      418,
    ];
    return $render;
  }

  /**
   * Test attached HTML head rendering.
   *
   * @return array
   *   A render array using the 'http_head' directive.
   */
  public function header() {
    $render = [];
    $render['#attached']['http_header'][] = [
      'X-Test-Teapot-Replace',
      'This value gets replaced',
    ];
    $render['#attached']['http_header'][] = [
      'X-Test-Teapot-Replace',
      'Teapot replaced',
      TRUE,
    ];
    $render['#attached']['http_header'][] = [
      'X-Test-Teapot-No-Replace',
      'This value is not replaced',
    ];
    $render['#attached']['http_header'][] = [
      'X-Test-Teapot-No-Replace',
      'This one is added',
      FALSE,
    ];
    $render['#attached']['http_header'][] = [
      'X-Test-Teapot',
      'Teapot Mode Active',
    ];
    return $render;
  }

  /**
   * Test attached HTML head rendering.
   *
   * @return array
   *   A render array using the 'html_head' directive.
   */
  public function head() {
    $head = [
      [
        '#tag' => 'meta',
        '#attributes' => [
          'test-attribute' => 'testvalue',
        ],
      ],
      'test_head_attribute',
    ];
    $render = [];
    $render['#attached']['html_head'][] = $head;
    return $render;
  }

  /**
   * Test attached feed rendering.
   *
   * @return array
   *   A render array using the 'feed' directive.
   */
  public function feed() {
    $render = [];
    $render['#attached']['feed'][] = [
      'test://url',
      'Your RSS feed.',
    ];
    return $render;
  }

  /**
   * Test HTTP header rendering for link.
   *
   * @return array
   *   A render array using the 'html_head_link' directive.
   */
  public function htmlHeaderLink() {
    $render = [];
    $render['#attached']['html_head_link'][] = [
      [
        'href' => '/foo?bar=<baz>&baz=false',
        'rel' => 'alternate',
      ],
      TRUE,
    ];
    $render['#attached']['html_head_link'][] = [
      [
        'href' => '/not-added-to-http-headers',
        'rel' => 'alternate',
      ],
      FALSE,
    ];
    $render['#attached']['html_head_link'][] = [
      [
        'href' => '/foo/bar',
        'hreflang' => 'nl',
        'rel' => 'alternate',
      ],
      TRUE,
    ];
    return $render;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RenderAttachedTestController::feed public function Test attached feed rendering.
RenderAttachedTestController::head public function Test attached HTML head rendering.
RenderAttachedTestController::header public function Test attached HTML head rendering.
RenderAttachedTestController::htmlHeaderLink public function Test HTTP header rendering for link.
RenderAttachedTestController::teapotHeaderStatus public function Test special header and status code rendering.