Score:1

Is it possible to add an entity to the current route parameters?

de flag

Using \Drupal::routeMatch()->getParameter(), it's possible to fetch objects that come from the parameters of the URL.

I'm wondering if it is possible to add values to the routeMatch. For example, if using the Groups module, nodes may be part of a group, however the group is not part of the path. Is there a way to load the group from the node, and add the group to the parameters that can be retrieved with \Drupal::routeMatch()->getParameter()?

Or, more broadly, I'd like to set the $group to be part of the "context" of a page request on a node page.

4uk4 avatar
cn flag
No, this is not necessary. The node instance is referenced in the route match and you can get the group info anytime you want with no performance hit. Whether you need a group cache context depends, because on a node page the main page content already depends on the more specific node and a more general cache context wouldn't make a difference. Unless you have page elements like blocks which only depend on the group.
Jaypan avatar
de flag
It's the latter - I have blocks with are dependent upon the group.
Score:2
cn flag

To use it in a block you could create a custom route.node_group context which gets the context from the route match. Hierarchically you have to place it under the route context. When merging contexts, for example if the context bubbles up to the page level, route can replace route.node_group.

Jaypan avatar
de flag
Thanks 4x4. I upvoted it.
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.