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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rrrob’s picture

deggertsen’s picture

Patch 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.

hermes_costell’s picture

if(is_object($variables['file'])){
			$variables['config']['file'] = file_create_url($variables['file']->uri);
		}else{
			$variables['config']['file'] = file_create_url($variables['file']['uri']);
		}

going to need something like this also at line 350 for

$id = $variables['file']['fid'] . $variables['preset'];

jethro’s picture

Status: Active » Needs review
FileSize
512 bytes

This works for me:

if(is_object($variables['file'])) {
$variables['file'] = (array) $variables['file'];
}

pbuyle’s picture

Title: Cannot use object of type stdClass as array » Cannot use object of type stdClass as array in template_preprocess_jw_player()
Issue summary: View changes
FileSize
873 bytes

This 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.

  • mongolito404 committed 3658a94 on 7.x-2.x
    Issue #1980940: Cannot use object of type stdClass as array in...
pbuyle’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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