Ctools plugin api code generated by features is - well - less than ideal ;). So this is an example of the hook_ctools_plugin_api code generated by features:

/**
 * Implements hook_ctools_plugin_api().
 */
function file_types_ctools_plugin_api() {
  list($module, $api) = func_get_args();
  if ($module == "file_entity" && $api == "file_default_displays") {
    return array("version" => "1");
  }
}

This issue has to do with this code: list($module, $api) = func_get_args(); The issue here is that features is not using the method arguments in the method, but rather getting them after the fact. The ctools API is currently very stable, so why this is done I have no idea. The issue was discovered when I was doing simple tests, and i just started throwing no arguments, one argument and so on to see what would happen. The result was that my test started throwing notices when i threw no arguments, or just one.

Fixing this would be a matter of actually putting the arguments in the method, rather than getting them after the fact. This way you ensure that there are always two arguments being thrown. The ctools people themselves - in their tutorial - would have written the method like this:

/**
 * Implements hook_ctools_plugin_api().
 */
function file_types_ctools_plugin_api($module, $api) {
  if ($module == "file_entity" && $api == "file_default_displays") {
    return array("version" => "1");
  }
}

To make this properly testable, and avoid it throwing these notices, I submit that we start using the ctools way of doing it. If not, I'd like to hear arguments of why we don't want to do it the way the ctools developers themselves say we should.

Comments

mpotter’s picture

Status: Active » Needs review

Your reasoning makes sense. My guess is that this is left over from some long-past issue with ctools api that is no longer relavent. But I'll keep this open for a while to get opinions from people who might have worked on features several years ago if there is any reason why this shouldn't be fixed.

lorique’s picture

@mpotter
I had a hunch it was a something like this. My issue here is not really that my test is throwing notice errors, although i prefer my code to be free of such things, but that the code is actually not very good. If I were to keep doing this, without using method arguments, id rather do something like this:

$args = func_get_args();
if (isset($args[0]) {
  $module = $args[0];
}
else {
  $module = '';
}

if (isset($args[1]) {
  $api = $args[1];
}
else {
  $api = '';
}

This code does it correctly, because it only assigns argument values to the variables if the values are there.. if not its simply set to empty. What the list function does not do, is check if there are actually any arguements there to assign values to, which in turn throws notices. So we can still use the same approach if its needed, but we can improve it so it no longer throws these notices. So regardless of the outcome of the next few comments, I think a patch is required.

hefox’s picture

  list($module, $api) = func_get_args();
  if ($module == "page_manager" && $api == "pages_default") {
    return array("version" => "1");
  }
  list($module, $api) = func_get_args();
  if ($module == "panelizer" && $api == "panelizer") {
    return array("version" => "1");
  }
  list($module, $api) = func_get_args();
  if ($module == "panels_mini" && $api == "panels_default") {
    return array("version" => "1");
  }
  list($module, $api) = func_get_args();
  if ($module == "strongarm" && $api == "strongarm") {
    return array("version" => "1");
  }

Here an example from an export... repeats a bit.

So yea, sounds like [module]_ctools_plugin_api($module => NULL, $api => NULL) should work instead?

hefox’s picture

Status: Needs review » Active

There's not actually a patch

lorique’s picture

@hefox

I didn't actually have time to create a patch when i added this issue last year, I was hoping someone with more experience with features would since its a fairly complex module. It doesn't seem likely though :(

mpotter’s picture

Status: Active » Needs review
StatusFileSize
new1.24 KB

OK, here is a patch that I think handles this.

Turns out this isn't "left over" from anything old. The issue was that Features didn't used to allow exported functions to contain any arguments. That was improved when Features Override was added so the returned code can have a 'code' and 'args' keys.

Status: Needs review » Needs work

The last submitted patch, features-ctools_api-1869654-6.patch, failed testing.

mpotter’s picture

Version: 7.x-1.0 » 7.x-2.x-dev

Bah, need to set the correct branch! Tester, try again!

mpotter’s picture

Status: Needs work » Needs review
mpotter’s picture

#6: features-ctools_api-1869654-6.patch queued for re-testing.

mpotter’s picture

Status: Needs review » Fixed

Passes testing, so committed to fc56938.

lorique’s picture

Took 6 months, but it got there.. YAY @mpotter!

Status: Fixed » Closed (fixed)

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