Score:0

Manually create an HtmlResponse for an entity view

cn flag

How do I manually create an HtmlResponse object that returns the full html for an entity view; identical to the html returned for the entity.{{whatever entity id}}.canonical route?

Context: I'm subscribing "kernel.request" to check for certain URL's that are supposed to bypass Drupal Path processing altogether. For some of these I'm returning a TrustedRedirectResponse, but others should show (not redirect to) an entity view.

4uk4 avatar
cn flag
You could create the HtmlResponse object in a sub-request similar to Drupal creating the response of an error page set to a node. But it's unclear why you can't make an entity route match the path and let the current request build the response. The error page is built in a sub-request because the current request has failed. You don't have this problem.
Menno van den Heuvel avatar
cn flag
@4uk4 : I've chosen to go this route (ha!) because I need to allow for any arbitrary URL to be entered by the user, and my site uses language prefixes that I need to be able to ignore. I'm not sure how else I could accomplish this. The redirect modules uses the same approach (but only redirects, obviously) A sub request seems heavyhanded, but should work.
4uk4 avatar
cn flag
You could ignore the language prefix and translate the arbitrary URL to the internal entity path in a path processor with a high priority.
Menno van den Heuvel avatar
cn flag
@4uk4 : true, I could do that, and it might work. I'll give that a shot.
Menno van den Heuvel avatar
cn flag
@4uk4: and it does work. Thanks!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.