Drupal 7: Watch for hyphens in CTools and Panels plugin names

I recently ran into an interesting problem with the way CTools plugin methods are discovered (namely, CTools content types, used by the Panels ecosystem) in Drupal 7.

The project I was working on had various content types named things like piwik-tracking-code (not the exact name, but good enough to illustrate the issue).

Panels looks for various methods, such as settings and render methods, by taking the machine name of the plugin (typically the filename) and adding suffixes to it—a lot like hooks, in fact.

You might be able to see where I’m going with this if you’re familiar with PHP. That’s right: piwik-tracking-code_render() is not a valid function name! Therefore, it fails.

There are a couple ways around this. With some of the plugin functions, you can specify the function names in the definition or in one of the functions. If you must hyphenate, you have to do this.

The other way, of course, is to simply use underscores. This is what I did and what I would recommend.