This may be a problem with media module, but since commit 497dd75a81f544a0c67fc2c658b518f55756fc56, views pulling a multimedia asset field (from media module) cause a fatal error about using an object as an array. It's trying to access $item['raw'][$id] but $item['raw'] is an object, though I don't know enough to say that this is a fault of how media module is implementing its field api hooks. Changing it to $item['raw']->$id produces various "undefined index" errors.

Reverting the change from the above commit solves the problem, but this change was obviously made for a reason so I'm not sure how best to patch it.

Comments

merlinofchaos’s picture

What is $item['raw'] in this case? Typically it's an array from the table, and Views is trying to match the 'columns' to the 'raw' data so that users can use tokens.

I guess my assumption that this would always be the case is clearly false.

katbailey’s picture

StatusFileSize
new1.16 KB

Oh what the heck - adding a patch that just reverts the above change purely for my own drush make purposes ;-)

merlinofchaos’s picture

If you tell me that it's basically the db fetched as an object and not an array, then a bit of code that tests is_array vs is_object can alleviate that. Cross fingers!

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new814 bytes

Mh this is a 1to1 revert of #1109532: Image Field alt/title tokens do not get displayed
This will 100% not work because $item['raw'] will never be a scalar, so the tokens will not work.

raw can be everything. For example and stdClass, a real object or an array where for example 'value' exist.

So we really have to look at it, here is a patch.

katbailey’s picture

Yes, works for me - thanks!

dawehner’s picture

Okay what about use ['raw']->{$id} if it's an object.

katbailey’s picture

Hmm, well the keys of the columns array are fid, title and data, but ['raw']->title and ['raw']->data aren't set so I'm getting undefined property errors. I'll try and re-work the logic and see what I come up with...

katbailey’s picture

StatusFileSize
new2.72 KB

Would this fly? It works for my purposes without errors.

      if (isset($item['raw'])) {
        // If $item['raw'] is an array then we can use it as is; if it's an object
        // we cast it to an array; if it's neither, we can't use it.
        $raw = is_array($item['raw']) ? $item['raw'] :
                (is_object($item['raw']) ? (array)$item['raw'] : NULL);
      }
      if (isset($raw) && isset($raw[$id]) && is_scalar($raw[$id])) {
        $tokens['[' . $this->options['id'] . '-' . $id . ']'] = filter_xss_admin($raw[$id]);
      }

Patch attached

merlinofchaos’s picture

Status: Needs review » Fixed

That should do it, I think.

Committed, thank you!

Status: Fixed » Closed (fixed)

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