I am getting the following when trying to redirect to an external site from my controller function defined in my routing file:
return new TrustedRedirectResponse($my_ext_url);
LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\Core\Routing\TrustedRedirectResponse. in Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (line 159 of core\lib\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber.php).
This is clearly related to cache metadata - but how do i switch this off for a trusted redirect?
Edit: There is currently no constructor on the controller and therefore no injection going on. Routing looks like (obv with correct indents :):
tocyn_payment.paypal_checkout:
path: 'test/{order_id}'
defaults:
_controller: 'Drupal\my_module\Controller\MyController::handle'
_title: 'Test Tite'
requirements:
_permission: 'access content'
Thanks in advance
Mathew