Hi,

I enabled the Embedded Inline Media module and tried to filter the video URLs provided by my own Media module (newly created). It didn't work, so naturally I assumed I was doing something stupid, but digging deeper I think there's a bug (probably a new one). Perhaps there has been a slight change to a hook the module was relying on?

Anyway, here's what I observe:

When a video URL that matches an enabled provider's hook_extract() is found, the _eminline_url_parse_full_links() function is fired to do the replacement of the URL with embed code.

At line 111, inside the _eminline_url_parse_full_links() function, you'll find this code:

  // Build our embed item.
  $item = emfield_parse_embed($field, $match[2], 'emvideo');
  // Check to make sure the provider that was found is an allowed provider.
  if ($field['providers'][$item['provider']]) {
    $item['data'] = (array)emfield_include_invoke('emvideo', $item['provider'], 'data', $field, $item);
  }
  else {
    return $match[0];
  }

The problem is the if statement. It assumes the array of providers is keyed with provider names, however, by dumping these variables to watchdog (and dpm) I have observed this is not the case. The $field['providers'] array in fact looks like this:

[providers] => Array ( 
  [0] => turner_cvp 
  [1] => youtube 
) 

So as you can see, if ($field['providers'][$item['provider']]) can never work. Instead, this module needs to do some sort of array search to find a provider. I can only assume the array structure for $field['providers'] has changed at some point recently and this used to work?

At first I thought maybe this was my fault, so I installed Media: YouTube to check, but it suffers the same problem. Nothing can or will be parsed, because the assumption that $field['providers'] is keyed with provider name is no longer correct.

I don't know whether to fix this module, fix Media: YouTube or if someone needs to fix the main Embedded Media Field module, but right now this is broken.

Thoughts?

Possible related issue: #947786: Inline embedding not working after Emfield.2.2 update

Perhaps it broke in 6.x-2.2? Was Embedded Inline Media properly tested with that release?

CommentFileSizeAuthor
#1 984060-providers_array_key_fix.patch769 bytesgreg.harvey

Comments

greg.harvey’s picture

Title: Don't enter required values when configuring input format & you are still allowed to save + it breaks $field['providers'] array. » No filters working because of providers array format
Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new769 bytes

DO NOT USE THIS PATCH! See below.

Here's a simple patch to kick things off. It works for me. Perhaps this is all we need to do?

Edit: Thinking further about this, if any providers are added to the array in the format Embedded Inline Media expects, they will be removed by this loop. I don't know if that could ever happen, but if it could, this might be better:

  // Convert $field['providers'] in to an array keyed by provider name, as required next.
  foreach ($field['providers'] as $key => $provider) {
    if (is_numeric($key)) {
      $field['providers'][$provider] = $provider;
      unset($field['providers'][$key]);
    }
  }

DO NOT USE THIS PATCH! See below.

greg.harvey’s picture

Title: No filters working because of providers array format » Don't enter required values when configuring input format & you are still allowed to save + it breaks $field['providers'] array.

Ahh, there is a bug, but it's not the bug I thought it was.

If you do not specify 'required' movie settings when configuring your input filter, then for some reason the $field['providers'] array looks like this:

[providers] => Array ( 
  [0] => turner_cvp 
  [1] => youtube 
) 

If you do specify settings, then the array is correctly formed, like this:

[providers] => Array ( 
  [turner_cvp] => turner_cvp 
  [youtube] => youtube 
) 

The PHP code above will catch the problem (that is *not* the patch, but the code in the post) - however the real solution is to enforce the settings somehow or provide defaults drawn from the provider settings pages.

No defaults in input format config == bad array format. <- this is the bug!

greg.harvey’s picture

Priority: Major » Normal

Oh, and down-grading. It's not as bad as I thought.

grill’s picture

Title: No filters working because of providers array format » Don't enter required values when configuring input format & you are still allowed to save + it breaks $field['providers'] array.
Priority: Major » Normal
Status: Needs review » Active

What about substituting

if ($field['providers'][$item['provider']]) {

by

  if ($field['providers'][$item['provider']] or in_array($item['provider'], $field['providers'])) {

?
The in_array($item['provider'], $field['providers']) condition part, gets around the bug.

What does it mean in #2: "If you do not specify 'required' movie settings when configuring your input filter"? I have some settings in the input filter but i'm getting the error as well!

Manu