wrav / oembed

A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.
MIT License
37 stars 37 forks source link

Exception: Undefined property: FallbackAdapter::$height #85

Closed michaelhue closed 11 months ago

michaelhue commented 3 years ago

Since upgrading to the latest 1.3.11 version my client sometimes gets this error:

ErrorException: Warning: Undefined property: wrav\oembed\adapters\FallbackAdapter::$height

The twig code:

{% if item.oembed and item.oembed.media -%}
  {% set media = item.oembed.media %}
  {% set props = {
    url: media.url,
    image: media.image,
    ratio: (media.height ?? 9) / (media.width ?? 16),
    providerName: media.providerName,
    code: item.oembed.render()
  } %}

  {{ tag('div', {
    class: 'embed-consent',
    data: { props: props|json_encode }
  }) }}
{% endif %}

The full stack trace:

ErrorException: Warning: Undefined property: wrav\oembed\adapters\FallbackAdapter::$height
#32 /var/www/virtual/lss/app/vendor/embed/embed/src/Adapters/Adapter.php(553): Embed\Adapters\Adapter::getHeight
#31 /var/www/virtual/lss/app/vendor/embed/embed/src/Adapters/Adapter.php(95): Embed\Adapters\Adapter::__get
#30 /var/www/virtual/lss/app/vendor/embed/embed/src/Adapters/Adapter.php(109): Embed\Adapters\Adapter::__isset
#29 /var/www/virtual/lss/app/vendor/twig/twig/src/Extension/CoreExtension.php(1422): twig_get_attribute
#28 /var/www/virtual/lss/app/vendor/craftcms/cms/src/helpers/Template.php(106): craft\helpers\Template::attribute
#27 /var/www/virtual/lss/app/storage/runtime/compiled_templates/b2/b2d0f1e4a52ea4ebb592b64ab71284335ad0b45f6870baf8a4ec6827c82ac713.php(323): __TwigTemplate_8230948ea057d5169d846cf184395251b451d15bf335cdfe4d32cdfdc3b6c28d::doDisplay
#26 /var/www/virtual/lss/app/vendor/twig/twig/src/Template.php(405): Twig\Template::displayWithErrorHandling
#25 /var/www/virtual/lss/app/vendor/twig/twig/src/Template.php(378): Twig\Template::display
#24 /var/www/virtual/lss/app/storage/runtime/compiled_templates/ee/ee3782bad6a09455dbf2d2bfeabb62ebbf90ca7af988988e84975ea2356b0e7b.php(200): __TwigTemplate_1c5c90cac28a0ae6100f0208a0a148ab9ea433dc54ddc0401118bc8e40dcbcee::block_content
#23 /var/www/virtual/lss/app/vendor/twig/twig/src/Template.php(182): Twig\Template::displayBlock
#22 /var/www/virtual/lss/app/storage/runtime/compiled_templates/42/42cc671aa0ea43f6a3a95d9cb19021f4046d242c63c88cd181726a4fde2107f7.php(106): __TwigTemplate_49cb5ee67ca94af0905e5c02e2797c7373a41b847c9ee023b0b6ebe151a08940::doDisplay
#21 /var/www/virtual/lss/app/vendor/twig/twig/src/Template.php(405): Twig\Template::displayWithErrorHandling
#20 /var/www/virtual/lss/app/vendor/twig/twig/src/Template.php(378): Twig\Template::display
#19 /var/www/virtual/lss/app/storage/runtime/compiled_templates/ee/ee3782bad6a09455dbf2d2bfeabb62ebbf90ca7af988988e84975ea2356b0e7b.php(43): __TwigTemplate_1c5c90cac28a0ae6100f0208a0a148ab9ea433dc54ddc0401118bc8e40dcbcee::doDisplay
#18 /var/www/virtual/lss/app/vendor/twig/twig/src/Template.php(405): Twig\Template::displayWithErrorHandling
#17 /var/www/virtual/lss/app/vendor/twig/twig/src/Template.php(378): Twig\Template::display
#16 /var/www/virtual/lss/app/vendor/twig/twig/src/Template.php(390): Twig\Template::render
#15 /var/www/virtual/lss/app/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\TemplateWrapper::render
#14 /var/www/virtual/lss/app/vendor/twig/twig/src/Environment.php(318): Twig\Environment::render
#13 /var/www/virtual/lss/app/vendor/craftcms/cms/src/web/View.php(389): craft\web\View::renderTemplate
#12 /var/www/virtual/lss/app/vendor/craftcms/cms/src/web/View.php(450): craft\web\View::renderPageTemplate
#11 /var/www/virtual/lss/app/vendor/craftcms/cms/src/web/Controller.php(257): craft\web\Controller::renderTemplate
#10 /var/www/virtual/lss/app/vendor/craftcms/cms/src/controllers/TemplatesController.php(100): craft\controllers\TemplatesController::actionRender
#9 [internal](0): call_user_func_array
#8 /var/www/virtual/lss/app/vendor/yiisoft/yii2/base/InlineAction.php(57): yii\base\InlineAction::runWithParams
#7 /var/www/virtual/lss/app/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\Controller::runAction
#6 /var/www/virtual/lss/app/vendor/craftcms/cms/src/web/Controller.php(190): craft\web\Controller::runAction
#5 /var/www/virtual/lss/app/vendor/yiisoft/yii2/base/Module.php(534): yii\base\Module::runAction
#4 /var/www/virtual/lss/app/vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application::runAction
#3 /var/www/virtual/lss/app/vendor/yiisoft/yii2/web/Application.php(104): yii\web\Application::handleRequest
#2 /var/www/virtual/lss/app/vendor/craftcms/cms/src/web/Application.php(263): craft\web\Application::handleRequest
#1 /var/www/virtual/lss/app/vendor/yiisoft/yii2/base/Application.php(392): yii\base\Application::run
#0 /index.php(21): null
sgtpenguin commented 2 years ago

I'm also getting this error using graphql.

sgtpenguin commented 2 years ago

Running into this again. Looks like it happens when the field is left empty and fallback adaptor isn't initializing width and height.

Inside src/adapters/FallbackAdapter.php set

$this->height = null;
$this->width = null;

inside init()

Seems to do the trick.

Here's the full edited file. Let me know if a PR is helpful.

<?php
/**
 * oEmbed plugin for Craft CMS 3.x
 *
 * A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.
 *
 * @link      https://github.com/wrav
 * @copyright Copyright (c) 2017 reganlawton
 */

namespace wrav\oembed\adapters;

use Embed\Adapters\Adapter;
use Embed\Utils;

class FallbackAdapter extends Adapter
{
    protected function init()
    {
        $this->providers = [];
        $this->height = null;
        $this->width = null;
    }

    public function getCode()
    {
        if (!$this->url) {
            return Utils::iframe($this->url);
        }

        return null;
    }
}
sgtpenguin commented 2 years ago

Is there any way this fix can be added to the project? It's a bummer that graphql completely errors out if content editors did not enter an embed.

sgtpenguin commented 1 year ago

Finding my way back here after adding this plugin to another project. Any possibility of a fix here?

reganlawton commented 11 months ago

@sgtpenguin Is this still an issue? I believe this was resolved in v2.3.1 PR.

I'll close the issue unless there is an issue