Closed (fixed)
Project:
Chaos Tool Suite (ctools)
Version:
7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Reporter:
Created:
23 Jun 2011 at 21:17 UTC
Updated:
19 Oct 2012 at 23:31 UTC
I'm a front end guy who is trying to learn some php but I can't seem to figure this out. I have a select list field in a node called Project Status and I would like to control visibility of various panel regions based on the value of this field. The $context variable is %node:field-proj-status and the php variable is $node->field_proj_status (array) but everything I try returns an error. Thanks in advance
Comments
Comment #1
blackclover commentedThanks to merlinofchaos!
Returns TRUE when the node being viewed proj_status field is set to Approved, exposing the content.
Hopefully this help.
Comment #2
blackclover commentedComment #3
valante commentedI've run into this issue myself. I dislike the solution above because it calls an external function when the PHP selection rule screen clearly states you have a $contexts variable available.
I entered the following code in the PHP rule:
Then I saved, loaded a sample node, read the message, and got the correct index for the field I wanted to test. Voila!
Comment #4
merlinofchaos commentedThis should be part of the documentation.
Comment #5
blackclover commentedSorry I'm somewhat of a PHP newby. I thought I tried that and it wouldn't work. Could you give me a sample snippet? Thanks
Comment #6
tobyontour commentedvalante> Absolute life-saver. Thanks
Comment #7
valante commented@blackclover, if you mean my method:
Notice that some of the $contexts array items are stdObjects, so the syntax is a little complicated.
Accessing an index in an array: $array_name['index_name']; (index name is enclosed in single/double quotes)
Accessing an object's property: $object_name->property_name; (property name is not enclosed in quotes)
For me, the value I wanted to test was something like this:
Hope that helps!
Comment #8
blackclover commentedThanks, I appreciate the tip. I'll give it t a try.
Comment #9
blackclover commentedThanks, I appreciate the tip. I'll give it t a try.
Comment #10
johnw3600 commentedDitto ...thanks.
This has completely opened up what I can do with content filtering!
But given that you can choose such items as 'Context', 'Node:classifications', 'URL', 'User:classifications' etc, its very surprising that the most obvious object, a 'content filter' is not there (or am I missing the point somewhere?)
Nonetheless a combination of comments from Valante:
print_r($contexts... ...and
return !empty($contexts['argument_entity_id:node_1']->data->your_field_name_here);
...allowed me to test against a 'Live' field whether content should be revealed or not:
return $contexts['argument_entity_id:node_1']->data->field_live['und'][0]['value'];(note that I have multi-lingual features enabled, hence 'und' in this case)
Cheers,
John
Comment #11
bryancasler commented#3 doesn't work for me. I've got php enabled and it's certainly being used.
http://www.diigo.com/item/image/1ks4o/7mts?size=o
There's three scenarios I'd love help figuring out code snippets for.
For the snippets lets assume our field name is field_XXXX
Any help would be greatly appreciated.
Comment #12
valante commented@animelion, your PHP is definitely not being used, seeing as the drupal_set_message line is printed to screen instead of being evaluated. Where exactly did you enter this snippet? And did you by any chance surround it with php tags (which shouldn't be there)?
Comment #13
bryancasler commented@valante I think you're right about the php tags, but I can't test that. Running into this problem now #1355300: Unable to Add Content to Panels.
Comment #14
bryancasler commented@valante It worked perfect. Thanks. Going to head over here #1300476: Add Access Plugin for Entity Field Value and here #1356494: Visibility rule becomes broken now.
Comment #15
Ashlar commentedComment #16
a.knutson commentedJeez, that was insanely helpful for me. Thanks a lot Valante.