Error when saving Matrix Field
Closed this issue · 2 comments
When attempting to save a Matrix Field I get the following error:
yii\base\ErrorException: foreach() argument must be of type array|object, string given in /var/www/html/vendor/ryssbowh/craft-activity/src/models/fieldHandlers/projectConfig/Transforms.php:21
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError(2, 'foreach() argum...', '/var/www/html/v...', 21)
#1 /var/www/html/vendor/ryssbowh/craft-activity/src/models/fieldHandlers/projectConfig/Transforms.php(21): craft\web\ErrorHandler->handleError(2, 'foreach() argum...', '/var/www/html/v...', 21)
#2 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): Ryssbowh\Activity\models\fieldHandlers\projectConfig\Transforms->init()
#3 /var/www/html/vendor/craftcms/cms/src/base/Model.php(78): yii\base\BaseObject->__construct(Array)
#4 /var/www/html/vendor/ryssbowh/craft-activity/src/traits/ProjectConfigFields.php(99): craft\base\Model->__construct(Array)
#5 /var/www/html/vendor/ryssbowh/craft-activity/src/traits/ProjectConfigFields.php(44): Ryssbowh\Activity\models\fieldHandlers\projectConfig\BlockFields->getHandler('settings.availa...', 'fields.{uid}.se...', Array, '')
#6 /var/www/html/vendor/ryssbowh/craft-activity/src/traits/ProjectConfigFields.php(62): Ryssbowh\Activity\models\fieldHandlers\projectConfig\BlockFields->getConfigValues('fields.{uid}', Array)
#7 /var/www/html/vendor/ryssbowh/craft-activity/src/models/fieldHandlers/projectConfig/BlockFields.php(82): Ryssbowh\Activity\models\fieldHandlers\projectConfig\BlockFields->getDirtyConfig('fields.{uid}', Array, Array)
#8 /var/www/html/vendor/ryssbowh/craft-activity/src/models/fieldHandlers/projectConfig/BlockFields.php(37): Ryssbowh\Activity\models\fieldHandlers\projectConfig\BlockFields->buildDirty(Array, Array)
#9 /var/www/html/vendor/ryssbowh/craft-activity/src/models/fieldHandlers/projectConfig/BlockFields.php(47): Ryssbowh\Activity\models\fieldHandlers\projectConfig\BlockFields->getDirty(Object(Ryssbowh\Activity\models\fieldHandlers\projectConfig\BlockFields))
#10 /var/www/html/vendor/ryssbowh/craft-activity/src/traits/ProjectConfigFields.php(70): Ryssbowh\Activity\models\fieldHandlers\projectConfig\BlockFields->isDirty(Object(Ryssbowh\Activity\models\fieldHandlers\projectConfig\BlockFields))
#11 /var/www/html/vendor/ryssbowh/craft-activity/src/base/recorders/ConfigModelRecorder.php(72): Ryssbowh\Activity\base\recorders\ProjectConfigRecorder->getDirtyConfig('matrixBlockType...', Array, Array)
#12 /var/www/html/vendor/ryssbowh/craft-activity/src/base/recorders/ConfigModelRecorder.php(24): Ryssbowh\Activity\base\recorders\ConfigModelRecorder->onChanged(Object(craft\events\ConfigEvent), 'matrixBlockSave...')
#13 /var/www/html/vendor/ryssbowh/craft-activity/src/recorders/MatrixBlocks.php(23): Ryssbowh\Activity\base\recorders\ConfigModelRecorder->onUpdate(Object(craft\events\ConfigEvent))
#14 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(1126): Ryssbowh\Activity\recorders\MatrixBlocks->Ryssbowh\Activity\recorders\{closure}(Object(craft\events\ConfigEvent))
#15 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#16 /var/www/html/vendor/yiisoft/yii2/base/Component.php(633): call_user_func(Array, Object(craft\events\ConfigEvent))
#17 /var/www/html/vendor/craftcms/cms/src/models/ProjectConfigData.php(82): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#18 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(516): craft\models\ProjectConfigData->commitChanges(Array, Array, 'matrixBlockType...', true, 'Save matrix blo...', true)
#19 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(476): craft\services\ProjectConfig->_setInternal('matrixBlockType...', Array, 'Save matrix blo...', true, false)
#20 /var/www/html/vendor/craftcms/cms/src/services/Matrix.php(240): craft\services\ProjectConfig->set('matrixBlockType...', Array, 'Save matrix blo...')
#21 /var/www/html/vendor/craftcms/cms/src/services/Matrix.php(583): craft\services\Matrix->saveBlockType(Object(craft\models\MatrixBlockType), false)
#22 /var/www/html/vendor/craftcms/cms/src/fields/Matrix.php(1030): craft\services\Matrix->saveSettings(Object(craft\fields\Matrix), false)
#23 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(1732): craft\fields\Matrix->afterSave(false)
#24 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(852): craft\services\Fields->applyFieldSave('47eeb68a-65d6-4...', Array, 'global')
#25 /var/www/html/vendor/craftcms/cms/src/controllers/FieldsController.php(341): craft\services\Fields->saveField(Object(craft\fields\Matrix))
#26 [internal function]: craft\controllers\FieldsController->actionSaveField()
#27 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#28 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#29 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('save-field', Array)
#30 /var/www/html/vendor/craftcms/cms/src/web/Application.php(304): yii\base\Module->runAction('fields/save-fie...', Array)
#31 /var/www/html/vendor/craftcms/cms/src/web/Application.php(607): craft\web\Application->runAction('fields/save-fie...', Array)
#32 /var/www/html/vendor/craftcms/cms/src/web/Application.php(283): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#33 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#34 /var/www/html/public/index.php(13): yii\base\Application->run()
#35 {main}
I was able to fix it by updating the init()
function in vendor/ryssbowh/craft-activity/src/models/fieldHandlers/projectConfig/Transforms.php
to:
public function init(): void
{
if ($this->value == '*') {
$this->fancyValue = \Craft::t('app', 'All');
} else {
$this->fancyValue = [];
if (is_iterable($this->value)) {
foreach ($this->value as $uid) {
$this->fancyValue[] = $this->getTransformName($uid);
}
$this->fancyValue = implode(', ', $this->fancyValue);
} else {
$this->fancyValue = $this->value;
}
}
}
If I had to guess, it might be UI Element Fields causing the issue? I didn't test further.
My Project
Application Info
PHP version 8.1.13
OS version Linux 5.15.49-linuxkit
Database driver & version MySQL 8.0.26
Image driver & version Imagick 3.7.0 (ImageMagick 6.9.11-60)
Craft edition & version Craft Pro 4.4.14
Yii version 2.0.47
Twig version v3.4.3
Guzzle version 7.7.0
Plugins
Amazon S3 2.0.3
Batch Actions 1.3.0
Blitz Recommendations 2.1.1
Block Usage 1.0.1
Button Box 4.2.0
Control Panel CSS 2.6.0
Control Panel JS 2.6.0
CP Field Inspect 1.4.4
Craft Geoman 1.0.1
Elements Panel 2.0.0
Embedded Assets 3.1.5
Enforce password 2.0.0
Feed Me 5.1.4
Field Manager 3.0.6
Formie 2.0.31
Hyper 1.1.7
Imager X 4.1.13
Maps v4.0.3
MatrixMate 2.1.3
Minify 4.0.0-beta.2
MJML 2.0.0
Optimise 4.0.28
Palette 3.1.5
Prism 3.0.0
Quick Field 2.0.4
Redactor 3.0.4
Retour 4.1.12
Simple 1.0.0
Smith 2.0.0
Super Table 3.0.9
Svg Picker 2.0.0-rc1
Table Maker 4.0.6
Twigpack 4.0.0-beta.4
Typed link field 2.1.5
Typogrify 4.0.1
UI Element fields 2.0.3
User Activity 2.3.11
Vite 4.0.6
Hi,
You must have a field defining empty image transforms config (like a redactor field) ?
I could reproduce the issue and fixed it in 2.3.12
Ah, that would make sense. We use Imager, and disable images in Redactor.
Thanks for the fix!