BUGFIX: Consistently initialize asset sources via createFromConfiguration
#4008
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes: #3965
The Problem
The case at hand was an asset source that uses a value object to validate the incoming asset source options. I expected to be able to define a promoted constructor property with said value object as its declared type:
...and initialize the value object in the
createFromConfiguration
static factory method defined by theAssetSourceInterface
:This failed with a Type Error, because the
AssetSourceService
, which is responsible for initializing asset sources, at one point does not utilizecreateFromConfiguration
to perform initialization, but calls the asset source constructor directly:neos-development-collection/Neos.Media/Classes/Domain/Service/AssetSourceService.php
Line 178 in a4791b6
The Solution
I adjusted the aforementioned routine of the
AssetSourceService
to use theAssetSourceInterface
-definedcreateFromConfiguration
static factory method instead of the asset source's constructor.Even though the pattern I described above only makes sense in a PHP >8.0 environment, I decided to target Neos 7.3 with this PR, because it should constitute a non-breaking bugfix.