Open gglnx opened 3 years ago
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.
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}
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)?
Just hit this as well.
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.
I don't have a reason for why this is happening, but I have a way to reproduce the error.
linkfield
within a matrix block (it can be a Matrix field with only one block type){% 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}
Getting the same issue as @dlindberg has described in the same setup.
I have the same issue as described by @dlindberg
Currently the developer toolbar doesn't load on my instance, because of an exception that's thrown by Linkfield: