spicywebau / craft-embedded-assets

Manage YouTube videos, Instagram photos and more as first class assets in Craft CMS
MIT License
171 stars 36 forks source link

I've added a public YouTube video and it causes an error when using getVideoCode #144

Closed johnwbaxter closed 4 years ago

johnwbaxter commented 4 years ago

Description

I've added a public YouTube video and it causes an error. Stacktrace below

2020-09-08 03:55:34 [-][1][fc8dc285d7e16a50418e763a3acdc749][error][TypeError] TypeError: Argument 1 passed to craft\helpers\Template::raw() must be of the type string, null given, called in /home/xxxxxxxx/vendor/spicyweb/craft-embedded-assets/src/models/EmbeddedAsset.php on line 253 and defined in /home/xxxxxxxx/vendor/craftcms/cms/src/helpers/Template.php:129
Stack trace:
#0 /home/xxxxxxxx/vendor/spicyweb/craft-embedded-assets/src/models/EmbeddedAsset.php(253): craft\helpers\Template::raw(NULL)
#1 /home/xxxxxxxx/vendor/twig/twig/src/Extension/CoreExtension.php(1499): spicyweb\embeddedassets\models\EmbeddedAsset->getVideoCode(Array)
#2 /home/xxxxxxxx/vendor/craftcms/cms/src/helpers/Template.php(92): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(spicyweb\embeddedassets\models\EmbeddedAsset), 'getVideoCode', Array, 'method', false, false)
#3 /home/xxxxxxxx/storage/runtime/compiled_templates/c4/c4473b7085b24a1b987b6fb9c179b961bfd1cac1ece642410dddfd24775e1c1b.php(50): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(spicyweb\embeddedassets\models\EmbeddedAsset), 'getVideoCode', Array, 'method')
#4 /home/xxxxxxxx/vendor/twig/twig/src/Template.php(407): __TwigTemplate_f886992587910636cf328ca872589523fee667e5625a1df0d4afb1d041d1fe28->doDisplay(Array, Array)
#5 /home/xxxxxxxx/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#6 /home/xxxxxxxx/storage/runtime/compiled_templates/9f/9ff9cb019db9e52aa081a57e9a0ae55b9aa951aa0479595febc3ea5a3df1872c.php(122): Twig\Template->display(Array)
#7 /home/xxxxxxxx/vendor/twig/twig/src/Template.php(184): __TwigTemplate_e3e91219249674fefe400ce5ff0b603f9cb249ddd8228fba50435eb855d5a5a9->block_content(Array, Array)
#8 /home/xxxxxxxx/storage/runtime/compiled_templates/2e/2e32a160d8fb81c3b50948d52172fb404e14c32fe5f4fd19341c6466629f482d.php(122): Twig\Template->displayBlock('content', Array, Array)
#9 /home/xxxxxxxx/vendor/twig/twig/src/Template.php(407): __TwigTemplate_cf82797b4ba5aa48f448c305167ee75021d89968484df7cf6c121074567abbbe->doDisplay(Array, Array)
#10 /home/xxxxxxxx/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#11 /home/xxxxxxxx/storage/runtime/compiled_templates/9f/9ff9cb019db9e52aa081a57e9a0ae55b9aa951aa0479595febc3ea5a3df1872c.php(48): Twig\Template->display(Array, Array)
#12 /home/xxxxxxxx/vendor/twig/twig/src/Template.php(407): __TwigTemplate_e3e91219249674fefe400ce5ff0b603f9cb249ddd8228fba50435eb855d5a5a9->doDisplay(Array, Array)
#13 /home/xxxxxxxx/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#14 /home/xxxxxxxx/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#15 /home/xxxxxxxx/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#16 /home/xxxxxxxx/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#17 /home/xxxxxxxx/vendor/craftcms/cms/src/web/View.php(391): Twig\Environment->render('_entrytypes/_ev...', Array)
#18 /home/xxxxxxxx/vendor/craftcms/cms/src/web/View.php(452): craft\web\View->renderTemplate('_entrytypes/_ev...', Array)
#19 /home/xxxxxxxx/vendor/craftcms/cms/src/web/Controller.php(243): craft\web\View->renderPageTemplate('_entrytypes/_ev...', Array, 'site')
#20 /home/xxxxxxxx/vendor/craftcms/cms/src/controllers/TemplatesController.php(95): craft\web\Controller->renderTemplate('_entrytypes/_ev...', Array)
#21 [internal function]: craft\controllers\TemplatesController->actionRender('_entrytypes/_ev...', Array)
#22 /home/xxxxxxxx/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#23 /home/xxxxxxxx/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)
#24 /home/xxxxxxxx/vendor/craftcms/cms/src/web/Controller.php(181): yii\base\Controller->runAction('render', Array)
#25 /home/xxxxxxxx/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('render', Array)
#26 /home/xxxxxxxx/vendor/craftcms/cms/src/web/Application.php(280): yii\base\Module->runAction('templates/rende...', Array)
#27 /home/xxxxxxxx/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#28 /home/xxxxxxxx/vendor/craftcms/cms/src/web/Application.php(265): yii\web\Application->handleRequest(Object(craft\web\Request))
#29 /home/xxxxxxxx/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#30 /home/xxxxxxxx/public_html/index.php(22): yii\base\Application->run()
#31 {main}

My template code is:

{% set vid = craft.embeddedAssets.get(block.video.one()) %} {{ vid.getVideoCode(['autoplay=0', 'controls=1', 'playsinline=0']) }}

I have tried vid.title and vid.url and they output the right info, so the embed has worked, but that method isn't.

Steps to reproduce

  1. Add Youtube video
  2. Output using getVideoCode method
  3. See issue

Other information

ttempleton commented 4 years ago

getVideoCode() should only fail if the embedded asset is not a video, or if it's not passed an array of parameters, which your template code does have, so at the moment I'm thinking it hasn't been detected as a video somehow. If you try vid.type, what does that output?

johnwbaxter commented 4 years ago

Ah! It shows as a link rather than a video. I think the user added a video with a youtube link that has a time set on it. It seems to have pulled in all the meta info correctly though!

ttempleton commented 4 years ago

It should still detect it as a video if the time is set (it should just discard the time), so it's definitely a bug if that isn't happening in a particular case.

If you select the video on the asset index page and use the Replace button to replace the video with its own URL, does that get detected as a video? If not, could you please let us know the video URL you're trying to add, either here or at plugins@spicyweb.com.au and we'll have a look at what's happening with it.

ttempleton commented 4 years ago

Closing this issue now -- hopefully you've sorted everything out, but if the issue persists, please let us know the previously-requested information and we'll reopen the issue.

siffring commented 4 years ago

@ttempleton I'm having a similar issue where a YouTube video is being detected as type=link.

Here's the YouTube URL: https://www.youtube.com/watch?v=bT0YpOmk8NA

I have tried adding it as a new asset a few times and get the same thing.

We're on version 2.4.2 with Craft 3.5.13.2.

johnwbaxter commented 4 years ago

@siffring @ttempleton Hey both, I forgot to update this! I found the reason it was doing this was because the video was configured in YouTube to not be allowed to be embedded on other websites. So Jason, check the settings on that YouTube video!!

siffring commented 4 years ago

Ah! It looks like that is the case here too! Not sure if that's something the plugin can check for or not. Thanks for the info!

johnwbaxter commented 4 years ago

No worries!!!