warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/www/html/sites/all/modules/filefield/filefield.module on line 267.

This error come when I finish setting up a cck image field with "Widget type: Image with cropping"

Earlier I faced this error on 6.x-3.0-alpha5 that came on on line 273 .. NOT with the dev version it is on line 267.

any idea?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bensemmel’s picture

Same error

CKIDOW’s picture

Same thing here...

realityloop’s picture

Same issue here

drewish’s picture

Status: Active » Postponed (maintainer needs more info)

please try the -dev release and confirm that it's present there too.

mrfelton’s picture

I get the same problem using alpha6 which was created on the same day as the latest -dev version.

apaderno’s picture

Title: warning: array_merge() [function.array-merge]: Argument #2 is not an array in » Wrong argument for array_merge()
mariusooms’s picture

Same issue...subscribe. Filefield 6.x-3.0-alpha6, haven't tried dev.

Marius

markus_petrux’s picture

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

I believe this problem is caused by imagefield_crop module.

In filefield_widget_settings() there's the following code:

  $function = $widget_type .'_widget_settings_'. $op;
  if (function_exists($function)) {
    $return = array_merge($return, $function($widget));
  }

And that means any module that implements a {$widget_type}_widget_settings_{$op} should return an array. However, if we look at imagefield_crop_widget.inc, there's at least one of these implementation that doesn't meet the requirement, hence it crashes in the caller. For example:

function imagefield_crop_widget_widget_validate($element) {
//  dpm(__FUNCTION__ . "[{$element['#type']}]");
  // Check if crop values are not empty
}

One possible solution for filefield would be to check the result of calling widget_settings function, maybe like this:

  $function = $widget_type .'_widget_settings_'. $op;
  if (function_exists($function)) {
    $result = $function($widget);
    if (is_array($result)) {
      $return = array_merge($return, $result);
    }
  }
apaderno’s picture

Status: Needs review » Active

The code reported in #8 is present in 6.x-3.x-dev too.

As stated in field.php, the values returned from the implementation of hook_widget_settings() are:

  • - "form": an array of form elements to add to the settings page.
  • - "validate": no return value. Use form_set_error().
  • - "save": an array of names of form elements to be saved in the database.

It doesn't then seem a problem with a specific module.

markus_petrux’s picture

hmm... that field.php doesn't exist in CCK 6. Anyway, 'validate' is probably the cause of the problem here. The file imagefield_crop_widget.inc contains a widget validate handler that's empty, it returns nothing, hence it causes the reported problem on filefield.

Note that is reported to happend when setting up a "Widget type: Image with cropping", so this is an issue that can be fixed in 2 ways:

1) imagefield_crop removes the function imagefield_crop_widget_widget_validate() or makes it return array().
2) filefield code includes a defensive check in the loop running widget operation handlers so that array_merge is used only if the return value is an array.

apaderno’s picture

The content of field.php is also reported in the documentation for hook_widget_settings().

I think that is rather difficult a validation function in the FAPI style is required to return anything, in Drupal.
filefield.module should avoid to check the return value when $op is equal to 'validate' or, more generally, it should check the value type returned from the called function.

For other informations, see CCK for Developers.

markus_petrux’s picture

Oh, I see what you mean. Then, probably imagefield_crop_widget_widget_validate() would be compliant with CCK documents, and the correct fix would affect filefield, so it should do something like this:

  $function = $widget_type .'_widget_settings_'. $op;
  if (function_exists($function)) {
    if ($op == 'validate') {
      $function($widget);
    }
    else {
      $return = array_merge($return, $function($widget));
    }
  }

...or more generally, a defensive check on the result as posted in #8:

  $function = $widget_type .'_widget_settings_'. $op;
  if (function_exists($function)) {
    $result = $function($widget);
    if (is_array($result)) {
      $return = array_merge($return, $result);
    }
  }

This is part of function filefield_widget_settings() in filefield.module.

apaderno’s picture

Status: Fixed » Active

The defensive check on the result is probably better for when CCK implements new operations for the hook_widget_operations(), and filefield.module is still not updated to handle them.

I would write the code like:

  $function = $widget_type .'_widget_settings_'. $op;
  if (function_exists($function)) {
    $result = $function($widget);
    if (isset($result) && is_array($result)) {
      $return = array_merge($return, $result);
    }
  }

The call to isset() before the call to is_array() is normally used on Drupal code; it avoids the code raises an access to a undefined variable warning.

drewish’s picture

someone want to roll a patch?

markus_petrux’s picture

Status: Active » Needs review
FileSize
502 bytes

Attached patch as in #13

markus_petrux’s picture

Re-rolled as the same exact issue affects other pieces of code in filefield.module.

drewish’s picture

Status: Needs review » Fixed

looks good, committed to HEAD.

bgogoi’s picture

Status: Active » Fixed

i just patched mine. no issues now. Thanks to all of you :)

Status: Fixed » Closed (fixed)

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