Hey!

I'm working on a project with both rules and context activated and just wanted to throw a thought that struck me. Wouldn't it be great to have different contexts as a condition in the rules module?
Say you want to display a message on a node if a certain context is active.
Even more, it would be possible to implement actions per context. Say fire some rules when a specific context is set to active. This would give a lot of creative options.

Will look into the implementation of this.

CommentFileSizeAuthor
#3 context_rules.tar_.gz1.12 KBfrankcarey

Comments

frankcarey’s picture

I'm kind of looking for the other way round... Use rules to set the page's context.

frankcarey’s picture

Ahhh, rules integration. I *heart* APIs! Here is my hacked together rules integration module. I'm going to keep working on this to at least clean it up, but i figure others might like to check it out.

I am able to use the "Create Context" Action in rules where i set "namespace" and "attribute", and then you can follow it up with the "Set Context" to set the "Value" to whatever you want. In my case, I'm setting a context value called "people" when users are viewing a profile page that isn't their own. I won't go through the conditions, but the context values for the actions are like this (which are the defaults):

namespace: context_ui
attribute: section
value:people

I think conditions should work as well, being able to retrieve what contexts are set, etc. Obviously this opens up much more control over how contexts are set, and rules can be imported and exported and have features integration, so this can be a really powerful shift! @maintainers: do you think it makes sense to have this be a new part of context module?

frankcarey’s picture

StatusFileSize
new1.12 KB

here is the module: NOTE this thing was hacked together over the last few hours and it's 1:41am. use at your own risk! However, feedback would be much appreciated.

amitaibu’s picture

I have created a new issue #655516: Maybe context should leverage Rules? - which is and isn't a duplicate ;)

In this issue we speak about Rules integration -- allowing rules to set the context object.

In that issue I claim that Rules itself *is* the context module -- where context only needs to provide custom conditions and actions, and no need to have a context object.

frankcarey’s picture

Without reading that issue :P I think that is right thinking... but really rules is a replacement for context_ui (or at least the part that sets contexts) not context module itself, which is basically a "state cache".

steven jones’s picture

Status: Active » Needs review
Issue tags: +context-2.x-rc-blocker

Would be nice to get this into 2.x

steven jones’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: -context-2.x-rc-blocker

The code needs some work.

I'm not sure the language used is the best, 'creating' a context here doesn't actually create a new context, just creates one for Rules' benefit etc.

This is probably best moved into a standalone bridge module, or the feature adding for 3.x.

sethcohn’s picture

+1

watsonerror’s picture

Cool

steven jones’s picture

Version: 6.x-2.0-beta7 » 6.x-3.x-dev

This should be against context 3.x, either as a new feature, or a bridge between rules and context.

Someone needs to pick this up if they are interested, otherwise this won't happen.

milos.kroulik’s picture

+1

baff’s picture

+1

thomjjames’s picture

Hi,

I'd be happy to take this on and release it, if no one objects?!

I would say the module should initially offer:
A. Event - "A context has been set" (possibly the reserve too).
B. Condition - To see if a selected context is set or unset (pretty sure this should be possible)
C. Action - The is probably the most useful part allowing rules to set or unset a context or contexts.

Let me know if there's anything else that needs considering.
Cheers
Tom

thomjjames’s picture

Went ahead and made a new project for this: http://drupal.org/project/context_rules

Please file any features etc in the issue queue.

Cheers
Tom