8000 Passing the request in ESI-based shortcode handlers? · Issue #14 · webfactory/WebfactoryShortcodeBundle · GitHub
[go: up one dir, main page]

Skip to content
Passing the request in ESI-based shortcode handlers? #14
Closed
@mpdude

Description

@mpdude

We're passing the current Request object along to controllers generating the shortcode substitution content:

try {
return $this->fragmentHandler->render(
new ControllerReference(
$this->controllerName,
array_merge(['request' => $this->requestStack->getCurrentRequest()], $shortcode->getParameters())
),
$this->renderer
);
} catch (InvalidArgumentException $exception) {
if ('esi' === $this->renderer) {
throw new InvalidArgumentException('An InvalidArgumentException occured while trying to render the shortcode '.$shortcode->getShortcodeText().'. You\'ve probably tried to use the ESI rendering strategy for '.'your shortcodes while handling a request that contained non-scalar values as part of URI '.'attributes. This can happen e.g. when using Param Converters for your original controller '.'action, as the request (containing the conversion result) is automatically passed to the call of '.'the shortcode controller to allow context sensitive shortcodes. You could use '.'Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.inline as parent in your '.'shortcode\'s service defintion, so that the inline instead of ESI rendering strategy will be '.'used.', 0, $exception);
}
throw $exception;
}

  1. This is not equivalent to what Symfony does when type-hinting for the Request class as a controller method argument, since Symfony injects the Request based on the type-hint. The code shown above works based on the parameter name.
  2. Passing arguments to ESI subrequests works only for scalar values. If the Request contains non-scalar values, most probably due to Param Converters being used, this might fail or at least not provide the expected results.

I think we should remove this general request-passing behaviour. To support "context-aware shortcodes" (where the rendering controller knows about the request where the shortcode is used), we could either recommend using the inline rendering strategy only. (TODO: Check if the Request can be injected automatically into such controllers.)

Or we need to come up with a way where you can express via configuration (extra DIC tags?) which parameter values to pass on for which shortcode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0