Problem/Motivation
Some global page-response properties should be changed for some responses. This is currently possible by implement the provided alter hook or an event subscriber, but the decision to do so often is happening during the custom-elements render process. E.g., a layout builder layout plugins wants to change the global page layout when rendered.
Some use-cases:
- switching to a custom layout, changing property "page": "layout--default",
- changing settings
- customizing metatags
Proposed resolution
Support customizing the page response by writing it into request attributes. By using request attributes the response customization happens cleanly per request and no global state is introduced.
For example, we name the attributes key "lupus_ce_renderer_response_data". After generating the default response, the provided response data attributes should overwrite the default response by following a deep-merge and replace-keys (array-replace?) strategy.
hook_lupus_ce_renderer_response_alter() should come last.
Finally, this should be documented at hook_lupus_ce_renderer_response_alter().
API changes
Only additions, no BC break.
Issue fork lupus_ce_renderer-3229064
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
fagoComment #4
useernamee commentedI've added this code and a README entry.
Comment #6
useernamee commentedComment #7
fagothere is some missing use statement somewhere still
Exception: TypeError: Argument 2 passed to Drupal\lupus_ce_renderer\CustomElementsRenderer::modifyResponseData() must be an instance of Drupal\lupus_ce_renderer\Request, instance of Symfony\Component\HttpFoundation\Request given, called in /var/www/html/modules/contrib/lupus_ce_renderer/src/CustomElementsRenderer.php on line 210Comment #8
fagoelse this looks good!
Comment #9
fagocode looks good now, let's do some more testing before merge.
Comment #10
fagoThis passed testing, so is ready to go!
Comment #13
mostepaniukvmChanged target branch to 2.x in PR , run test on D9.2 and merged