Strange behaviors updating from `1.1.4`
DynamiteGoesBoom opened this issue · 8 comments
Describe the bug
So I received this message last month when attempting an upgrade from 1.1.4
to 1.1.5
:
Exception 'Error' with message 'Typed static property verbb\hyper\Hyper::$plugin must not be accessed before initialization'
I simply reverted back to 1.1.4
then decided I'd wait on upgrading it as I was a bit busy with other projects.
Today, I tried updating to 1.1.9
and although I no longer received that error, my field settings completely disappeared on the Entry where that standalone Hyper field was assigned to.
Steps to reproduce
- have a
target
Hyper field assigned to an entry type - upgrade to 1.1.9
- may see
target
field as empty
Craft CMS version
4.4.16
Plugin version
1.1.4
Multi-site?
No
Additional context
I was attempting during the initial install to migrate from LinkIt fields. So I'm not sure if something during that process affected the later issues i was having. So instead of messing with the failed migrations, I simply setup that one single target
field as a way to test out Hyper's capabilities before I decided to make the switch. FTR I'm not completely sold on Hyper > LinkIt (at least not yet) but maybe once I get through these items my mind could get made up.
I can invite you to our GitHub repo as this is quite the strange one to explain and likely next to impossible to recreate or get a solid handle on what is actually going on.
Thanks as always!
Likely related to #72 where something on your end is calling a Craft element before it's initialised. I added handling for this to prevent the error from showing, but it's unfortunately had the side effect of doing this to fields, so I'll be reverting that.
You should be able to determine which plugin is causing this early initialization of Craft in your log files (feel free to share them and I can help decipher them), and using the early release via composer require verbb/hyper:"dev-craft-4 as 1.1.9"
As for the Hyper > LinkIt migration, more than happy to hear any feedback you have to make things better (apart from this obvious hiccup).
I've also made improvements to the LinkIt migration since 1.1.4 as well.
Hmm I'm getting this error even after upgrading to 1.1.10
:
Exception 'Error' with message 'Typed static property verbb\hyper\Hyper::$plugin must not be accessed before initialization'
in /var/www/project/cms/vendor/verbb/hyper/src/fields/HyperField.php:399
Here's the full stack trace:
in /var/www/project/cms/vendor/verbb/hyper/src/fields/HyperField.php:399
Stack trace:
#0 /var/www/project/cms/vendor/yiisoft/yii2/base/Component.php(180): verbb\hyper\fields\HyperField->setLinkTypes(Array)
#1 /var/www/project/cms/vendor/yiisoft/yii2/BaseYii.php(558): yii\base\Component->__set('linkTypes', Array)
#2 /var/www/project/cms/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure(Object(verbb\hyper\fields\HyperField), Array)
#3 /var/www/project/cms/vendor/craftcms/cms/src/base/Model.php(78): yii\base\BaseObject->__construct(Array)
#4 /var/www/project/cms/vendor/verbb/hyper/src/fields/HyperField.php(75): craft\base\Model->__construct(Array)
#5 [internal function]: verbb\hyper\fields\HyperField->__construct(Array)
#6 /var/www/project/cms/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#7 /var/www/project/cms/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('verbb\\hyper\\fie...', Array, Array)
#8 /var/www/project/cms/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('verbb\\hyper\\fie...', Array, Array)
#9 /var/www/project/cms/vendor/craftcms/cms/src/Craft.php(54): yii\BaseYii::createObject(Array, Array)
#10 /var/www/project/cms/vendor/craftcms/cms/src/helpers/Component.php(143): Craft::createObject(Array)
#11 /var/www/project/cms/vendor/craftcms/cms/src/services/Fields.php(593): craft\helpers\Component::createComponent(Array, 'craft\\base\\Fiel...')
#12 /var/www/project/cms/vendor/craftcms/cms/src/services/Fields.php(618): craft\services\Fields->createField(Array)
#13 /var/www/project/cms/vendor/craftcms/cms/src/services/Fields.php(647): craft\services\Fields->_fields(NULL)
#14 /var/www/project/cms/vendor/craftcms/cms/src/elements/db/ElementQuery.php(2086): craft\services\Fields->getAllFields()
#15 /var/www/project/cms/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1393): craft\elements\db\ElementQuery->customFields()
#16 /var/www/project/cms/vendor/yiisoft/yii2/db/QueryBuilder.php(227): craft\elements\db\ElementQuery->prepare(Object(craft\db\mysql\QueryBuilder))
#17 /var/www/project/cms/vendor/yiisoft/yii2/db/Query.php(157): yii\db\QueryBuilder->build(Object(craft\elements\db\GlobalSetQuery))
#18 /var/www/project/cms/vendor/yiisoft/yii2/db/Query.php(249): yii\db\Query->createCommand(Object(craft\db\Connection))
#19 /var/www/project/cms/vendor/craftcms/cms/src/db/Query.php(247): yii\db\Query->all(NULL)
#20 /var/www/project/cms/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1567): craft\db\Query->all(NULL)
#21 /var/www/project/cms/vendor/craftcms/cms/src/services/Globals.php(551): craft\elements\db\ElementQuery->all()
#22 /var/www/project/cms/vendor/craftcms/cms/src/services/Globals.php(262): craft\services\Globals->_allSets(1)
#23 /var/www/project/cms/config/colour-swatches.php(27): craft\services\Globals->getSetByHandle('design')
#24 /var/www/project/cms/vendor/craftcms/cms/src/services/Config.php(289): include('/var/www/projec...')
#25 /var/www/project/cms/vendor/craftcms/cms/src/services/Config.php(281): craft\services\Config->_configFromFileInternal('/var/www/projec...')
#26 /var/www/project/cms/vendor/craftcms/cms/src/services/Plugins.php(928): craft\services\Config->getConfigFromFile('colour-swatches')
#27 /var/www/project/cms/vendor/craftcms/cms/src/services/Plugins.php(228): craft\services\Plugins->createPlugin('colour-swatches', Array)
#28 /var/www/project/cms/vendor/craftcms/cms/src/base/ApplicationTrait.php(1580): craft\services\Plugins->loadPlugins()
#29 /var/www/project/cms/vendor/craftcms/cms/src/console/Application.php(52): craft\console\Application->_postInit()
#30 /var/www/project/cms/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\console\Application->init()
#31 /var/www/project/cms/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct(Array)
#32 /var/www/project/cms/vendor/yiisoft/yii2/console/Application.php(89): yii\base\Application->__construct(Array)
#33 [internal function]: yii\console\Application->__construct(Array)
#34 /var/www/project/cms/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#35 /var/www/project/cms/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\console\\A...', Array, Array)
#36 /var/www/project/cms/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\console\\A...', Array, Array)
#37 /var/www/project/cms/vendor/craftcms/cms/src/Craft.php(54): yii\BaseYii::createObject(Array, Array)
#38 /var/www/project/cms/vendor/craftcms/cms/bootstrap/bootstrap.php(256): Craft::createObject(Array)
#39 /var/www/project/cms/vendor/craftcms/cms/bootstrap/console.php(40): require('/var/www/projec...')
#40 /var/www/project/cms/craft(12): require('/var/www/projec...')
#41 {main}
Hopefully this helps and thanks @engram-design 👍
So looks like there's something in config/colour-swatches.php
that references an element (a Global Set with the handle design
it seems), which I believe is fired off before Craft and Hyper has fully initialised.
From Brandon's response it looks like config files in general shouldn't access things about Craft until Craft is ready.
Hmm interesting. I was setting this in that CS config:
// Get the settings global set
$colors = Craft::$app->globals->getSetByHandle('design');
$primary = $colors->colorPrimary;
$secondary = $colors->colorSecondary;
$tertiary = $colors->colorTertiary;
$quaternary = $colors->colorQuaternary;
$white = $colors->colorWhite;
$black = $colors->colorBlack;
if (! empty($colors->colorPrimary))
{
$primary = $colors->colorPrimary->getHex();
}
How else can I get around that error?
I'm not sure if it's feasible to wrap things in a Craft::$app->onInit(function() {
call, but it's probably unlikely.
I'll see what I can do about this, as it's cropping up a bit more...
Thanks @engram-design as always you rock 🤘
Should be fixed this for the next release. To get this early run composer require verbb/hyper:"dev-craft-4 as 1.1.10"
@engram-design that appears to have corrected the issue, many thanks!