Closed (outdated)
Project:
Context
Version:
6.x-3.0
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Anonymous (not verified)
Created:
11 Nov 2009 at 14:42 UTC
Updated:
22 Feb 2023 at 08:55 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
bohz commentedThanks 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
Comment #2
steven jones commentedInteresting, would be good to get this in to 2.x.
Comment #3
steven jones commentedCommitted to 2.x
Comment #4
yhahn commentedForward port would be great, at your leisure.
Comment #5
ManyNancy commentedThank you all, subscribe.
Comment #6
yhahn commentedComment #7
tim.plunkettSub. I need this desperately, I guess I should work on a patch.
Comment #8
tim.plunkettWell I got something working, but it now needs a reroll since you just moved context_context_registry. Here's my diff from svn.
Comment #9
tim.plunkettAlright, this is rerolled against CVS.
Comment #10
tim.plunkettI'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.
Comment #11
yhahn commentedAgreed, 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.
Comment #12
tim.plunkettI'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?
Comment #13
Anonymous (not verified) commented@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.
Comment #14
yhahn commented@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.
Comment #15
tim.plunkettUgh. 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?
Comment #16
jyg commentedI 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?
Comment #17
cyberderf commentedInterested... Can you explain what it does in details ?
Comment #18
webflo commentedHi, 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.
Comment #19
tim.plunkettAwesome, I'll check it out.
Comment #20
webflo commentedHi, 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.
Comment #21
Anonymous (not verified) commentedI'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.
Comment #22
jumpfightgo commentedI 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.
Comment #23
markabur commentedNice. 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.
Comment #24
dman commentedNice - just what I was looking for!
Works good for me. Clean code.
Comment #25
dman commentedI 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.
Comment #26
jyg commentedFor #25 I was getting this error:
when I did this, it stopped complaining and I do not think I've harmed anything:
Was this the correct solution?
jyg
Comment #27
steven jones commentedNeed to check that something is iterator-able before iterating over it
Comment #28
jacerider commentedSubscribing.
Comment #29
codycraven commentedFor #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.
Comment #30
codycraven commentedI 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.
Comment #31
dman commentedYeah, 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.
Comment #32
djroshi commentedThanks for this
Comment #33
tim.plunkettLooks okay to me. Patch had to be applied with -p3, be warned.
Comment #34
pindaman commentedthanks, I was looking for this really long..
working great.
after doing : patch -p3 < context_content-629756-30.patch
Comment #35
btopro commentedsub
Comment #36
berenddeboer commentedWhy is this not in context? It works perfectly. I've rerolled it against the official 3.0 release in case people are using that.
Comment #37
gstout commentedSorry 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
Comment #38
jelo commentedHas 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?
Comment #39
yannickooWhat's about the 7.x branch?
Comment #40
doublejosh commentedThere're two modules for this type of thing...
http://drupal.org/project/context_bool_field
http://drupal.org/project/context_entity_field
Comment #41
webflo commentedRe-rolled the patch from comment #30. The patch in #36 is broken because plugins/context_condition_content.inc is missing.
Comment #42
webflo commentedRemoved the revision marker in plugins/context_condition_content.inc.
Comment #43
fadgadget commentedHello does #42 work against the latest Dev version? I keep getting a wsod. I think it might be my patching skills.
Thanks
Comment #44
kristen polThanks to everyone for the work on this issue. Closing as outdated as this is for Drupal 6.