New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: YouTube shortlinks (youtu.be) support #1725

Closed
FrittenKeeZ opened this Issue Jan 16, 2018 · 0 comments

Comments

Projects
None yet
3 participants
@FrittenKeeZ

FrittenKeeZ commented Jan 16, 2018

As the title explains...

diff --git a/statamic/core/View/BaseModifiers.php b/statamic/core/View/BaseModifiers.php
index 08e8ecc..53c688a 100644
--- a/statamic/core/View/BaseModifiers.php
+++ b/statamic/core/View/BaseModifiers.php
@@ -2070,6 +2070,10 @@ class BaseModifiers extends Modifier
             return str_replace('watch?v=', 'embed/', $url);
         }

+        if (str_contains($url, 'youtu.be')) {
+            return str_replace('youtu.be', 'www.youtube.com/embed', $url);
+        }
+
         if (str_contains($url, 'vimeo')) {
             return str_replace('/vimeo.com', '/player.vimeo.com/video', $url);
         }
@@ -2085,7 +2089,7 @@ class BaseModifiers extends Modifier
      */
     public function isEmbeddable($url)
     {
-        return Str::contains($url, ['youtube', 'vimeo']);
+        return Str::contains($url, ['youtube', 'youtu.be', 'vimeo']);
     }

     // ------------------------------------
diff --git a/statamic/resources/js/components/fieldtypes/VideoFieldtype.vue b/statamic/resources/js/components/fieldtypes/VideoFieldtype.vue
index 32622ae..e9542dd 100644
--- a/statamic/resources/js/components/fieldtypes/VideoFieldtype.vue
+++ b/statamic/resources/js/components/fieldtypes/VideoFieldtype.vue
@@ -19,6 +19,10 @@ export default {
                 return this.data.replace('watch?v=', 'embed/');
             }

+            if (this.data.includes('youtu.be')) {
+                return this.data.replace('youtu.be', 'www.youtube.com/embed');
+            }
+
             if (this.data.includes('vimeo')) {
                 return this.data.replace('/vimeo.com', '/player.vimeo.com/video');
             }
@@ -27,7 +31,7 @@ export default {
         },

         isEmbeddable() {
-            return this.data.includes('youtube') || this.data.includes('vimeo');
+            return this.data.includes('youtube') || this.data.includes('youtu.be') || this.data.includes('vimeo');
         },

         isVideo() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment