I have applied the patch in #792024: Form error after installing on drupal 7.0-alpha4 and everything seems to work. I can insert images and they get properly generated.

But after I enable Insert for a field, I get the following warning when editing the field, as well as viewing the nodes of that content type:

Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 104 of D:\wamp\www\d7\includes\entity.inc).

This happens with Drupal 7 alpha 6, I did not experience it in alpha 5. Something must have changed between the alphas causing this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

I've reproduced this problem but I've decided not to spend more time on Drupal 7 until it stabilizes. I'd be happy to review any patches you can submit, but I looked at this for an hour or so and couldn't find the reason easily.

rfay’s picture

Priority: Normal » Major

Confirmed: I have this also. Just enabling the insert widget on an imagefield seems to bring it on.

I don't blame you for waiting for D7 to stabilize :-) We're only 9 months into code freeze.

rfay’s picture

Title: Warning after enabling Insert for an image field in D7a6 » Warning after enabling Insert: Warning: array_flip(): Can only flip STRING and INTEGER values!
Version: 7.x-1.0-alpha1 » 7.x-1.x-dev
Priority: Major » Critical

As the "Send to text area" button is also missing, I assume that this is actually critical. Perhaps that's a different issue.

quicksketch’s picture

Status: Active » Postponed

I won't be working any more to fix D7 problems, but I'd be happy to apply any patches.

tsvenson’s picture

Priority: Critical » Normal

This error message has slightly changed in Drupal 7 beta 2:

Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 167 of [path]\includes\entity.inc).

Also, it does only seem to appear when you edit the field for the content type, it no longer shows up when you view or edit the nodes.

To be able to test this, you need the patch in #918958: file_directory_path is removed in D7, replaced with file_default_scheme.

florisla’s picture

I'm pretty new to this, but the array that cannot be flipped looks like this:

Array
(
    [0] => Array
        (
            [fid] => 0
            [upload_button] => Upload
            [remove_button] => Remove
            [upload] => 
        )

)

