There is a alter_stubs.inc file that holds a bunch of hook_alter functions to allow plug-ins a chance at having a hand at drupal_alter. The problem with this is that it gets called for hexagon even when it isn't even used. It creates more overhead and the stub file is kind of large and can only grow larger. It also creates a new name space so it doesn't go into an infinite loop. Not exactly ideal. The only thing good about this is that for some drupal_alter hooks, the plug-in could just use an alter function and it would just work.

The coming change moves away from that. The alter_stubs.inc file will only host the alter hooks the plug-ins actually use. This will curb the growth of the file and minimize the overhead of drupal_alter having to call it for the theme.

If a sub-theme contains a plug-in that needs an alter hook, it must also provide the stubs in its host theme but in most cases I don't think plug-ins will be altering too much so I think this is a reasonable tradeoff.

Here's an example of a stub:

/**
 * Implements hook_css_alter().
 * @see drupal_get_css()
 */
function hex_css_alter(&$css) {
  hex_plugin_alter('hex', 'css', $css);
}

The hex_plugin_alter() is what handles the alter for the plug-in. Simply provide alter function specific to the host theme and add that function. Provide the name of the host theme for the first parameter, the type of alter for the second and the rest for the data. The rest will be taken care of.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dvessel’s picture

dvessel’s picture

Status: Active » Fixed
FileSize
879 bytes

Had a typo in a function preventing the debug mode form elements from showing in the theme settings page.

dvessel’s picture

Another follow-up. This time the function should be called with the __FUNCTION__ magic method instead of the two parameters. ex: hex_plugin_alter(__FUNCTION__, $data). Less chance of errors from manually typing the wrong $host. The patch also removes more alter stubs that weren't used.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

bad grammar.