Download & Extend

Bug in Handling filefields within multivalued flexifields

Project:Composite Layout
Version:6.x-1.0-beta7
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

    * warning: preg_match() expects parameter 2 to be string, array given in /home/nicholas/workspace/campaign/includes/bootstrap.inc on line 771.
    * warning: Invalid argument supplied for foreach() in /home/nicholas/workspace/campaign/sites/all/modules/composite/modules/content/composite_cck.module on line 194.

This error is seen when going to Zones tab, here are the steps to reproduce:

  1. Add a new content type (content type A)
  2. Within Content type A: Add a select field, add a text field, and add an image field (from imagefield module)
  3. Add another content type (content type B)
  4. Within Content type B: Add a flexifield (using flexifield module) that pulls in content type A.

You will now see this error.

You will also find an extra field that should not be under the fields section. It looks to be an array being used as a string. Field value: Metrics [0] (my field was called metrics).

Comments

#1

Hah, have I heard of flexifield.module before? Nope. Do I know what it does? Nope.

Anyway ...

It's a bit strange. The paragraph of code is:

  if (is_array($field_type['formatters'])) {
    foreach ($field_type['formatters'] as $formatter_name => $formatter_info) {
      $formatter_options[$formatter_name] = $formatter_info['label'];
    }
    $formatter_options['hidden'] = t('<Hidden>');
  }

but I explicitly check $field_type['formatters'] is an array before calling foreach, so it shouldn't be complaining afterwards ... Not sure.

I think I'll wait until flexifield hits beta or RC before looking at this in detail.

#2

OK, understood that you want to wait, but I kind of doubt that much of the core implementation will be changing before an RC. That is since a number of large sites have already started using it, and the developer seems to be aware of that. The odd thing seems to be that it is finding, I believe, filefields within the flexifields. Hence the Field value: Metrics [0] I mentioned in my first post. The issue only occurs upon adding file/imagefields within the flexifields.

Thanks for the response and I look forward to a resolution. If I find a solution then I will post a patch.

#3

Status:active» fixed

Hi,

I have committed a fix.

If you'd like to hand patch your system, do the following:

In the file .../composite/modules/content/composite_cck.module, replace the function _composite_cck_preview_element() with the following definition:

function _composite_cck_preview_element($element) {
  if (isset($element['value'])) {
    if (is_numeric($element['value'])) {
      return check_plain($element['value']);
    }
    else if (is_string($element['value'])) {
      if (strlen($element['value']) < 40) {
        return check_plain($element['value']);
      }
      else {
       return check_plain(substr($element['value'], 0, 37)) .'...';
      }
    }
  }
  else if (isset($element['nid'])) {
    $data = db_fetch_object(db_query("SELECT nid, title FROM {node} WHERE nid = %d", $element['nid']));
    if (!empty($data->nid)) {
      return l($data->title, "node/$data->nid");
    }
  }
  // File reference
  else if (isset($element['fid'])) {
    return l($element['filename'], $element['filepath']);
  }
  else if (isset($element['uid'])) {
    $data = db_fetch_object(db_query("SELECT uid, name FROM {users} WHERE uid = %d", $element['uid']));
    if (!empty($data->uid)) {
      return l($data->name, "user/$data->uid");
    }
  }
}

The issue arises only if you have a multi-valued field of type flexifield. In the zones tabs of a composite enabled node, Composite Layout tries to preview the values of individual fields. Problem is, the value of a flexifield is an array, and this causes some downstream functions (in bootstrap.inc) to choke because they are expecting a string, or something convertable to a string.

The fix tests for this, and does not attempt a preview if the field value is an array.

PS: Field value: Metrics [0] is the first value of the Metrics multi-valued field. That is actually operating as intended.

If you still have issues with this, please re-open this thread and let me know.

Thanks.

#4

Wow, thanks for the fast work on this. Well the previous error is fixed, but there is now a new error:
warning: Invalid argument supplied for foreach() in /home/nicholas/workspace/campaign2/sites/all/modules/composite/modules/content/composite_cck.module on line 194.

I can only guess that something is getting setn to that function in the wrong form.

Thanks again.

#5

Title:Bug in Handling complex flexifields» Bug in Handling filefields within multivalued flexifields
Status:fixed» needs work

I feel this issues needs a title change.

#6

Status:needs work» fixed

Ah, the warning message in comment #4 of this thread is actually an old bug.

See comment #4 of #465762: After upgrade 6.11->6.12: Getting errors when visiting /composite_zones and changing zones for a fix.

Or you can wait for the next release of Composite Layout (whenever that will be) which will automatically include this fix.

#7

That does it. Thanks. Sorry I hadn't noticed that warning was unrelated to this bug. Definitely fixed.

#8

Status:fixed» closed (fixed)

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