craft-linkfield icon indicating copy to clipboard operation
craft-linkfield copied to clipboard

Exception on Developer Toolbar

Open gglnx opened this issue 3 years ago • 7 comments

Currently the developer toolbar doesn't load on my instance, because of an exception that's thrown by Linkfield:

yii\base\ErrorException: Trying to get property 'customTextRequired' of non-object in vendor/sebastianlenz/linkfield/src/models/Link.php:400
Stack trace:
#0 vendor/craftcms/cms/src/web/ErrorHandler.php(77): yii\base\ErrorHandler->handleError(8, 'Trying to get p...', '/var/www/client...', 400)
#1 vendor/sebastianlenz/linkfield/src/models/Link.php(400): craft\web\ErrorHandler->handleError(8, 'Trying to get p...', '/var/www/client...', 400, Array)
#2 vendor/sebastianlenz/linkfield/src/models/element/ElementLink.php(175): lenz\linkfield\models\Link->rules()
#3 vendor/yiisoft/yii2/base/Model.php(465): lenz\linkfield\models\element\ElementLink->rules()
#4 vendor/yiisoft/yii2/base/Model.php(421): yii\base\Model->createValidators()
#5 vendor/yiisoft/yii2/base/Model.php(190): yii\base\Model->getValidators()
#6 vendor/yiisoft/yii2/base/Model.php(796): yii\base\Model->scenarios()
#7 vendor/yiisoft/yii2/base/Model.php(740): yii\base\Model->safeAttributes()
#8 vendor/sebastianlenz/craft-utils/src/foreignField/ForeignFieldModel.php(159): yii\base\Model->setAttributes(Array)
#9 vendor/sebastianlenz/linkfield/src/models/Link.php(439): lenz\craft\utils\foreignField\ForeignFieldModel->setSerializedData(Array)
#10 vendor/sebastianlenz/craft-utils/src/foreignField/ForeignFieldModel.php(112): lenz\linkfield\models\Link->setSerializedData(Array)
#11 [internal function]: lenz\craft\utils\foreignField\ForeignFieldModel->unserialize(Array)
#12 vendor/opis/closure/functions.php(36): unserialize('a:15:{s:7:"flas...')
#13 vendor/yiisoft/yii2-debug/src/controllers/DefaultController.php(218): Opis\Closure\unserialize('a:15:{s:7:"flas...')
#14 vendor/yiisoft/yii2-debug/src/controllers/DefaultController.php(140): yii\debug\controllers\DefaultController->loadData('6072deb113928', 5)
#15 [internal function]: yii\debug\controllers\DefaultController->actionToolbar('6072deb113928')
#16 vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#17 vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#18 vendor/yiisoft/yii2/base/Module.php(534): yii\base\Controller->runAction('toolbar', Array)
#19 vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction('debug/default/t...', Array)
#20 vendor/craftcms/cms/src/web/Application.php(577): craft\web\Application->runAction('debug/default/t...', Array)
#21 vendor/craftcms/cms/src/web/Application.php(253): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#22 vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#23 web/index.php(33): yii\base\Application->run()
#24 {main}

gglnx avatar Apr 11 '21 11:04 gglnx

Hi @gglnx, thanks for reporting this. It seems like the link field runs into an issue when trying to load a serialized model, I've created a patch that should fix this.

sebastian-lenz avatar Apr 14 '21 20:04 sebastian-lenz

I've checked it, but now I'm getting a new error:

yii\base\ErrorException: Trying to get property 'customTextMaxLength' of non-object in vendor/sebastianlenz/linkfield/src/models/Link.php:404
Stack trace:
#0 vendor/craftcms/cms/src/web/ErrorHandler.php(77): yii\base\ErrorHandler->handleError(8, 'Trying to get p...', '/Users/dennis/P...', 404)
#1 vendor/sebastianlenz/linkfield/src/models/Link.php(404): craft\web\ErrorHandler->handleError(8, 'Trying to get p...', '/Users/dennis/P...', 404, Array)
#2 vendor/sebastianlenz/linkfield/src/models/element/ElementLink.php(175): lenz\linkfield\models\Link->rules()
#3 vendor/yiisoft/yii2/base/Model.php(465): lenz\linkfield\models\element\ElementLink->rules()
#4 vendor/yiisoft/yii2/base/Model.php(421): yii\base\Model->createValidators()
#5 vendor/yiisoft/yii2/base/Model.php(190): yii\base\Model->getValidators()
#6 vendor/yiisoft/yii2/base/Model.php(796): yii\base\Model->scenarios()
#7 vendor/yiisoft/yii2/base/Model.php(740): yii\base\Model->safeAttributes()
#8 vendor/sebastianlenz/craft-utils/src/foreignField/ForeignFieldModel.php(159): yii\base\Model->setAttributes(Array)
#9 vendor/sebastianlenz/linkfield/src/models/Link.php(439): lenz\craft\utils\foreignField\ForeignFieldModel->setSerializedData(Array)
#10 vendor/sebastianlenz/craft-utils/src/foreignField/ForeignFieldModel.php(112): lenz\linkfield\models\Link->setSerializedData(Array)
#11 [internal function]: lenz\craft\utils\foreignField\ForeignFieldModel->unserialize(Array)
#12 vendor/opis/closure/functions.php(36): unserialize('a:15:{s:7:"flas...')
#13 vendor/yiisoft/yii2-debug/src/controllers/DefaultController.php(218): Opis\Closure\unserialize('a:15:{s:7:"flas...')
#14 vendor/yiisoft/yii2-debug/src/controllers/DefaultController.php(140): yii\debug\controllers\DefaultController->loadData('607f321e0e486', 5)
#15 [internal function]: yii\debug\controllers\DefaultController->actionToolbar('607f321e0e486')
#16 vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#17 vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
#18 vendor/yiisoft/yii2/base/Module.php(534): yii\base\Controller->runAction('toolbar', Array)
#19 vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction('debug/default/t...', Array)
#20 vendor/craftcms/cms/src/web/Application.php(577): craft\web\Application->runAction('debug/default/t...', Array)
#21 vendor/craftcms/cms/src/web/Application.php(253): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#22 vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object(craft\web\Request))
#23 web/index.php(33): yii\base\Application->run()
#24 {main}

