I've been going over the example code in features.api.php to see what I need to change, and had some questions.

Where the example code refers to "mycomponent_defaults" - that is meant to be the default_hook value for the component, yes? Is there a way to get that string from the component definition instead of having it hardcoded in multiple places?

In the revert hook example, it makes a direct call to module_invoke_all($module_name, 'mycomponent_defaults');. Is there a reason to do that vs a call to features_get_default('mycomponent', $module_name)?

Thanks!

Comments

yhahn’s picture

Status: Active » Fixed

Where the example code refers to "mycomponent_defaults" - that is meant to be the default_hook value for the component, yes? Is there a way to get that string from the component definition instead of having it hardcoded in multiple places?

Yes, that is the default hook. In terms of redundancy, I'm assuming you're referring to the return value of hook_features_export_render(). This is a change we could make in the next version of the API, but at the moment the explicit declaration of the defaults hook in hook_features_export_render() gives you the additional flexibility of writing more that one function if you were to need them.

Is there a reason to do that vs a call to features_get_default('mycomponent', $module_name)?

Yes, if your component has been written into include files by Features you will want to use features_get_default('mycomponent', $module_name). It is more or less equivalent to doing this:

features_include_defaults('mycomponent');
$defaults = module_invoke($module, 'mycomponent_defaults');
brad.bulger’s picture

about the default_hook value - the explicit use of the hook name in the render function makes sense, for the reasons you say. i meant more the redundancy in my own module's code. if for some odd reason i change the value of "default_hook" in the component declaration, i would have to go change the string where it appears elsewhere. looking through the features code, it seems like i could make a call to features_get_default_hooks() to avoid that:

  $default_hook = features_get_default_hooks('mycomponent');
  return array($default_hook => $code);
....
  $default_hook = features_get_default_hooks('mycomponent');
  $mycomponents = module_invoke_all($module_name, $default_hook);

or just use a constant or some such. this is a very minor thing. mostly about making clear what the string is and where it comes from.

the question about how to get defaults in the revert() hook function came up because i was getting FALSE, but i see now that's because module_name and component swapped places in the call. so just my bug.

thanks for the quick response!

Status: Fixed » Closed (fixed)

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