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.0.2]: Twig variable in asset folder path causes upload button to not be displayed if folder doesn't exist #11254

Closed
richhayler opened this issue May 18, 2022 · 5 comments

Comments

@richhayler
Copy link

richhayler commented May 18, 2022

What happened?

Description

Upload button not displayed on file selection modal due to twig variable used in sub folder path for a path that doesn't exist, e.g. if using {slug} in the folder path

Steps to reproduce

  • Create a new filesystem
  • Create a new volume that references the filesystem
  • Create a new field that points to the volume
  • For the field settings....
  • Select "restrict assets to a single location'
  • Select folder location from the dropdown
  • Add {slug} in the subfolder path
  • Ensure "Allow sub folders" and "Allow uploading directly to the field" are both unchecked
  • Save and assign field to entry type in a new section
  • Create a new entry and click the asset file to upload a new file
  • Modal is displayed without the upload button in the bottom left

CleanShot 2022-05-18 at 13 51 44@2x

Expected behavior

Event though the folder for the slug doesn't appear (as this would be created when the entry is created), the upload button should be displayed in the file selection modal.

Craft CMS version

4.0.2

PHP version

8.1.5

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@richhayler richhayler changed the title [4.x]: Twig variable in asset folder path causes upload button to not be displayed if folder doesn't exist [4.0.2]: Twig variable in asset folder path causes upload button to not be displayed if folder doesn't exist May 18, 2022
@brandonkelly
Copy link
Member

Thanks for pointing that out! Just fixed for the next release.

@brandonkelly
Copy link
Member

Craft 4.0.3 is out now with that fix.

@richhayler
Copy link
Author

richhayler commented May 22, 2022

I have updated to 4.0.3 and it's now working as expected using {slug} in the sub folder path.

Should I be able to use access globalSet variables in the folder subpath? - e.g. I have a globalSet named "global" with a text field, "mytext" (which is a single word, no spaces)?

CleanShot 2022-05-22 at 15 53 19@2x

If I use {global.mytext} this results in an error stating that "the field’s Asset Location setting has an invalid subpath (“{global.domain}”)".

craft\errors\InvalidSubpathException: Could not resolve the subpath “{global.domain}”. in /craft/vendor/craftcms/cms/src/fields/Assets.php:855
Stack trace:
#0 /craft/vendor/craftcms/cms/src/fields/Assets.php(955): craft\fields\Assets->_resolveVolumePathToFolderId()
#1 /craft/vendor/craftcms/cms/src/fields/Assets.php(495): craft\fields\Assets->_determineUploadFolderId()
#2 /craft/vendor/craftcms/cms/src/fields/Assets.php(565): craft\fields\Assets->craft\fields\{closure}()
#3 /craft/vendor/craftcms/cms/src/base/Element.php(4512): craft\fields\Assets->afterElementSave()
#4 /craft/vendor/craftcms/cms/src/services/Elements.php(2696): craft\base\Element->afterSave()
#5 /craft/vendor/craftcms/cms/src/services/Elements.php(766): craft\services\Elements->_saveElementInternal()
#6 /craft/vendor/craftcms/cms/src/controllers/GlobalsController.php(221): craft\services\Elements->saveElement()
#7 [internal function]: craft\controllers\GlobalsController->actionSaveContent()
#8 /craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#9 /craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#10 /craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#11 /craft/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction()
#12 /craft/vendor/craftcms/cms/src/web/Application.php(625): craft\web\Application->runAction()
#13 /craft/vendor/craftcms/cms/src/web/Application.php(280): craft\web\Application->_processActionRequest()
#14 /craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#15 /craft/web/index.php(19): yii\base\Application->run()
#16 {main}

Next craft\errors\InvalidSubpathException: The Logo field’s Asset Location setting has an invalid subpath (“{global.domain}”). in /craft/vendor/craftcms/cms/src/fields/Assets.php:980
Stack trace:
#0 /craft/vendor/craftcms/cms/src/fields/Assets.php(495): craft\fields\Assets->_determineUploadFolderId()
#1 /craft/vendor/craftcms/cms/src/fields/Assets.php(565): craft\fields\Assets->craft\fields\{closure}()
#2 /craft/vendor/craftcms/cms/src/base/Element.php(4512): craft\fields\Assets->afterElementSave()
#3 /craft/vendor/craftcms/cms/src/services/Elements.php(2696): craft\base\Element->afterSave()
#4 /craft/vendor/craftcms/cms/src/services/Elements.php(766): craft\services\Elements->_saveElementInternal()
#5 /craft/vendor/craftcms/cms/src/controllers/GlobalsController.php(221): craft\services\Elements->saveElement()
#6 [internal function]: craft\controllers\GlobalsController->actionSaveContent()
#7 /craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#8 /craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#9 /craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#10 /craft/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction()
#11 /craft/vendor/craftcms/cms/src/web/Application.php(625): craft\web\Application->runAction()
#12 /craft/vendor/craftcms/cms/src/web/Application.php(280): craft\web\Application->_processActionRequest()
#13 /craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#14 /craft/web/index.php(19): yii\base\Application->run()
#15 {main}

@brandonkelly
Copy link
Member

brandonkelly commented May 24, 2022

You would need to use normal Twig syntax for that ({{ global.mytext }}). The {shorthand} syntax is exclusively for properties of the entry being saved (or the Matrix block if the Assets field is nested in a Matrix field.)

@richhayler
Copy link
Author

Thank you for responding and providing those tips!

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

2 participants