When using the Media library I get this error.. I'll try to provide more info.

Comments

slashrsm’s picture

brandonjp’s picture

Title: Fatal error: Cannot use object of type stdClass as array in ....../views/modules/field/views_handler_field_field.inc on line 621 » Fatal error: Cannot use object of type stdClass as array in modules/field/field.form.inc on line 193
Version: 7.x-1.x-dev » 7.x-1.0-beta3
Priority: Major » Normal

Pretty sure mine is different... but I was having "Fatal error: Cannot use object of type stdClass as array in modules/field/field.form.inc on line 193" - Still not sure how or why, but when I changed the content type to not Require Previewing, the issue has gone away.

JacobSingh’s picture

Is this when used in conjunction w/ views?

#1102500: Media reference fields sets #items to objects, not arrays like other modules..
Is that a dupe?

bc’s picture

I encounter this error with and without views modules enabled

i'm on 7.x-1.x dev for media module

i'll be investigating this bug more today!

steps to reproduce:

/node/add/whatevercontentype-that-has-media-field
select media
(in media modal dialog, Web: specify an embed url, or Upload: upload an image, and then Submit)
save or preview node
php error results
BUT
node data is saved (or kept in preview mode) without the media attached... but with the media in the gallery!

where does the error occur? i'll find out soon!

bc’s picture

aha!

bug occurs when saving a preview with 2 or more media fields

see http://drupalcode.org/project/media.git/blob/HEAD:/media.fields.inc#l258

258     // @todo $items[$delta] is sometimes a loaded media entity (an object)
259     //   rather than an array. This conflicts with Field API expectations (for
260     //   example, it results in fatal errors when previewing a node with a
261     //   multi-valued media field), so should be fixed. In the meantime, don't
262     //   assume that $current_value is an array.

i'm working on a solution now.

bc’s picture

i can't come up with a clean fix right now, but this core patch makes things usable for the time being (but is evil and makes other things less functional, barf)

diff --git a/modules/field/field.form.inc b/modules/field/field.form.inc
index f578281..acaee80 100644
--- a/modules/field/field.form.inc
+++ b/modules/field/field.form.inc
@@ -189,7 +189,8 @@ function field_multiple_value_form($field, $instance, $langcode, $items, &$form,
             '#title_display' => 'invisible',
              // Note: this 'delta' is the FAPI 'weight' element's property.
             '#delta' => $max,
-            '#default_value' => isset($items[$delta]['_weight']) ? $items[$delta]['_weight'] : $delta,
+            //'#default_value' => isset($items[$delta]['_weight']) ? $items[$delta]['_weight'] : $delta,
+            '#default_value' => $delta,
             '#weight' => 100,
           );
         }
sreynen’s picture

Priority: Normal » Major

I marked #1102500: Media reference fields sets #items to objects, not arrays like other modules.. as a duplicate.

The simplest steps to reproduce seem to be:

1) Add a multi-value media field to a content type.
2) Add at least one element to that field in a node.
3) Preview the node.
4) WSOD, PHP error in log.

I'm working on a patch now, which looks like it could be as simple as converting an object to an array.

sreynen’s picture

I changed this to "major" priority, because the priority definition for "major" sounds like it's using this issue as the example, i.e. "a PHP error which is only triggered under rare circumstances or which affects only a small percentage of all users."

sreynen’s picture

Status: Active » Needs review
StatusFileSize
new560 bytes

This incredibly simple patch appears to fix it without causing any new problems.

Status: Needs review » Needs work

The last submitted patch, multivalue_error-1064502-9.patch, failed testing.

sreynen’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Status: Needs work » Needs review

Patch is against dev.

sreynen’s picture

#9: multivalue_error-1064502-9.patch queued for re-testing.

JacobSingh’s picture

StatusFileSize
new3.17 KB

The above patch doesn't catch all the errors that this change causes. This patch isn't perfect either, but it does seem to do the casting w/o causing a bunch of warnings and notices.

bc’s picture

#13: 1064502_multivalue_preview.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1064502_multivalue_preview.patch, failed testing.

bc’s picture

Status: Needs work » Needs review
StatusFileSize
new1.34 KB

patch patched for recent refactor

effulgentsia’s picture

I agree with this approach. It breaks BC for any module that implements its own media field formatter, but one that's easy to fix, and I don't think there's very many of those, and there's already recently introduced BC-breakage, so now's probably a good time to do this.

Marked #1005642: $items[$delta] is sometimes an object when Field API requires array. Causes WSOD when previewing multi-valued media field. a duplicate.

Any other reviews / testing results to report on #16?

@bc: if you're up for it, please resubmit the patch, with the inclusion of removing code comments near the affected lines that are made unnecessary. Thanks.

bc’s picture

StatusFileSize
new1.58 KB

removed irrelevant comments from patch, re #17

effulgentsia’s picture

Status: Needs review » Fixed

Thanks. Committed to 7.x-1.x. #18 missed another @todo that could be removed, but I included that in the commit: http://drupalcode.org/project/media.git/commitdiff/18a2777?hp=392e17bccc....

See #17 and Media project page for warnings about updating to a Media dev snapshot post-beta4. I'll release a beta5 when downstream projects have had a chance to update their code accordingly.

trillex’s picture

Thanks for the new dev, but since I started using it, this happens everytime I try to enter a node with a media image:

Fatal error: Call to undefined function file_view_multiple() in /sites/all/modules/media/includes/media.fields.inc on line 169

effulgentsia’s picture

After updating to the new code, did you run update.php?

trillex’s picture

I had not. My bad. Carry on. :)

Status: Fixed » Closed (fixed)

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

golubovicm’s picture

Status: Active » Closed (fixed)

I got similar error here, it says:

Fatal error: Cannot use object of type stdClass as array in .../www/sites/all/modules/media/includes/media.fields.inc on line 392

This error appears when I try to save node that contains mm field, i.e. I got node $mm and
node_save($mm);

causes this, but not always!

When mine mm node is shown and I try to save it (I got some counter field inside) it trows error.

I also got some other content type which got node reference and "points" to multimedia node.

When that other kind of node is shows, and then I read from it mm nid load mm node and save it - it works well?!?

So, when node that have mm field is shown error appears, and when it's not, but mm node nid is calculated then there are no errors?!?

Another thing is that in "same" situation multimedia node looks different:
So, if $mm is node with multimedia field and $field_files is mm field this:

$mm->field_files['und'][$i]

is sometime object and sometime array, depends on that is multimedia node displayed or not.

This "patch" fixed problem of reading field for me:

if (is_object($mm->field_files['und'][$i])){
$file_thumb = file_load($mm->field_files['und'][$i]->fid);
}else{
$file_thumb = file_load($mm->field_files['und'][$i]['fid']);
}

, but I can't still save node.

Guys, please fix this.

Milan

golubovicm’s picture

Status: Closed (fixed) » Active

P.S. I re-activated this issue, because I think it's some deeper node/array mistake. Probably some function that executes when node is displayed messes up something.

oierbravo’s picture

Status: Closed (fixed) » Needs review

#13: 1064502_multivalue_preview.patch queued for re-testing.

brsgnsbe’s picture

#9: multivalue_error-1064502-9.patch queued for re-testing.

robeano’s picture

Status: Needs review » Fixed

I'm not seeing any errors when running the latest 7.x-1.x version of Media module. I'm setting this back to Fixed. A new issue with specific errors should be created if people continue to have problems with Media and previewing nodes.

Status: Fixed » Closed (fixed)

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