public function HIncludeFragmentRenderer::render

Additional available options:

  • default: The default content (it can be a template name or the content)
  • id: An optional hx:include tag id attribute
  • attributes: An optional array of hx:include tag attributes

Overrides FragmentRendererInterface::render

File

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

Class

HIncludeFragmentRenderer
Implements the Hinclude rendering strategy.

Namespace

Symfony\Component\HttpKernel\Fragment

Code

public function render($uri, Request $request, array $options = array()) {
  if ($uri instanceof ControllerReference) {
    if (null === $this->signer) {
      throw new \LogicException('You must use a proper URI when using the Hinclude rendering strategy or set a URL signer.');
    }
    $uri = $this->signer
      ->sign($this
      ->generateFragmentUri($uri, $request));
  }

  // We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.
  $uri = str_replace('&', '&', $uri);
  $template = isset($options['default']) ? $options['default'] : $this->globalDefaultTemplate;
  if (null !== $this->templating && $template && $this
    ->templateExists($template)) {
    $content = $this->templating
      ->render($template);
  }
  else {
    $content = $template;
  }
  $attributes = isset($options['attributes']) && is_array($options['attributes']) ? $options['attributes'] : array();
  if (isset($options['id']) && $options['id']) {
    $attributes['id'] = $options['id'];
  }
  $renderedAttributes = '';
  if (count($attributes) > 0) {
    foreach ($attributes as $attribute => $value) {
      $renderedAttributes .= sprintf(' %s="%s"', htmlspecialchars($attribute, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset, false), htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset, false));
    }
  }
  return new Response(sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
}