Comments

bohz’s picture

Thanks a lot.
I have tested the patch and works very well, beside being extremely useful.
I would love to see this feature added to context in future releases.
Cheers

steven jones’s picture

Issue tags: +context-2.x-rc-blocker

Interesting, would be good to get this in to 2.x.

steven jones’s picture

Status: Needs review » Fixed

Committed to 2.x

yhahn’s picture

Version: 6.x-2.0-beta7 » 6.x-3.0-beta4
Assigned: Unassigned » steven jones
Status: Fixed » Active

Forward port would be great, at your leisure.

ManyNancy’s picture

Thank you all, subscribe.

yhahn’s picture

Version: 6.x-3.0-beta4 » 6.x-3.x-dev
Assigned: steven jones » yhahn
Priority: Normal » Critical
tim.plunkett’s picture

Sub. I need this desperately, I guess I should work on a patch.

tim.plunkett’s picture

Status: Active » Needs work
StatusFileSize
new3.33 KB

Well I got something working, but it now needs a reroll since you just moved context_context_registry. Here's my diff from svn.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new3.94 KB

Alright, this is rerolled against CVS.

tim.plunkett’s picture

I'm realizing now that its rather greedy to name a condition "Content" and then only offer functionality for fields with allowed values.
That said, I think that this is a welcome addition to the Context module.

yhahn’s picture

Agreed, I'm on board for adding this. Would you mind adding a simpletest for this to the patch? You use one of the other condition tests as an example/starting point in Context 3.x.

tim.plunkett’s picture

I've never written a simpletest before (shame on me!), so I'm not sure the thoroughness required. I was considering just testing a select list of text with allowed values set. Or should it include variants, such as radio buttons of numbers?

Anonymous’s picture

@tim.plunkett I'm not a SimpleTest wizard either, and sometimes it comes really easily for one problem and I need help with others. In this case, I would imitate another test in Context, such as the user role condition test.

yhahn’s picture

@tim.plunkett: the basic select list with allowed values sounds fine. A test for just basic functionality will ensure that the condition is working in its most basic form.

tim.plunkett’s picture

Status: Needs review » Needs work

Ugh. It looks like I borrowed a little too much from the taxonomy condition. This plugin only works if the allowed value keys are unique, which is not a safe assumption. This things needs a total overhaul. Any advice?

jyg’s picture

I see this in the code for 2.x, but I do not see how to use it in the UI. I was under the impression that I'd add a CCK field to a content type which would allow me to choose a Context for a given node. Am I missing something here?

cyberderf’s picture

Interested... Can you explain what it does in details ?

webflo’s picture

StatusFileSize
new3.64 KB

