Closed (fixed)
Project:
Chaos Tool Suite (ctools)
Version:
7.x-1.x-dev
Component:
Page Manager
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
31 Jan 2012 at 13:09 UTC
Updated:
15 Feb 2012 at 09:00 UTC
I am coding a custom task_handler for a node_view task.
My render callback looks currently like the code below (the most of my code was copied from http_response task_handler).
Now I want to access the node object in the $contexts: array(..., [argument_entity_id:node_1] => ctools_context Object, ...); I guess I should not write $node = $contexts['argument_entity_id:node_1']->data, should I? Because the array key looks very generic. I think there should be a function to retrieve the node context. May somebody help me to find a good way to get the node object out of the contexts array?
// Go through arguments and see if they match.
ctools_include('context');
ctools_include('context-task-handler');
// Add my contexts
$contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler);
// Test.
if ($test && !ctools_context_handler_select($handler, $contexts)) {
return;
}
if (isset($handler->handler)) {
ctools_context_handler_pre_render($handler, $contexts, $args);
}
// Get node object from context.
// This works but does not look good, because argument_entity_id:node_1 looks very generic.
$node = $contexts['argument_entity_id:node_1']->data;
Comments
Comment #1
merlinofchaos commentedI *just* wrote code similar to this, and it's in the very latest Panelizer 2.x -- go see the panelizer_node task there. I think it should answer all your questions by virtue of being actual working code, but if you have further questions please activate this issue again and I will try to elucidate if you need it.
Comment #2
osopolarThank you merlinofchaos for the quick and helpful response.
To resume: Panelizer uses a function which get the correct context from the configuration if set, otherwise it takes just the first context available: