I got this error message when trying to create a feature.

Warning: Invalid argument supplied for foreach() in conditional_fields_features_export_options() (Zeile 14 von /sites/all/modules/conditional_fields/includes/conditional_fields.features.inc).

This is the function:


function conditional_fields_features_export_options() {
  $dependencies = conditional_fields_load_dependencies();
  $entity_info = entity_get_info();
  $options = array();
  foreach ($dependencies as $type => $data) {
    foreach ($data as $dependency => $info) {
      $option = $type . ':' . $dependency;
      if (!isset($options[$dependency])) {
        $options[$option] = $entity_info[$type]['bundles'][$dependency]['label'] . ' (' . $type . ')';
      }
    }
  }
  return $options;
}

The function conditional_fields_load_dependencies(); can return "false" if there are no dependencies (?). I think this is what happens here. So I added this to check my findings:


  if (!is_array($dependencies)) {
    $dependencies = array();
  }

Message gone.

Changed the code to this:

  if (!is_array($dependencies)) {
    return (array());
  }

This code does not look good, so the patch is not good. But its late right now.

How could I do this in good coding style?

Comments

darrenmothersele’s picture

I got the same error message. I think instead of patching conditional_fields.features.inc we should patch conditional_fields_load_dependencies() so that it returns an empty array when there are no dependencies.

JThan’s picture

Status: Active » Needs review

Sounds good to me, I just did not know what implications this could have at other places in the module. But it is definitely better to solve this at the place you solved it. So, let someone test this?

yvmarques’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, for the patch #1 works for me !

Cheers,

-- Yvan

IshanComBr’s picture

patch #1 works for me also

TKS!

peterpoe’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Typo