-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a context provider #282
base: 8.x-1.x
Are you sure you want to change the base?
Conversation
$context_definition = new ContextDefinition('entity:node', NULL, FALSE); | ||
$value = NULL; | ||
if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) { | ||
if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything before $node instanceof NodeInterface
is core code, copy-paste from NodeRouteContext
, and so are the parts including and after $cacheability
. Reviewing those are pointless. Speaking of pointless, propably checking whether $node instanceof NodeInterface
is pointless but it's cheap enough...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you limit this to nodes? To me the idea of using a node as a group type is odd. I know it was common to do it like this in D7, but to me it makes more sense to use a custom Group
entity type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are a D7 port and this PR needs to reuse #252 anyways which unhardwires node
. I will probably do it during Drupalaton (are you coming?)
I believe there's a similar effort by @RoySegall on #252 . The idea is indeed to provide a Context provider that is being fed by OgContext plugins. |
Maybe worth joining efforts on that PR? |
My PR was a shallow one - just plugin that return the first group without all the special logic. I added a test that send the user to a group but it fails for some reason which I'm not aware of yet. If @chx want to join in and help with the tests - he is more than welcome. |
I do not quite know what that PR is about but it's not about this. I tried to understand but failed -- and when I searched for ContextProvider then I found none. Please help me understand, I do not quite understand the core context system but I read #252 and I haven't found any core interfaces implemented or tagged services so I don't get it. |
Sure, I'm not too familiar with #252, so I will explain the idea in generel, which is porting Og-Context module to OG8. Here's the logic:
Here's the relevant code from OG7:
@chx , Hope it clarifies a bit the intention :) |
So #252 is WIP and not yet integrating with core but eventually it wants to...? |
Indeed it's WIP. But as @RoySegall stated, he's open to collaboration, so if you'd like to tackle this task differently in terms of steps to reach the goal, that's of course possible to discuss. |
I still do not know whether we have the same goals :) I am providing a context for core, mostly for blocks. It uses a different logic to what you described:
That's it. But, it's a core context provider. I simply do not see what is the end goal of yours, I am guessing it might also want to be a ContextProvider but I do not know. |
I think we're close, however your use case is just hardcoded to getting groups out of nodes (although agreed it will be a common case). So my goal is that instead of hardcoding the specific check for nodes in the core's ContextProvider, we delegate the job of getting that groups to OgContext plugins. So you could have one plugin that gets the context from a node, and another arbitrary one that will do it by the time of the day. Those plugins pass their groups to the ContextProvider that will indeed select the "best matching" one, and return it. In short: The current logic you put in place seems like a great start, and the next step is baking the OgContext plugins in. |
So you want to add a ContextProvider to #252 to actually use the logic created there. And then I guess add the logic from here to there as well? |
And to clarify further: I have no idea what hook_og_context_negotiation_info is, what module it integrated with and ... anything at all. I do not see the connection points to the rest of Drupal in the D7 version either. |
#252 need to handle a smaller scope - return the first group that the context handler will find. After the merge then we can move to higher scope. This is the case of the PR as I can see it. |
So let's clarify: there's no such thing as a "context handler". You are making a horribly confusing mess by calling it "OgContext" when core has a context subsystem. |
I haven't gone over #252 properly yet, so I just know there's the effort but can't say much about the code there. If you are ok and have time to work on the above goals, we can take your PR as a starting point as-well. I'm sure @RoySegall won't be insulted :)
No problem, I just wanted to link to the OG7 code that does the same. The gist of it is, that we are porting the same concepts, only with D8 code. |
Yes, we can of course change it. It's mostly since it was called in D7 og-context module. |
OK, so let's get back here. #252 has nothing to do with this PR then :) except perhaps I could reuse the "entity" OgContext plugin. |
I guess that's debatable 😉 I think they are both related to the end goals -Having a pluggable context provider. They just tackle it from different ends. I wouldn't mind tackling this task in small PRs as long as the end goal is clear (unless of course you think there are better ways). In terms of names, to prevent confusion with the core context how about:
|
The names sound good. There are some challenges left if you want to indeed create |
Thanks for pointing out the ones I thought off sucked 😄
What difficulties do you foresee? |
I just discussed some of this with @timplunkett and in particular
} this makes me wonder as core does not have a term from URL, a user from URL etc context but og will have to have one as groups are any entity type so while of course it's very doable we are sort of on uncharted territory. |
My favorite place 😉 |
The ones that exist in core were the result of straight ports of parts of the block visibility system. User/Term from URL could easily be added to core in 8.3 or any minor. |
Thanks for shoving up! What about an EntityContextProvider which does the same as NodeContextProvider but for every entity? And yes, it's relevant to this discussion because that's essentially what we would be doing sprinkled with some og logic |
Yes, that's exactly what OG will need. It would be wonderful if it could extended a core |
In our project we are using the I think that version would be a good starting point. It needs some tweaks though, it cannot deal with routes that have multiple group parameters. https://github.com/ec-europa/og_menu/blob/8.x-1.x/src/ContextProvider/OgRouteContext.php |
Ping @sandervd who wrote the ContextProvider in OG Menu. |
That code is alright but compare to #252 and see the discussion above and the code in here. We do not just want a group entity to appear as the context value but the group the per route entity belongs to. |
In the end the |
Did you do the rename already to |
Only in my brain, not in code yet :) |
I really like plugin based approach of @RoySegall. If I'm not mistaking, the next step would be to wrap all of this inside a ContextProvider, right? However, when we do so, will there be only one Og context generated, or should it be possible to create multiple 'contexts' (with individual settings)? |
Yes. I'll add some overview to #252, so it's easier to pickup the work there.
The @chx I'll close this one, and lets move collaboration and discussion to #252 |
I'd like to circle back to this one. OG8 is taking the approach oh simplifying stuff from OG7, and after some thought I think that we can un-port OG-Context module and just have a non-node specific context provider in. The reason is that the context from the route is the most common one, and if a dev would like to extend it, they could have their own context provider. @RoySegall @pfrenssen will that work for your use cases? |
I'm not familiar with what OGContext was doing in D7, but what I understood from previous discussions is that it was able to figure out the group context of things like group content that belongs to multiple groups, depending on the user session. For me it makes sense to have a plugin based system, I see this similar to how for example language negotiation works. My context could depend on:
For complex sites a developer will need custom rules, but this would be another plugin that can complement the ones that are already there. |
My PR provided the infrastructure for that. I'll get back to this one this week. |
Our site is pretty much split into subsites by group. Displaying the relevant blocks on a group node or a node belonging to a group is possible with this context provider. If it's not generic enough just won't fix this and I will dump it into a separate sandbox module. Here's how placing a block with
* "node" = @ContextDefinition("entity:node", label = @Translation("Node"), required = FALSE),
looks: