verbb / craft-videoembedder

MIT License
17 stars 14 forks source link

Template error when using link that doesn't allow embedding #5

Closed michtio closed 6 years ago

michtio commented 6 years ago

If user uses a link where embedding is disabled (eg. https://www.youtube.com/watch?v=P_qRH_SkJEM) the Craft Plugin throws an unrecoverable error:

Return value of mikestecker\videoembedder\services\VideoEmbedderService::embed() must be of the type string, null returned

Since we don't always have control over what a user posts, this error should be catched and mentioned that there is no embedding allowed, or at least the null should be able to covered in the twig template.

mikestecker commented 6 years ago

@michtio thanks for reporting this. I'll work on some sort of error handling for this case. I'm thinking it simply shouldn't output anything? That, or I could have it spit out a message letting you know the URL doesn't support embedding?

mikestecker commented 6 years ago

@michtio I haven't pushed out this release yet but I added a catch for when the URL doesn't return a result, either that there's no video at the URL or embedding is disabled.

You'll want to check to make sure the plugin returns a valid result as well:

{% set embed = craft.videoEmbedder.embed(videoUrl, {autoplay: 1, rel: 0, theme: 'dark'}) %}

{% if embed | length %}
    your code here
{% endif %}