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]: Exception thrown when saving Asset w/o filename #11439

Closed
timkelty opened this issue Jun 14, 2022 · 1 comment
Closed

[4.x]: Exception thrown when saving Asset w/o filename #11439

timkelty opened this issue Jun 14, 2022 · 1 comment
Assignees

Comments

@timkelty
Copy link
Contributor

timkelty commented Jun 14, 2022

What happened?

Description

In 3.x, this code would work:

                    $screenshot = new Asset([
                        'title' => $plugin->name,
                        'tempFilePath' => $tempPath,
                        'newLocation' => "{folder:{$folderId}}" . $targetFilename,
                        'avoidFilenameConflicts' => true,
                    ]);
                    Craft::$app->getElements()->saveElement($screenshot);

In 4, when saving, it will throw: InvalidConfigException('Asset not configured with its filename')

Easily fixed by providing filename in the config, but not what the intended behavior is, as I don't see anything in the changelog/upgrade guide about this.

Craft CMS version

4.0.4

PHP version

8

@brandonkelly
Copy link
Member

This was only barely possible in Craft 3, due to this code:

https://github.com/pixelandtonic/craftnet/blob/d9feddaee8fe133e77c259c85c2558f8f0e6ea75/src/controllers/PluginsController.php#L499-L501

(Validate newLocation on its own, and then save the asset without running additional validation. If either of those things didn’t happen, you would get a validation/ops error.)

So I’m not really considering this a regression, but it does make sense that you shouldn’t have to specify a newLocation and a filename, so I’ve made it possible to omit filename for Craft 4.1.

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