I'm using panels 3 (selection rules) and I'm trying to figure:

IF context term = Posters
return true

pretty simple, but I do not understand how to access the contexts from with in PHP. I've searched everywhere for a solution.

please help, thanks ^__^

Comments

mossill’s picture

I can't find any solid references to this feature.

mossill’s picture

I'm not referring to using php for a panel display. I'm referring to the Selection rules area for php. The $contexts array is available. It prints out values if you run a:

print_r(array_values($contexts));

yeah man..... awesome-ness

I'm just having trouble accessing the object. Here is what it prints out (Contexts Data)

Array (
[0] =>
ctools_context Object (
[type] => Array ( [0] => terms [1] => term )

[data] =>
stdClass Object (
[tid] => 4
[vid] => 1
[name] => Fashion
[description] =>
[weight] => 0
)
[title] => Fashion
[page_title] =>
[identifier] => Term(s) being viewed
[argument] => 4
[keyword] => term
[original_argument] => 4
[restrictions] => Array ( )
[empty] =>
[plugin] => terms
[operator] => and
[tids] => Array ( [0] => 4 )
[id] => argument_terms_1
)

[1] =>
ctools_context Object (
[type] => string
[data] => 0
[title] => Unknown context
[page_title] =>
[identifier] => Depth
[argument] =>
[keyword] => depth
[original_argument] => 0
[restrictions] => Array ( )
[empty] =>
[plugin] =>
string [id] => argument_string_1
)

[2] =>
ctools_context Object (
[type] => vocabulary

[data] =>
stdClass Object (
[vid] => 1
[name] => Store
[description] =>
[help] => Hold Ctrl while clicking to select multiple categories.
[relations] => 1
[hierarchy] => 1
[multiple] => 0
[required] => 1
[tags] => 0
[module] => uc_catalog
[weight] => 0

[nodes] => Array ( [clothing] => clothing [film] => film [music_album] => music_album [poster] => poster [music_bundle] => music_bundle [product] => product )
)

[title] => Store
[page_title] =>
[identifier] => tax-vocab
[argument] => 1
[keyword] => tax-vocab
[original_argument] =>
[restrictions] => Array ( )
[empty] =>
[plugin] => vocabulary
)

[3] =>
ctools_context Object (
[type] => term

[data] =>
stdClass Object (
[tid] => 4
[vid] => 1
[name] => Fashion
[description] =>
[weight] => 0
)
[title] => Fashion
[page_title] =>
[identifier] => Term parent
[argument] => 4
[keyword] => parent_term
[original_argument] =>
[restrictions] => Array ( )
[empty] =>
[plugin] => term
)

[4] =>
ctools_context Object (
[type] => user

[data] =>
stdClass Object (
[uid] => 1
[name] => admin
[pass] => no way jose
[mail] => mossbird.cc
[mode] => 0
[sort] => 0
[threshold] => 0
[theme] =>
[signature] =>
[signature_format] => 0
[created] => 1247515438
[access] =>
[login] =>
[status] => 1
[timezone] =>
[language] =>
[picture] =>
[init] =>
[data] => }

[timezone_name] =>
[sid] =>
[hostname] => 71.198.15.198 [timestamp] => 1255405320 [cache] => 0 [session] => uc_cart_id|s:32:"";node_overview_filter|a:0:{}

[form_build_id] => form-
[roles] => Array ( [2] => authenticated user [3] => admin )
)

[title] => admin
[page_title] =>
[identifier] => Logged in user
[argument] => 1
[keyword] => viewer
[original_argument] =>
[restrictions] => Array ( )
[empty] =>
[plugin] => user
[id] => 0 )

)

awesome !

mossill’s picture

Ok I got it. retrieve the object you want from the array then use it as an object.

one easy way is:
$object = $contexts['context_vocabulary_1'];
print $object->type;

digidev’s picture

$contexts['context_vocabulary_1'];

Not sure where you get the "context_vocabulary_1" from? Wouldn't that be rather something like $contexts[0] ?

Unless I'm missing some php logic (it's been a while since I used it)

Adam S’s picture

Looking at the time of the comments I can only imagine what you did all day. You only just prove the best way to help the Drupal community is by helping yourself! Thanks for the effort......... I passed it on over here http://drupal.org/node/578900#comment-2174250

nevets’s picture

This may be a silly question but since you have a context on term when you add a selection rule can't you add a rule on "taxonomy: term" (or what ever you names the context) and select the term there?

rogical’s picture

Drupal Solution Architect