Deprecate optional parent prop in Cms\File#3372
Conversation
6b04afa to
de6ea7e
Compare
|
Yes, because several methods like |
|
But is then the mistake that |
|
Yes, I think so. Either |
|
I also think that it's a mistake in setParent. We don't have any isolated files that don't have a parent. The only ones are assets and they are handled by a different class. |
de6ea7e to
30aa3d7
Compare
File::create(): make parent prop optionalFile: parent prop needs to be required
|
@lukasbestle @bastianallgeier I have tried that (see new commit), but at least in a larger number of our tests, |
|
Are there use-cases where it would make sense to manually instantiate a |
|
Virtual files? |
|
Yeah, you are right. These do have parents (their virtual or real page), but it could well be that users are manually instantiating the files without passing the |
|
It's really tricky cause I feel either way it would be a breaking change. But the current state - |
|
Yep, currently a file object without parent is of limited use as many methods will not work if the parent is not defined. Maybe we should deprecate a missing parent property in 3.6.0 (with deprecation warning) and then enforce it in 3.7.0. |
30aa3d7 to
f267086
Compare
File: parent prop needs to be requiredparent prop in Cms\File
|
@lukasbestle I have adapted the PR as suggested |
lukasbestle
left a comment
There was a problem hiding this comment.
Looks good! I've fixed a few typos and made some changes to make the message more clear.
Could you please check why the E2E tests started failing? In one of the test cases an error component pops up, so it looks like we use the deprecated behavior ourselves somewhere.
|
👍 |
lukasbestle
left a comment
There was a problem hiding this comment.
I've also updated the backend tests to pass the parent prop so we don't have this work when we make it required in 3.7.0.
5e5371d to
ab3c64a
Compare
|
I've rebased this PR against |
|
👍 lgtm |
Status: ready for review 👀
Release notes
Deprecated
Kirby\Cms\Filewithout aparentproperty has been deprecated and throws a warning. Starting in 3.7.0 the property will be required and cause a breaking error if not passed.Initial post
This getkirby/getkirby.com#1348 issue for the website pointed out that the
parentprop should be listed as required, since theFile::create()method will throw an exception if it is not passed.However, looking at the code I could not figure out why it should be required. We only seem to pass it to
File::factory()which creates a newFileobject. There the property setterFile::setParent()states the property as optional.@lukasbestle @bastianallgeier
Do you remember maybe why this Exception was put there to require the
parentprop?