This is a quick and dirty tutorial for calling a CTools/Panels 3 custom handler from code. It works for handlers for the system pages, such as the user page override. Calling custom/panels pages from code is different. Make sure you replace all instances of MODULE_NAME with your module's name.
Step 1: Create a file named MODULE_NAME.delegator_default.inc and put it somewhere in your module's directory.
Step 2: Paste in the following code.
/**
* Implementation of hook_default_delegator_handlers()
*/
function MODULE_NAME_default_delegator_handlers() {
// BEGIN HANDLER EXPORT ******************************************************/
// PASTE YOUR HANDLER EXPORT IN HERE
// END HANDLER EXPORT ******************************************************/
$handlers[$handler->name] = $handler;
return $handlers;
}
?>
If you have multiple handlers to export, make sure each one ends with $handlers[$handler->name] = $handler; to put it in the array, and return the full array at the end.
Step 3: On the task handler list page, click on "operation" and then choose "export" from the drop down. Copy the contents where it says // PASTE YOUR HANDLER EXPORT IN HERE in the code above.
Step 4: Add the following code to your .module.
function MODULE_NAME_ctools_plugin_api($module, $api) {
if ($module == 'delegator' && $api == 'delegator_default') {
$module_path = drupal_get_path('module', 'MODULE_NAME');
return array('version' => 1, 'path' => $module_path . '/path/to/include/file');
}
}
?>
Change "/path/to/include/file" to the actual path from your module root to MODULE_NAME.delegator_default.inc. You can leave out the 'path' if it's in the module's root.
Step 5: Clear your cache.
At this point, if everything worked, you should see the "Type" change from "Normal" to "Overridden" which means it sees the handler in code but is still using the one in the database.
Bonus step: If you don't like the name MODULE_NAME.delegator_default.inc, you can call it something else by adding 'file' => 'filename' to the array in MODULE_NAME_ctools_plugin_api.
Thanks again to merlinofchaos for patiently getting me through doing this for APK's user page and for adding a couple suggestions to this article. :)
Comments
Hi Michelle! Great to see
Hi Michelle!
Great to see your tremendous effort on this. I am absolutly looking forward to the new APK and very confident that it will rock.
I never really understood Panels2 so I am happy to learn Panels 3. Glad that people like you already using it.
Can you (perhaps on the project page) give a rough timeframe? I don't want to pressure you - just curious.
I mentioned a while ago that my page would launch but I sadly only could run tests and had to do some big changes (and got some financial troubles, sigh). However we are about to go live and I am wondering if I should stall this due to my reliance on the "old" APK. I know you discourage us from using it but it works pretty well even with the buggy Panels 2.
Your work is great - thanks!
Sorry, I avoid giving ETAs
Sorry, I avoid giving ETAs because I think people will get hurt worse if I guess and am wrong than to just say "when it's ready". If I would have given you an ETA 2 months ago, I would be 2 months late because I never thought it would take this long. I can say that I've got the P2 version nearly replicated in P3, though, and am mostly doing clean up and testing. So shouldn't be too long, unless I run into unexpected snags.
I'm discouraging people from using the current Alpha because upgrades are going to be rough and unsupported. If it's working for you, that's fine. Just be aware that Panels 2 is going to be deprecated as soon as Panels 3 is stable enough and you will need to re-install the APK and redo any customizations. It's possible the Panels' upgrader will work with it but the odds aren't good.
Michelle
Nice Michelle! Is this the
Nice Michelle! Is this the first Panels 3 random howto I've seen in the wild?
No problem! That is a
No problem!
That is a sensible approach and I was simply fishing. I am aware that P2 is going over board but at the moment there is simply a gap - nothing to do about this.
Seeing this P3 stuff makes my head spin......
Rock on!
edit: Mollom sucks!
@Simon: Well, I suppose it
@Simon: Well, I suppose it depends if you've seen the other two I wrote. ;)
@dddave: Yeah, I know it's a bad spot right now while I chase P3. The good news is that it won't be too much longer. (I hope!)
As for Mollom, it's blocked 64,607 spams on this site so far. So I'm pretty happy with it. :)
Michelle
@Mollom Something must have
@Mollom
Something must have changed in the last days because I know have constantly to do a captcha because Mollom got suspicious. Noticed that on a couple of sites and find it pretty annoying. But I guess on your side it does a good job and the number sounds pretty impressive.
@dddave: It could be that
@dddave: It could be that your IP has gotten flagged as a spammer in it. Might want to go to their site and see if they have any options for getting off their list.
Michelle
Awesome, great tutorial .
Awesome, great tutorial . Thanks for sharing
Your work is great - thanks!