class HtmlPageController

Default controller for most HTML pages.

Hierarchy

Expanded class hierarchy of HtmlPageController

1 string reference to 'HtmlPageController'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml
1 service uses HtmlPageController

File

drupal/core/lib/Drupal/Core/Controller/HtmlPageController.php, line 17
Contains \Drupal\Core\Controller\HtmlPageController.

Namespace

Drupal\Core\Controller
View source
class HtmlPageController {

  /**
   * The HttpKernel object to use for subrequests.
   *
   * @var \Symfony\Component\HttpKernel\HttpKernelInterface
   */
  protected $httpKernel;

  /**
   * Constructs a new HtmlPageController.
   *
   * @param \Symfony\Component\HttpKernel\HttpKernelInterface $kernel
   */
  public function __construct(HttpKernelInterface $kernel) {
    $this->httpKernel = $kernel;
  }

  /**
   * Controller method for generic HTML pages.
   *
   * @param Request $request
   *   The request object.
   * @param callable $_content
   *   The body content callable that contains the body region of this page.
   *
   * @return \Symfony\Component\HttpFoundation\Response
   *   A response object.
   */
  public function content(Request $request, $_content) {

    // @todo When we have a Generator, we can replace the forward() call with
    // a render() call, which would handle ESI and hInclude as well.  That will
    // require an _internal route.  For examples, see:
    // https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml
    // https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/InternalController.php
    $attributes = clone $request->attributes;
    $controller = $_content;

    // We need to clean off the derived information and such so that the
    // subrequest can be processed properly without leaking data through.
    $attributes
      ->remove('system_path');
    $attributes
      ->remove('_content');
    $response = $this->httpKernel
      ->forward($controller, $attributes
      ->all(), $request->query
      ->all());

    // For successful (HTTP status 200) responses, decorate with blocks.
    if ($response
      ->isOk()) {
      $page_content = $response
        ->getContent();
      $response = new Response(drupal_render_page($page_content));
    }
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HtmlPageController::$httpKernel protected property The HttpKernel object to use for subrequests.
HtmlPageController::content public function Controller method for generic HTML pages.
HtmlPageController::__construct public function Constructs a new HtmlPageController.