I created the contactemail and wanted to use the node context to output some more information on the contact panel like the contacts name and a link back to the node. But the context is empty. It was not easy to find the problem because there is not much documentation around ctools. But finally I found why the context was not loaded (because just the empty placeholder was loaded) and I fixed it to load the node into a context.

See patch below.

Comments

osopolar’s picture

Status: Active » Needs review
StatusFileSize
new927 bytes

We can't use ctools_context_get_placeholders_from_argument() because it will only return an empty context, as discription says: Retrieve a list of empty contexts for all arguments. The correct function is ctools_context_handler_get_task_contexts().

chriscalip’s picture

   // @todo add ability to accept the node and field name context; well maybe just the node context
 
-  // is it worth the performance hit to include node as a context? if so switch
-  //$contexts = emailpanels_contactemail_get_contexts($task, '', array($nid));
-  $contexts = emailpanels_contactemail_get_contexts($task, '', array());
-
+  // Load the node into a context.
+  $contexts = ctools_context_handler_get_task_contexts($task, '', array($nid));
   $output = ctools_context_handler_render($task, '', $contexts, array('nid' => $nid, 'field_name' => $field_name));
   if ($output !== FALSE) {
     return $output;

Yeah, is it worth the performance hit to include a context?

I am guessing you are saying yes. I guess in hindsight it really does not matter since we can cache pages.

I'll add on my to-do. Thanks

osopolar’s picture

What performance hit you are talking about? The only one I can see would be node_load, but node_load is caching the node object ... so we loose some performance here, but we will get it back in email_mail_page() ;)

osopolar’s picture

@chriscalip: so what do you think about the performance hit, is there a performance hit?

chriscalip’s picture

Status: Needs review » Fixed

@osopolar : i was just over-thinking about it; it would be negligible really because most of the time we do cache. but even without cache it's not so bad. BTW thank you for your contribution;
commited to dev.
http://drupalcode.org/project/panels_extras.git/commit/f050785

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.