Hi, i have rerolled the patch and solved the issue with
unique values (tim.plunkett - #15). This patch works like the views condition. Patch is against 6.x-3.x. I dont like the interface. I think groups of checkboxes is much better. But i think its not possible to save nested arrays in contexts conditions.

tim.plunkett’s picture

Assigned: yhahn » Unassigned
Status: Needs work » Needs review

Awesome, I'll check it out.

webflo’s picture

Hi, i have rolled a new patch. The only difference to #18 is the user inteface. Now the form is build with multiple groups of checkboxes instead of one group with nested checkboxes. screenshot and patch is attached.

Anonymous’s picture

StatusFileSize
new4.87 KB

I've rewritten the patch in #21 to register different conditions for each field. This allows a seamless upgrade path from Context 2 for these conditions. It also simplifies the UI. The new plugin descends from context_condition_node, so it can also apply to node forms.

jumpfightgo’s picture

I agree with @bangpound that it makes a lot more sense for each field to be a different condition, especially if your content types have many CCK fields.

markabur’s picture

Nice. The site I'm working on had used this functionality in 2.x and the patch in #21 works for 3.x. Minimally tested but looks good as far as that goes.

dman’s picture

Status: Needs review » Reviewed & tested by the community

Nice - just what I was looking for!
Works good for me. Clean code.

dman’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.97 KB

I found a small problem with this.

Partially built nodes may return NULL as a value for some CCK fields.
Clearly we'd expect a check against that to return FALSE, but due to the logic inside context_condition->get_contexts(NULL) it is returning TRUE.
(because called with 'no argument', it returns all contexts)

This situation can occur if you have existing content, then add a field, then try to check against that field.
Old nodes will have that value set to NULL when loaded. Passing NULL forward through the check gives us a false positive.
One solution is to open each old node and re-save it again (which will populate the field with an empty string or whatever) but that's impractical. CCK can deal with an incomplete set of values, therefore we need to also.

So, if we are looking at NULL in a content field, then stop trying to check against it.
Here's an update to #21 that resolves this for me.

jyg’s picture

For #25 I was getting this error:

warning: Invalid argument supplied for foreach() in /home/hf/dev/trunk/acquia-drupal-1.2.30/sites/all/modules/context/plugins/context_condition_content.inc on line 19.

when I did this, it stopped complaining and I do not think I've harmed anything:

--- plugins/context_condition_content.inc	(revision 462)
+++ plugins/context_condition_content.inc	(working copy)
@@ -16,7 +16,7 @@
 
     // This plugin can only support one column fields.
     $column = key($field['columns']);
-    foreach ($node->{$this->plugin} as $item) {
+    if (!empty($node->{$this->plugin})) foreach ($node->{$this->plugin} as $item) {
       // Do not check against undefined values
       if (!$item[$column]) {
         continue;

Was this the correct solution?

jyg

steven jones’s picture

Status: Needs review » Needs work

Need to check that something is iterator-able before iterating over it

jacerider’s picture

Subscribing.

codycraven’s picture

StatusFileSize
new4.35 KB

For #26 I was unable to reproduce the issue with the information given. Also logically I do not see how that error could be displayed as a CCK field should always at the minimum produce array('0' => array('value' => NULL)) in $node->{$this->plugin}, which is iterable.

I added a wrapper to the .install to prevent a fatal undefined function error if the site does not have content installed.

This is looking like a pretty solid patch now, marking needs review.

codycraven’s picture

Status: Needs work » Needs review
StatusFileSize
new4.71 KB

I was able to reproduce the issue in #26 on a user registration page with node profiles. Attached is the patch with an if wrapper in the plugin.

dman’s picture

Yeah, it's a bit of an edge case, but still got me. Patch fix looks fine, I think.

Now I'm trying to figure out if a new issue I'm having - using a cck field as a checkbox - is failing to register because the unchecked state (0) isn't being saved... 0 (off) is different from NULL (never saved) but somehow it's not saving for me. Even the Context UI won't let me save it (a checkbox in an off state as a condition). Probably just me.

djroshi’s picture

Thanks for this

tim.plunkett’s picture

Priority: Critical » Normal
Status: Needs review » Reviewed & tested by the community

Looks okay to me. Patch had to be applied with -p3, be warned.

pindaman’s picture

thanks, I was looking for this really long..
working great.
after doing : patch -p3 < context_content-629756-30.patch

btopro’s picture

sub

berenddeboer’s picture

Version: 6.x-3.x-dev » 6.x-3.0
StatusFileSize
new3.04 KB

Why is this not in context? It works perfectly. I've rerolled it against the official 3.0 release in case people are using that.

gstout’s picture

Sorry this re-roll patch in #36 is no good.

It fails to create context_condition_content.inc which then tosses a fatal missing required plug-in error.

The original in #30 is fine for dev

jelo’s picture

Has this patch made it into the module? I am wondering if there will be an option to have a context that checks against a CCK field with "contains" operator?

yannickoo’s picture

What's about the 7.x branch?

doublejosh’s picture

webflo’s picture

StatusFileSize
new4.31 KB

Re-rolled the patch from comment #30. The patch in #36 is broken because plugins/context_condition_content.inc is missing.

webflo’s picture

Removed the revision marker in plugins/context_condition_content.inc.

fadgadget’s picture

Hello does #42 work against the latest Dev version? I keep getting a wsod. I think it might be my patching skills.

Thanks

kristen pol’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Closed (outdated)

Thanks to everyone for the work on this issue. Closing as outdated as this is for Drupal 6.