A formatter that renders the video URL can be useful for passing to theme templates, indexing, or admin views.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

recrit created an issue. See original summary.

recrit’s picture

Status: Active » Needs review
StatusFileSize
new1.63 KB

The attached patch adds a field formatter video_embed_field_video_url.

sam152’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
  1. +++ b/src/Plugin/Field/FieldFormatter/VideoUrl.php
    @@ -0,0 +1,49 @@
    +class VideoUrl extends Video {
    

    Do we need to extend this?

  2. +++ b/src/Plugin/Field/FieldFormatter/VideoUrl.php
    @@ -0,0 +1,49 @@
    +        $autoplay = $this->currentUser->hasPermission('never autoplay videos') ? FALSE : $this->getSetting('autoplay');
    

    Why is this relevant?

  3. +++ b/src/Plugin/Field/FieldFormatter/VideoUrl.php
    @@ -0,0 +1,49 @@
    +        $embed_code = $provider->renderEmbedCode($this->getSetting('width'), $this->getSetting('height'), $autoplay);
    +        if (!empty($embed_code['#url']) && ($embed_url = Url::fromUri($embed_code['#url']))) {
    

    Why not just print $item->value? We cannot rely on #url being set, some providers might choose to return a different render array structure to render their videos.

  4. +++ b/src/Plugin/Field/FieldFormatter/VideoUrl.php
    @@ -0,0 +1,49 @@
    +        $element[$delta]['#cache']['contexts'][] = 'user.permissions';
    

    I don't think this is needed.

recrit’s picture

@Sam152:

1 - This was extended in order to get the render code from the plugin.
2 - Autoplay - To allow the plugin to return a url with the proper structure for autoplaying, Example: "?autoplay=1".
3 - The entered value != the url. The plugins extract the id and then create a url in their embed code.
4 - Needed for #2.

An alternative approach could be to add a method to the plugin interface for "getUrl()". Then this url formatter could use that to get the url.

sam152’s picture

Re: #3, what I'm saying is, the method is called renderEmbedCode, it doesn't enforce across all the providers who implement the interface that the renderable array returned will by type => video_embed_iframe, this is simply a convention the youtube/vimeo ones use currently.

brunodbo’s picture

The patch in #2 was outputting an incorrect url for me (https://www.youtube.com/embed/videoseries), without the video ID.

Attached patch simply outputs the $item->value, as suggested in #3, which I would expect from a 'Video URL' field formatter. Not sure if this a solid approach though (we may need to build the url in a different way).

sam152’s picture

Still NW for tests.

anybody’s picture

+1 for this, very important requirement!

krisrobinson’s picture

+1 for this, could it also be used to provide the thumbnail URL instead of the thumbnail image?

GenkiOne’s picture

Is this issue still alive ?
Because it would be very useful

anybody’s picture

-- Comment was incorrect sorry -- *deleted*

gijimmyj’s picture

+1 for this as well. It seems likely that you would want to get at the video url

anybody’s picture

@brunodbo, would you be so kind to reroll your patch and check why the tests fail? It would be nice to have this RTBC'd soon.

ConradFlashback’s picture

+1

brunodbo’s picture

Status: Needs work » Needs review

Queuing test bot.

brunodbo’s picture

Is the test that failed in #6 still relevant? It doesn't show up at https://www.drupal.org/node/1243930/qa anymore. In any case, I queued the patch in #6 for testing with the 'PHP 5.5 & MySQL 5.5, Drupal 8.7.x' test.

As far as I can tell from https://www.drupal.org/pift-ci-job/819115, the fail in #6 had to do with the usage of deprecated code elsewhere in the module, not related to the patch.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Well I think we can set this RTBC? patch is green now and we have good feedback!

peacog’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new735 bytes
new1.5 KB

Thank you very much for this patch. I've made a small modification to it to better support Youtube playlists. When the provider is a playlist, the url should link to the playlist page rather than to the first video in the playlist. This patch achieves that by simply changing the url from youtube.com/watch to youtube.com/playlist.

anybody’s picture

Thank you Peacog,

your patch looks good and works, but I can't get that str_replace, which seems a bit dirty to me. Can you provide a working example here? If I change watch to "playlist" in Youtube URLs, the URL is broken for me? What am I doing wrong?

Would be nice to push this forward!

anybody’s picture

Hi @Peacog,

could you perhaps provide a short example for my "str_replace" question in #18? It would be nice to move forward here, because this is a deserved feature for several users.

peacog’s picture

Hi @Anybody.

When you want to embed a playlist this module requires you to provide an url with the format https://www.youtube.com/watch?v=VIDEO_ID&list=PLAYLIST_ID, i.e. it includes the id of the first video as well as the id of the playlist itself. With urls of that format you can replace 'watch' with 'playlist'.

There is an alternative way to solve the playlist problem in #3028911: Provider does not support linking to playlist page. I haven't tried it myself but if it works it might be a better solution.

recrit’s picture

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Well I think we can set this RTBC now and hope for maintainer review?

sam152’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

With the advent of Media in core, the Video Embed Field module has moved to being minimally maintained. Only issues which assist in the migration to Media in core will be committed. To read more about this decision, please see: #3089599: Maintenance status for Video Embed Field now that media is in core.

anybody’s picture

Version: 8.x-2.x-dev » 3.0.x-dev
Status: Closed (won't fix) » Reviewed & tested by the community

I'd like to set this back to RTBC as this now has a 3.0.x branch, this still works perfectly and patch still applies. Can we please merge this into 3.0.x?

mably’s picture

Could we have an MR please?

anybody’s picture

@mably thanks for the super quick reply! Yes already on it, we'll post it here tomorrow! Probably @grevil will do it and finally check the implementation.

grevil made their first commit to this issue’s fork.

grevil’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Needs tests

Ok, I created the MR and made the code a bit prettier. Please review!

I am a bit unsure about the output array:

      $elements[$delta] = [
        '#markup' => $video_url->toString(),
        '#url' => $video_url,
      ];

looks a bit odd don't you think?

grevil’s picture

Note, that test failures are unrelated. The tests are simply not compatible with the newest PHPUnit version. We should fix that in a seperate issue.

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Re #30 that was already part of the first patch and has been reviewed, so I think it should be fine IMHO

Please link the test issue here, once created.

grevil’s picture

Done, tests fixed here: #3554816: Fix PHPUnit tests.

mably’s picture

Related issue has been merged.

anybody’s picture

Tests are also green here now! :)

  • mably committed b8fe8689 on 3.x authored by grevil
    [#2879932] feat: Provide a URL field formatter
    
mably’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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