Closed RoySegall closed 8 years ago
@amitaibu Before I'll start implementing the changes don't you want me to moe og context plugin into OG core?
I moved OG context into core. Now I can say I started the work on OG context.
Another update - Now we have the next two cool, IMO, API:
$plugins = Og::contextHandler()->getPlugins();
$plugin = Og::contextHandler()->getPlugin('entity');
I have updated the issue summary.
@RoySegall can you please rename the classes/ plugins to be the same as in the issue summary.
I changed the plugin to Group resolver
from `OG context'
OK. I got the rename of the classes. Now I need to extend the OgContext form ContextProviderInterface
What's the status here?
I started to work on extending from ContextProviderInterface
and I got interrupted. I'll try to get back to it tonight.
@amitaibu I extended OgContextInterface
from ContextProviderInterface
and I there are two methods I need to implements but I still can't see how they suppose to fit in.
If some one can throw some tips that would be awesome.
I dig a bit in the code and it seems that we need to create a service, in addition to the context group resolver, that will look like this:
og.og_route_context:
class: Drupal\og\ContextProvider\GroupRouteContext
arguments: ['@current_route_match']
tags:
- { name: 'context_provider' }
and that service will use the logic I created so far. After that we can have in any plugins something like this:
/**
* Provides a 'User Role' condition.
*
* @OgTask(
* id = "people",
* label = @Translation("People"),
* context = {
* "group" = @ContextDefinition("group", label = @Translation("Current group"))
* }
* )
*/
But IMO this will be another PR. In the mean while I'll keep working in the tests.
I added a skeleton for the test and this time I did not got any weird errors from PHPUNIT.
Great. Can you please re-roll, and re-open this PR against Gizra/og
One the tests will work as expected I'll create new PR against gizra/OG. In the meanwhile don't close the PR.
10x.
@RoySegall would you be OK if I continue on this? I have time to work on it this week.
I would like to start with adopting the naming scheme that @amitaibu suggested in https://github.com/amitaibu/og/pull/282#issuecomment-236657256:
- Context provider :
class OgContext implements ContextProviderInterface {
- Plugin manager:
class GroupResolverManager extends DefaultPluginManager {
- Single Plugin:
class GroupResolver extends GroupResolverInterface {
And then secondly get the tests green.
I had a look through the code but it seems to me that the chosen approach is more complex than needed. Maybe I am not seeing the use cases that require this complex approach, but the way I imagined this to work was like this:
OgContext::getRuntimeContexts()
.OgContext::getRuntimeContexts()
loads the og.group_resolvers
config to get the list of enabled group resolvers in the right order.OgContext::getRuntimeContexts()
requests the enabled group resolver plugins from GroupResolverManager::getInstance()
.OgContext::getRuntimeContexts()
calls each plugin in the right order, and if it finds one that returns a single result, it loads this group and returns it as context.In my mind the whole procedure would be like 50 lines of code + a couple hundred lines for the default config, the individual plugins and tests.
This approach with the separate handler and saving plugin configuration in a dedicated GroupResolverNegotiation
entity, and RETURN_ONLY_IN_STORAGE
seems to be quite complicated for what we are trying to achieve.
I always enjoy seeing your code review!
I think your analysis is very good, with a single remark:
OgContext::getRuntimeContexts() calls each plugin in the right order, and if it finds one that returns a single result, it loads this group and returns it as context.
OgContextProvider::getRuntimeContexts() will call the OgGroupResolver
plugins, and let them return all their values. That is, it will not break on the first group that is found.
Then, it will apply some simple (hardcoded) rule to get the "Best matching" group, by order:
A
, and now you visit a group content that belongs to groups A
and B
-- so we should be nice and keep you in the A
context.Thanks for the feedback! With your permission I will continue this work and try to bring it to conclusion. I'll make a new PR with the simplified approach.
👍
@pfrenssen Any new on this one? I kind of lost context on this one in the past few weeks.
Goal
Port og-context module to OG8.
GroupResolver
are plugins that can extract group for the pages or entities they are acting on. One can get the groups from the router, and another arbitrary one that will do it by the time of the day.Those plugins pass their groups to the
OgContextProvider
that will select the "best matching" one, and return it. The best matching logic is currently (by order):Naming
Context provider : class OgContext implements ContextProviderInterface {
Plugin manager: class GroupResolverManager extends DefaultPluginManager {
Single Plugin: class GroupResolver extends GroupResolverInterface {
The GroupResolver plugins will return multiple groups, but eventually OgContextProvider will select only a single one. The logic is that when your theme/language/whatever needs to change according to context it should act only on a single context.