Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: Twig template not found using action elements/save-draft in frontend #12131

Closed
swordinthestone opened this issue Oct 16, 2022 · 2 comments

Comments

@swordinthestone
Copy link

swordinthestone commented Oct 16, 2022

What happened?

Description

When using ajax or direct form post with an action "elements/save-draft" from front end, action return a template error "Unable to find the template “_includes/forms/text”". I am using this action to save a draft for existing entry to provide a preview to end user.

The error is occur on
src/controllers/ElementsController @ Line 1151

$form = $fieldLayout->createForm(...)

This action is loading templates from front end template folder, instead of vendors folder, to bulild response. Actions works as excepted from control panel.

After reading the sourece code, I am not sure it is intended to process this way or not, because it makes sense to build form tabs on control panel. However, as Craft 4 has change "entry-revisions/save-draft" to "elements/save-draft", and seem like there is no other alternative actions to save draft from front end nativly from Craft.

Therefore, my question is:
Should action "elements/save-draft" be only used on developing custom control panel plugins? We should write custom action to handle element draft for front end.

Steps to reproduce

  1. Form submit from front end with action "elements/save-draft" with proper elementId, Element types and other required data, even using exact same payload for Preview.

Expected behavior

Can return an response as action from control panal to save a draft.

Actual behavior

Draft is not created in database, because the form render error interrupt the response building process.

Stack:

2022-10-16 10:09:57 [web.ERROR] [craft\web\twig\TemplateLoaderException] craft\web\twig\TemplateLoaderException: Unable to find the template “_includes/forms/text”. in D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\web\twig\TemplateLoader.php:108
Stack trace:
#0 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\web\twig\TemplateLoader.php(69): craft\web\twig\TemplateLoader->_resolveTemplate('_includes/forms...')
#1 D:\wamp64\www\berry-vgc\vendor\twig\twig\src\Environment.php(261): craft\web\twig\TemplateLoader->getCacheKey('_includes/forms...')
#2 D:\wamp64\www\berry-vgc\vendor\twig\twig\src\Environment.php(309): Twig\Environment->getTemplateClass('_includes/forms...')
#3 D:\wamp64\www\berry-vgc\vendor\twig\twig\src\Environment.php(277): Twig\Environment->load('_includes/forms...')
#4 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\web\View.php(428): Twig\Environment->render('_includes/forms...', Array)
#5 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\fieldlayoutelements\TextField.php(145): craft\web\View->renderTemplate('_includes/forms...', Array)
#6 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\fieldlayoutelements\entries\EntryTitleField.php(75): craft\fieldlayoutelements\TextField->inputHtml(Object(craft\elements\Entry), false)
#7 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\fieldlayoutelements\BaseField.php(215): craft\fieldlayoutelements\entries\EntryTitleField->inputHtml(Object(craft\elements\Entry), false)
#8 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\models\FieldLayout.php(738): craft\fieldlayoutelements\BaseField->formHtml(Object(craft\elements\Entry), false)
#9 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\web\View.php(1553): craft\models\FieldLayout->craft\models\{closure}()
#10 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\models\FieldLayout.php(737): craft\web\View->namespaceInputs(Object(Closure), NULL)
#11 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\controllers\ElementsController.php(1158): craft\models\FieldLayout->createForm(Object(craft\elements\Entry), false, Array)
#12 [internal function]: craft\controllers\ElementsController->craft\controllers\{closure}(Object(craft\db\Connection))
#13 D:\wamp64\www\berry-vgc\vendor\yiisoft\yii2\db\Connection.php(817): call_user_func(Object(Closure), Object(craft\db\Connection))
#14 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\controllers\ElementsController.php(1222): yii\db\Connection->transaction(Object(Closure))
#15 [internal function]: craft\controllers\ElementsController->actionSaveDraft()
#16 D:\wamp64\www\berry-vgc\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#17 D:\wamp64\www\berry-vgc\vendor\yiisoft\yii2\base\Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#18 D:\wamp64\www\berry-vgc\vendor\yiisoft\yii2\base\Module.php(552): yii\base\Controller->runAction('save-draft', Array)
#19 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\web\Application.php(301): yii\base\Module->runAction('elements/save-d...', Array)
#20 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\web\Application.php(625): craft\web\Application->runAction('elements/save-d...', Array)
#21 D:\wamp64\www\berry-vgc\vendor\craftcms\cms\src\web\Application.php(280): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#22 D:\wamp64\www\berry-vgc\vendor\yiisoft\yii2\base\Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#23 D:\wamp64\www\berry-vgc\index.php(22): yii\base\Application->run()
#24 {main} {"memory":11733288,"exception":"[object] (craft\\web\\twig\\TemplateLoaderException(code: 0): Unable to find the template “_includes/forms/text”. at D:\\wamp64\\www\\berry-vgc\\vendor\\craftcms\\cms\\src\\web\\twig\\TemplateLoader.php:108)"} 
2022-10-16 10:09:57 [web.INFO] [application] Request context:

Craft CMS version

4.2.4

PHP version

8.1.9

Operating system and version

Windows 10 21H2

Database type and version

MariaDB 10.4.10

Image driver and version

No response

Installed plugins and versions

@i-just
Copy link
Contributor

i-just commented Oct 17, 2022

Hi, thanks for getting in touch. We've also noticed it outselves a few days ago. It's been fixed for Craft 4.3 (85b5da2).

brandonkelly added a commit that referenced this issue Oct 18, 2022
@brandonkelly
Copy link
Member

Craft 4.3 was released earlier this week with the fix for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants