When a media object is transformed using the YouTubeProvider (during a form submission and saving of an entity for instance), it eventually calls the fixBinaryContent() method, which contains the following lines:
if (preg_match("/(?<=v(\=|\/))([-a-zA-Z0-9_]+)|(?<=youtu\.be\/)([-a-zA-Z0-9_]+)/", $media->getBinaryContent(), $matches)) {
$media->setBinaryContent($matches[2]);
}
The regex itself is fine, but the value passed to setBinaryContent is not always the correct one.
After some debugging, when the above example Browser URL is returned by $media->getBinaryContent(), the resulting preg_match() $matches variable looks like the following:
For a YouTube input field, a user could input the following types of URLs:
Browser URL - http://www.youtube.com/watch?v=J---aiyznGQ Share URL - http://youtu.be/J---aiyznGQ
When a media object is transformed using the YouTubeProvider (during a form submission and saving of an entity for instance), it eventually calls the fixBinaryContent() method, which contains the following lines:
The regex itself is fine, but the value passed to setBinaryContent is not always the correct one.
After some debugging, when the above example Browser URL is returned by $media->getBinaryContent(), the resulting preg_match() $matches variable looks like the following:
Browser URL values store the correct value as expected.
When the above example Share URL is returned by $media->getBinaryContent(), the resulting preg_match() $matches variable looks like the following:
So, when a Share URL is used, the media does not have a reference to the YouTube URL since fixBinaryContent only saves the $matches[2] value.
From the data, it looks like the setBinaryContent line could be changed to:
But maybe a safer way is to change it to something like: