I think I'm the first one to try and implement the 'base' property in hook_features_api(). In doing so I found a bug in features_export_render(). Or I must be doing something wrong. That's also possible because of the lack of documentation on the property (Document example for 'base' implementation of hook_features_api).

The bug itself is caused because the $components key doesn't match the $component_hooks key when using the 'base' property. When the 'base' property is set it should be passing in the right component key instead of the 'base' property.

function features_export_render($export, $module_name, $reset = FALSE) {
  $code = array();

  // Generate hook code
  $component_hooks = features_export_render_hooks($export, $module_name, $reset);
  $components = features_get_components();
  $deprecated = features_get_deprecated($components);

  // Group component code into their respective files
  foreach ($component_hooks as $component => $hooks) {
    if ($reset && !empty($deprecated[$component])) {
      // skip deprecated components on final export
      continue;
    }
    $file = array('name' => 'features');
    if (isset($components[$component]['default_file'])) {
      switch ($components[$component]['default_file']) {
        case FEATURES_DEFAULTS_INCLUDED:
          $file['name'] = "features.$component";
          break;
        case FEATURES_DEFAULTS_CUSTOM:
          $file['name'] = $components[$component]['default_filename'];
          break;
      }
    }
...

So this piece of code should take into account that if the 'base' property is set, it's component key should match the $component_hooks key. Otherwise the code will always end up in the mymodule.features.inc file. And I don't know what other reprecussions that can have.

It looks to me that the 'base' implementation was added for supporting my edge use case. But it wasn't fully implemented in the other hooks. I think it should be looked at again.

I will see if I can write a patch to fix this single bug. But I'm expecting a lot more to follow.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexverb’s picture

Version: 7.x-2.0-rc3 » 7.x-2.x-dev
Status: Active » Needs work
FileSize
1.72 KB

The following patch checks if a base component exists if no component is matched. But looking further into this issue it looks like using the 'base' property creates a multitude of new problems. A lot of the hooks do not bring along the $component parameter.

So for example: if I would like to split up the code through hook_features_export_render() in different files by using different components with the 'base' property I cannot use the components key to differentiate the function names. So I would be able to generate different files with this patch. But if generating the same function name I imagine redeclaration errors popping up immediatly.

So my prediction of stumbling into more problems seems to be right. For now I'm just going to abandon this issue until someone picks up the documentation issue above. Because it's simply too complex for me to understand.

RavindraSingh’s picture

Status: Needs work » Postponed (maintainer needs more info)

@alexverb, are you still facing this issue? please reopen. I am not facing this issue as of now with latest version.

mpotter’s picture

Priority: Major » Normal