gglnx avatar Apr 20 '21 19:04 gglnx

Okay, I have to admit that I cannot reproduce the issue and that I've created the fix purely by looking at the code. So, after having another look, it seems like in your case an issue arrises here: https://github.com/sebastian-lenz/craft-utils/blob/master/src/foreignField/ForeignFieldModel.php#L149

When we deserialize a link model, the plugin tries to load the original field by fetching it from the field service via its id. In your case this must fail for some reason. What is your exact setup that causes that error, are you using any plugins that alter the behavior of fields in Craft (e.g. Neo)?

sebastian-lenz avatar May 05 '21 19:05 sebastian-lenz

Just hit this as well.

  • Setup is a regular matrix, no neo, not even super table. Only other fields are an asset and a plain text field.
  • Entry, Custom, Mail and URL enabled.
  • Default link text is set
  • Allow custom link text enabled.
  • Link target, both checked.
  • Everything else is default

The Linkfield was required and now isn't, only change I can think of.

Site is using the field in few places with a similar setup without the problem.

curtishenson avatar Sep 02 '21 00:09 curtishenson

I don't have a reason for why this is happening, but I have a way to reproduce the error.

  • Use linkfield within a matrix block (it can be a Matrix field with only one block type)
  • In your template eager load your matrix field:
{% do craft.app.elements.eagerLoadElements(className(entry), [entry], ['matrixField']) %}

stack trace:

Error: Call to a member function getEnabledLinkTypes() on null in /var/www/project/cms/vendor/sebastianlenz/linkfield/src/models/Link.php:439
Stack trace:
#0 /var/www/project/cms/vendor/sebastianlenz/craft-utils/src/foreignField/ForeignFieldModel.php(112): lenz\linkfield\models\Link->setSerializedData(Array)
#1 [internal function]: lenz\craft\utils\foreignField\ForeignFieldModel->unserialize(Array)
#2 /var/www/project/cms/vendor/opis/closure/functions.php(36): unserialize('a:15:{s:7:"flas...')
#3 /var/www/project/cms/vendor/yiisoft/yii2-debug/src/controllers/DefaultController.php(218): Opis\Closure\unserialize('a:15:{s:7:"flas...')
#4 /var/www/project/cms/vendor/yiisoft/yii2-debug/src/controllers/DefaultController.php(140): yii\debug\controllers\DefaultController->loadData('6227a26104098', 5)
#5 [internal function]: yii\debug\controllers\DefaultController->actionToolbar('6227a26104098')
#6 /var/www/project/cms/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /var/www/project/cms/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#8 /var/www/project/cms/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('toolbar', Array)
#9 /var/www/project/cms/vendor/craftcms/cms/src/web/Application.php(293): yii\base\Module->runAction('debug/default/t...', Array)
#10 /var/www/project/cms/vendor/craftcms/cms/src/web/Application.php(602): craft\web\Application->runAction('debug/default/t...', Array)
#11 /var/www/project/cms/vendor/craftcms/cms/src/web/Application.php(272): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#12 /var/www/project/cms/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#13 /var/www/project/cms/web/index.php(12): yii\base\Application->run()
#14 {main}

dlindberg avatar Mar 08 '22 18:03 dlindberg

Getting the same issue as @dlindberg has described in the same setup.

zizther avatar May 10 '22 10:05 zizther

I have the same issue as described by @dlindberg

mbruggenwirth avatar Jun 28 '22 12:06 mbruggenwirth