I'm not sure how or why this is triggered, but the line 174 "$uri = media_parse_to_uri($video['link'][0]['@attributes']['href']);", is invalid at times. Triggered when clicking Apply when adding media to a field via YouTube tab.

Some of the videos in this loop were:


instead of arrays. Some arrays did not have the link delta structure either.

My workaround was:

        if (is_array($video['link']) && is_array($video['link'][0]) && !is_array($video['link'][0]['@attributes']['href'])) {
          $uri = media_parse_to_uri($video['link'][0]['@attributes']['href']);
Members fund testing for the Drupal project. Drupal Association Learn more


HongPong’s picture

Hmm... with this version of media youtube & media 7.x-2.0-unstable6 had this error when I tried to add youtube urls via what I thought was the correct method.

for "Enabled browser plugins" on the field, just setting Youtube does not work. I set "web" as well.

That provides 2 tabs, a youtube tab and a web tab in the field editor:

URL or Embed code *
Input a url or embed code from one of the listed providers.
Supported providers

The input web URL works right but trying to put the youtube id "ABC123abc123" type code in the youtube tab gives me the string offset error.

RobW’s picture

Title: Fatal error: Cannot use string offset as an array in sites/all/modules/media_youtube/media_youtube.module on line 175 » YouTube Tab: Fatal error: Cannot use string offset as array in sites/all/modules/media_youtube/media_youtube.module on line 175
realityloop’s picture

has there been any solutions found for this issue?

Countzero’s picture

Same here using latest dev and latest Media dev.

Also, the popup doesn't close itself but loads a page when I happen to make it work, and it never saves the info correctly.

rooby’s picture

Version: 7.x-2.0-alpha2 » 7.x-2.x-dev
Status: Active » Needs review
668 bytes

The problem is that the code is expecting an array of results, so if you only get a single result it fails (the response is structured differently for a single result).

This patch fixes it for me.

rooby’s picture

I still cannot actually select a video though.
I know I have successfully used this module in the past so there must be some regressions.

[EDIT] actually it is working now. I will keep an eye out for that issue returning again.

Countzero’s picture

The patch definitely solves he Youtube related bug. I can now paste a URL in the textfild, apply, and the video is added.

Still, the popup doesn't close correctly, but I guess it's not related.

Thanks a lot for this patch.

rooby’s picture

I have also seens that popup problem a few times, but currently it is working for me so I cannot investigate further right now.

That probably needs a new issue.

andypost’s picture

Got the same trouble with current (new stable) version.
Patch solves the critical bug

+++ b/media_youtube.moduleundefined
@@ -160,7 +160,10 @@ function media_youtube_add($form, &$form_state = array()) {
+    $videos = array_key_exists('id', $search['entry']) ? array($search['entry']) : $search['entry'];

use isset() against array functions

$videos = isset($search['entry']['id']) ? array($search['entry']) : $search['entry'];
aaron’s picture

Status: Needs review » Reviewed & tested by the community
657 bytes

Here is a patch with andypost's suggestion. Because it's so minor and works, I am setting the status to RTBC.

andypost’s picture

@aaron Thanx a lot! +1 to commit

rooby’s picture

Thanks Aaron. I was planning to do that but you saved me the time :)

Murz’s picture

This patch fix problem for me, +1 for commit.

sirtet’s picture

Status: Reviewed & tested by the community » Needs work

For me too, this fixes the fatal...

but what i see is that an url like
leads to no results.
only after cutting down to
it actually finds the video...

AdamGerthel’s picture

The patch didn't work at all for me. It solves the fatal error, but when picking a video, the "default" is a file link, not the video itself. It's also difficult to pick the video itself. After searching for the URL, I get thrown back to the upload tab. Going back to the internet tab shows the video I searched for, but the interface looks a bit weird. After selecting the video and then hitting submit I aren't able to pick any other display format than "default" which seems to be broken.

rooby’s picture

Status: Needs work » Reviewed & tested by the community

I think that this should be committed and new issues opened for all the other propblems people are seeing.

This issue is for

YouTube Tab: Fatal error: Cannot use string offset as array in sites/all/modules/media_youtube/media_youtube.module

The patch fixes that issue.

If you are seeing different issues than the title of this issue please open a new issue if there isn't one for that specific problem.

botris’s picture

+1 for commit

axe312’s picture

Patch is still applying to current dev after half a year, please commit it!

Murz’s picture

I have test this patch, it works well, please commit!

aaron’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

belvedere’s picture

+1 for patch working

galayant’s picture


Do you know if this patch (media_youtube-string-as-array-1668950-10.patch) is included in the 2.0-rc5 stable version?