Skip to content

Commit 258e102

Browse files
mpdudeMalteWunschFabianSchmick
authored
Stop passing the request into shortcode-resolving controllers (#15)
Do not try to pass the current `Request` object to controller methods performing the shortcode resolution: * For ESI-based subrequests, this does not work. * For `inline` subrequests, it is not necessary since the appropriate `Request` instance can be obtained directly from the `RequestStack`. (webfactory Case 134296) Co-authored-by: Malte Wunsch <mw@webfactory.de> Co-authored-by: Fabian Schmick <fs@webfactory.de>
1 parent 51006a5 commit 258e102

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased 2.0]
99

10+
### Removed
11+
12+
- The current request will no longer be passed to controllers generating the shortcode substitution (see #15). For shortcodes being handled `inline`, use the `RequestStack` directly in the substituting controller method to obtain the parent request. For `esi`-based renderers, there is no current solution provided by this bundle (see #14). Check your shortcode controllers for access to the request attribute named `request` to find affected places.
13+
1014
### Changed
1115

12-
- Logging will now by default be directed to the `shortcode` channel,
13-
instead of the `app` channel used previously.
16+
- Logging will now by default be directed to the `shortcode` channel, instead of the `app` channel used previously.
1417
- Slightly reduced the logging level in `EmbeddedShortcodeHandler`.

src/Handler/EmbeddedShortcodeHandler.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Webfactory\ShortcodeBundle\Handler;
44

5-
use InvalidArgumentException;
65
use Psr\Log\LoggerInterface;
76
use Psr\Log\NullLogger;
87
use Symfony\Component\HttpFoundation\RequestStack;
@@ -67,20 +66,9 @@ public function __invoke(ShortcodeInterface $shortcode)
6766
]
6867
);
6968

70-
try {
71-
return $this->fragmentHandler->render(
72-
new ControllerReference(
73-
$this->controllerName,
74-
array_merge(['request' => $this->requestStack->getCurrentRequest()], $shortcode->getParameters())
75-
),
76-
$this->renderer
77-
);
78-
} catch (InvalidArgumentException $exception) {
79-
if ('esi' === $this->renderer) {
80-
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);
81-
}
82-
83-
throw $exception;
84-
}
69+
return $this->fragmentHandler->render(
70+
new ControllerReference($this->controllerName, $shortcode->getParameters()),
71+
$this->renderer
72+
);
8573
}
8674
}

0 commit comments

Comments
 (0)