(not sure about the words 'Upload' and 'Remove'; they are in Dutch on my install ('Uploaden'/'Verwijderen').

mlncn’s picture

Issue tags: +undefined

Can't figure out where this is coming from– are we certain it's Insert causing this?

florisla’s picture

Not 100% sure in my case. Will double check on a clean D7 beta2 install.

florisla’s picture

Double checked and confirmed.

It starts occurring after insert has been enabled for an image field. And very strange: it keeps occurring even when insert is disabled for that field, and even when the insert module is disabled.

Steps I took to reproduce (which may contain superfluous steps):

  • Install Drupal 7 beta 2
  • Create a standard article
  • Set Number of values of field Image in content type Article to Unlimited
  • Create an article and upload two images to it. Include these images in the content as well trough IMG tags.
  • Allow the IMG tag in the filtered HTML text format.
  • Set Number of values of field Image in content type Article to Unlimited
  • Enable Insert module
  • Enable the Insert button for field Image in content type Article
  • fun and profit: the array_flip problem appears.

The $ids variable looks like this:

Array
(
    [0] => Array
        (
            [fid] => 0
            [upload_button] => Upload
            [remove_button] => Remove
            [upload] => 
        )
)
florisla’s picture

Title: Warning after enabling Insert: Warning: array_flip(): Can only flip STRING and INTEGER values! » Warning after enabhttp://drupal.org/node/850946ling Insert: Warning: array_flip(): Can only flip STRING and INTEGER values!

Investigating...

Stack trace looks like this:

array_flip (includes/entity.inc line 168)
load (includes/common.inc line 7145)
entity_load (includes/file.inc line 533)
file_load_multiple (includes/file.inc line 549)
file_load (modules/image/image.field.inc line 194)
image_field_prepare_view (modules/field/field.attach.inc line 331)
_field_invoke_multiple (modules/field/field.attach.inc line 1075)
field_attach_prepare_view (modules/node/node.module line 2492)
node_view_multiple (modules/node/node.module line 2522)
node_page_default ( line )
call_user_func_array (includes/menu.inc line 480)
menu_execute_active_handler (index.php line 22)
florisla’s picture

Also interesting to note: disabling the insert button on the field does not make the error go away (as mentioned in #9) unless you also change the 'Number of values' of the Image field from Unlimited to another value...

However, when the insert button is enabled, the error is there regardless of the value of 'Number of values' on the image field.

florisla’s picture

Title: Warning after enabhttp://drupal.org/node/850946ling Insert: Warning: array_flip(): Can only flip STRING and INTEGER values! » Warning after enabling Insert: Warning: array_flip(): Can only flip STRING and INTEGER values!
FileSize
759 bytes

Insert module apparently messes up the 'default image' configuration form for file fields.

With insert module enabled, the "Default image" settings' form elements no longer appear in the file field admin interface.

One of the side effects of the bug is that at image_field_prepare_view time, $field['settings']['default_image'] contains the form array and not the actual default_image string as would be expected.

This patch to core image field does not fix the bug, but merely works around the issue by checking if $field['settings']['default_image'] is indeed a string. So it prevents the array_flip() warning to occur.

Haven't found the cause of the bug though.

florisla’s picture

I think I have found the cause.

This fixes an 'early abort' return statement in that did not return the array, as (I think) it should.

After changing this, I see:

  • Insert works as before
  • The array_flip() error is gone
  • The missing 'Default image' settings' form elements are visible again in the image field admin interface.

PS: Please ignore the patch in #12 above; it is wrong! (value should not be a string, but an integer)

florisla’s picture

Status: Postponed » Needs review

Please apply #13 and check if it works in your case too.

tsvenson’s picture

Status: Needs review » Reviewed & tested by the community

@florisla

Confirmed, seems to do the trick. No more warnings, also checked the log and noting in there either.

Great work, seems this module is now working properly for Drupal 7 again.

okokokok’s picture

With patch in #13 the warning disappears but there was no "insert" button yet.
Then I tried disabling and re-enabling insert. Nothing yet.

However drush cc all did the trick and the button is there and working!

Thanks!

nadavoid’s picture

After applying the patch, I still get the warning message, but only on pages that don't have any images in an Insert enabled field. Using Drupal 7 rc2.

nadavoid’s picture

Status: Reviewed & tested by the community » Needs work

updating status

FiNeX’s picture

Isn't this a dup of bug http://drupal.org/node/937100 ?

JohnnyX’s picture

I get the following errors after set "Enabled insert styles" to colorbox...

    Notice: Undefined offset: 1 in colorbox_insert_content() (Zeile 451 von /<PATH>/sites/all/modules/colorbox/colorbox.module).
    Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (Zeile 178 von /<PATH>/includes/entity.inc).
    Notice: Undefined offset: 1 in colorbox_insert_content() (Zeile 451 von /<PATH>/sites/all/modules/colorbox/colorbox.module).
    Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (Zeile 178 von /<PATH>/includes/entity.inc).

But I don't know is it a insert or colorbox bug?

I try to use insert with image resize filter and colorbox to show image with original size

Jamie Holly’s picture

#20 I can confirm this and it's in insert. I have been fighting this for a few weeks and thought it was part of core (see http://drupal.org/node/937100). Finally I disabled insert and my problems went away (I don't use colorbox).

JohnnyX’s picture

I use patched insert, image resize filter and colorbox with my D7 test environment and finally it works!
There was a problem with colorbox. A new release fixed my problems. Testet with a new D7 installation...

But I don't use insert module colorbox integration! I use image resize filter to add colorbox feature to resized images. Works fine for me!

marcvangend’s picture

As I also mentioned in #937100: Image/file module passing form values to file_load_multiple(): I had this same problem ("Can only flip STRING and INTEGER values!") after installing Insert module on a site that started when D7 was in beta. The problem went away after updating to Drupal 7.0 and re-saving one of the image field settings (http://example.com/admin/structure/types/manage/[contenttype]/fields/[fi...). It's not really an upgrade path but I hope that helps anyone as a workaround.

ebremer’s picture

Applied #5 and #13. Working nicely now. :-)

ebremer’s picture

I take that back. I'm getting the error below when create a style in the "Image Styles" area. Also, the preview image of what a image style will do does not work. The problems go away once the Insert module is disabled.

Error reported:
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'image_style_generate' was given in menu_execute_active_handler() (line 501 of /www/mysite-7.0/includes/menu.inc).

ebremer’s picture

I did some more experiments and the errors crop up when I use the private file system. In changing the insert_menu() function to the below seems to be working for me now (with #5 & #13 applied as well). I'm still testing but so far, no errors.

function insert_menu() {
$items = array();

// Generate image derivatives of publicly available files.
// If clean URLs are disabled, image derivatives will always be served
// through the menu system.
// If clean URLs are enabled and the image derivative already exists,
// PHP will be bypassed.
$directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath();
$items[$directory_path . '/styles/%image_style'] = array(
'title' => 'Generate image style',
'page callback' => 'image_style_deliver',
'page arguments' => array(count(explode('/', $directory_path)) + 1),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
// Generate and deliver image derivatives of private files.
// These image derivatives are always delivered through the menu system.
$items['system/files/styles/%image_style'] = array(
'title' => 'Generate image style',
'page callback' => 'image_style_deliver',
'page arguments' => array(3),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);

return $items;
}

ebremer’s picture

FileSize
2.59 KB

Here is a patch that combines #5, #13, and my last post on the changes I did to function insert_menu(). I worked all day with it and finished migrating my site from D6-D7. No errors.

bryancasler’s picture

confirmed, #27 works for me

marcvangend’s picture

Looks good, but I couldn't test the patch myself because the problem has already gone away on my site. One nitpick:

+++ /www/ebremer-7.0/sites/all/modules/insert/insert.module	2011-01-16 00:23:49.000000000 -0500
@@ -21,26 +21,34 @@ require dirname(__FILE__) . '/includes/i
-  return $items;
+   return $items;

I think this is a mistake, no need for the extra space.

Powered by Dreditor.

enriquesl’s picture

I had the same problem ("Can only flip STRING and INTEGER values!") without the module Insert, and without using image field. I was using the theme "Corolla". The problem disappeared just switching to default D7 theme Bartik, and appear when switching again to Corolla (reloading the user page to reproduce the warning).

quicksketch’s picture

Status: Needs work » Fixed
FileSize
584 bytes

Thanks, the only part needed in this patch after these related issues is the return $element; line. These other patches address the remaining portions of the patch.

#941000: Insert breaks styled images in Drupal 7
#918958: file_directory_path is removed in D7, replaced with file_default_scheme

Status: Fixed » Closed (fixed)

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

bryancasler’s picture

Quicksketch, I'm still getting this error, but I can't confirm the cause. Was this patch committed to the D7 branch?

rfay’s picture

Issue tags: -undefined

#31 was committed January 20, 2011; commit 55cb1a42575552a80e9fe9046305de3b281528b9

There are lots of ways you could get this obscure error from Drupal, so you'll probably have to do some debugging to figure out where you're getting it from.

tsvenson’s picture

@animelion: Its also very likely it could be another module that causes this. Can you post the complete error message you get as well as let us know what other modules and versions you use with Insert.

rfay’s picture

@animelion, if you install Commerce Devel I believe it will give you a stack trace when this error occurs. It does not depend on commerce.

bryancasler’s picture

rfay, thanks so much. Quick question, how does it differ from your "Fatal" module? I'll report back here when I have something.

rfay’s picture

Fatal is for testing and creating errors. Commerce Devel is for solving errors you got some other way. Fatal was used as an easy way to create errors for Commerce Devel.

revu’s picture

I also have run into the same problem but it is with .mp4 file

Error message
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of www...\includes\entity.inc).

leisurman’s picture

Issue summary: View changes

My array_flip error can from a default image in a cck field that was missing inside the cck field after a d6 to d7 upgrade
https://www.drupal.org/node/1102570#comment-10978037

stellarvisions’s picture

I found this most helpful

https://www.drupal.org/node/2396677