Cms: Error on getIsLivePreview() in plugins

Created on 23 Jul 2020  路  4Comments  路  Source: craftcms/cms

Description

$this->request in Controller somehow becomes a string which causes getIsLivePreview() to error out when loading some plugins.

Error: Call to a member function getIsLivePreview() on string in /application/vendor/craftcms/cms/src/web/Controller.php:133
Stack trace:
#0 /application/vendor/yiisoft/yii2/base/Controller.php(178): craft\web\Controller->beforeAction(Object(yii\base\InlineAction))
#1 /application/vendor/craftcms/cms/src/web/Controller.php(181): yii\base\Controller->runAction('default-view', Array)
#2 /application/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('default-view', Array)
#3 /application/vendor/craftcms/cms/src/web/Application.php(295): yii\base\Module->runAction('calendar/settin...', Array)
#4 /application/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('calendar/settin...', Array)
#5 /application/vendor/craftcms/cms/src/web/Application.php(280): yii\web\Application->handleRequest(Object(craft\web\Request))
#6 /application/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#7 /application/web/index.php(61): yii\base\Application->run()
#8 {main}

Steps to reproduce

  1. Upgrade to 3.5.0-RC1.1
  2. Navigate to admin/calendar for solspace/calendar or admin/campaign/settings/general for putyourlightson/campaign

Additional info

  • Craft version: 3.5.0-RC1.1
  • PHP version: 7.4.2
  • Database driver & version: MySQL 5.7.26
  • Plugins & versions:
    -- Calendar | 3.0.9
    -- Campaign | 1.15.4
bug

Most helpful comment

(Will mention this to Solspace.)

All 4 comments

Actually wtf.. i did not know request can be a string.

https://www.yiiframework.com/doc/api/2.0/yii-base-controller#$request-detail
https://github.com/yiisoft/yii2/blob/master/framework/base/Controller.php#L72

@brandonkelly do you have any idea about this? The request should be loaded already into the controller, since beforeAction happens after init, right?

+1 Freeform 3.7.0

Issue, at least in Calendar鈥檚 settings case, is that the init() method is not calling parent::init(). With Yii components, any time you create an init() method, you should always call parent::init() before anything else.

https://github.com/solspace/craft3-calendar/blob/f7941705c4e0a54ff4d64d8af7207be55509b492/src/Controllers/SettingsController.php#L17-L22

Guessing this will generally be the culprit when this error comes up. There are other bugs that would come from not calling parent::init() as well though, like $allowAnonymous not getting normalized properly.

(Will mention this to Solspace.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

angrybrad picture angrybrad  路  3Comments

leigeber picture leigeber  路  3Comments

angrybrad picture angrybrad  路  3Comments

timkelty picture timkelty  路  3Comments

bitboxfw picture bitboxfw  路  3Comments