Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
In some instances, the file
entry in the $variables
passed to template_preprocess_jw_player()
is an object. But the code assume it will always be an array. This happen when using JW Player as file formatter with File Entity.
Proposed resolution
Cast $variables['file']
as array at the beginning of template_preprocess_jw_player()
.
Original report by @username
Fatal error: Cannot use object of type stdClass as array in /drupal/sites/all/modules/contrib/jw_player/jw_player.module on line 382
$variables['file']
is an object. Patch below.
Comment | File | Size | Author |
---|---|---|---|
#5 | jw_player-cant_user_object_as_array-1980940-5.patch | 873 bytes | pbuyle |
#4 | jw_player-cant_use_object_as_array-1980940-4.patch | 512 bytes | jethro |
#1 | jw_player-cant_use_object_as_array-1980940-1.patch | 410 bytes | rrrob |
Comments
Comment #1
rrrob CreditAttribution: rrrob commentedComment #2
deggertsen CreditAttribution: deggertsen commentedPatch gave me opposite error:
Notice: Trying to get property of non-object in template_preprocess_jw_player() (line 382 of /public_html/d7/sites/all/modules/jw_player/jw_player.module).
It was working just fine before the patch.
Comment #3
hermes_costell CreditAttribution: hermes_costell commentedgoing to need something like this also at line 350 for
$id = $variables['file']['fid'] . $variables['preset'];
Comment #4
jethro CreditAttribution: jethro commentedThis works for me:
if(is_object($variables['file'])) {
$variables['file'] = (array) $variables['file'];
}
Comment #5
pbuyle CreditAttribution: pbuyle commentedThis happen to me when using JW Player as file formatter with File Entity.
Patch in #4 does not apply anymore. The attached patch is a reroll.
Comment #7
pbuyle CreditAttribution: pbuyle commented