public function InlineFragmentRenderer::render

Additional available options:

  • alt: an alternative URI to render in case of an error

Overrides FragmentRendererInterface::render

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php, line 50

Class

InlineFragmentRenderer
Implements the inline rendering strategy where the Request is rendered by the current HTTP kernel.

Namespace

Symfony\Component\HttpKernel\Fragment

Code

public function render($uri, Request $request, array $options = array()) {
  $reference = null;
  if ($uri instanceof ControllerReference) {
    $reference = $uri;
    $uri = $this
      ->generateFragmentUri($uri, $request);
  }
  $subRequest = $this
    ->createSubRequest($uri, $request);

  // override Request attributes as they can be objects (which are not supported by the generated URI)
  if (null !== $reference) {
    $subRequest->attributes
      ->add($reference->attributes);
  }
  $level = ob_get_level();
  try {
    return $this->kernel
      ->handle($subRequest, HttpKernelInterface::SUB_REQUEST, false);
  } catch (\Exception $e) {

    // we dispatch the exception event to trigger the logging
    // the response that comes back is simply ignored
    if (isset($options['ignore_errors']) && $options['ignore_errors'] && $this->dispatcher) {
      $event = new GetResponseForExceptionEvent($this->kernel, $request, HttpKernelInterface::SUB_REQUEST, $e);
      $this->dispatcher
        ->dispatch(KernelEvents::EXCEPTION, $event);
    }

    // let's clean up the output buffers that were created by the sub-request
    while (ob_get_level() > $level) {
      ob_get_clean();
    }
    if (isset($options['alt'])) {
      $alt = $options['alt'];
      unset($options['alt']);
      return $this
        ->render($alt, $request, $options);
    }
    if (!isset($options['ignore_errors']) || !$options['ignore_errors']) {
      throw $e;
    }
    return new Response();
  }
}