spicywebau / craft-content-templates

A Craft CMS plugin for providing content editors a starting point when creating entries
Other
4 stars 2 forks source link

Can't create new templates if Preparse Field also installed #2

Closed daltonrooney closed 1 year ago

daltonrooney commented 1 year ago

Bug Description

Trying to save a new template results in an exception:

Error: Call to a member function getFieldLayout() on null in /var/www/html/craft/vendor/spicyweb/craft-content-templates/src/elements/ContentTemplate.php:582
Stack trace:
#0 /var/www/html/craft/vendor/besteadfast/craft-preparse-field/src/services/PreparseFieldService.php(149): spicyweb\contenttemplates\elements\ContentTemplate->getFieldLayout()
#1 /var/www/html/craft/vendor/besteadfast/craft-preparse-field/src/PreparseField.php(155): besteadfast\preparsefield\services\PreparseFieldService->shouldParseElementOnMove(Object(spicyweb\contenttemplates\elements\ContentTemplate))
#2 [internal function]: besteadfast\preparsefield\PreparseField->besteadfast\preparsefield\{closure}(Object(craft\events\MoveElementEvent))
#3 /var/www/html/craft/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\events\MoveElementEvent))
#4 /var/www/html/craft/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger('craft\\services\\...', 'afterMoveElemen...', Object(craft\events\MoveElementEvent))
#5 /var/www/html/craft/vendor/craftcms/cms/src/services/Structures.php(562): yii\base\Component->trigger('afterMoveElemen...', Object(craft\events\MoveElementEvent))
#6 /var/www/html/craft/vendor/craftcms/cms/src/services/Structures.php(333): craft\services\Structures->_doIt(8, Object(spicyweb\contenttemplates\elements\ContentTemplate), Object(craft\records\StructureElement), 'prependTo', 'update')
#7 /var/www/html/craft/vendor/spicyweb/craft-content-templates/src/services/ProjectConfig.php(162): craft\services\Structures->prependToRoot(8, Object(spicyweb\contenttemplates\elements\ContentTemplate))
#8 [internal function]: spicyweb\contenttemplates\services\ProjectConfig->spicyweb\contenttemplates\services\{closure}(Object(craft\db\Connection))
#9 /var/www/html/craft/vendor/yiisoft/yii2/db/Connection.php(818): call_user_func(Object(Closure), Object(craft\db\Connection))
#10 /var/www/html/craft/vendor/spicyweb/craft-content-templates/src/services/ProjectConfig.php(168): yii\db\Connection->transaction(Object(Closure))
#11 /var/www/html/craft/vendor/spicyweb/craft-content-templates/src/elements/ContentTemplate.php(318): spicyweb\contenttemplates\services\ProjectConfig->save('34125cdd-342c-4...', Array)
#12 /var/www/html/craft/vendor/craftcms/cms/src/services/Elements.php(3160): spicyweb\contenttemplates\elements\ContentTemplate->afterSave(false)
#13 /var/www/html/craft/vendor/craftcms/cms/src/services/Elements.php(1063): craft\services\Elements->_saveElementInternal(Object(spicyweb\contenttemplates\elements\ContentTemplate), true, false, true, Array, false)
#14 /var/www/html/craft/vendor/craftcms/cms/src/controllers/ElementsController.php(1324): craft\services\Elements->saveElement(Object(spicyweb\contenttemplates\elements\ContentTemplate))
#15 [internal function]: craft\controllers\ElementsController->actionApplyDraft()
#16 /var/www/html/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#17 /var/www/html/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#18 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('apply-draft', Array)
#19 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(302): yii\base\Module->runAction('elements/apply-...', Array)
#20 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(627): craft\web\Application->runAction('elements/apply-...', Array)
#21 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(281): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#22 /var/www/html/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#23 /var/www/html/public/index.php(26): yii\base\Application->run()
#24 {main}

Steps to reproduce

  1. New installation of Content Templates
  2. Craft CMS 4.4.11

Expected behaviour

No response

Content Templates version

1.0.1

Craft CMS version

4.4.11

ttempleton commented 1 year ago

Not at my dev machine at the moment, but the stack trace shows the error coming from Preparse Field. Does saving work if you disable that plugin? If so, when I get a chance later today I'll dig into it and figure out which plugin this bug belongs to.

ttempleton commented 1 year ago

I can confirm the bug affecting compatibility with Preparse Field was on the Content Templates side, and should now be fixed in 1.0.2.

daltonrooney commented 1 year ago

Thanks, I can confirm that 1.0.2 solved the problem! Appreciate the quick fix. (A couple more issues coming your way, hope you don't mind.)