Problem/Motivation
Constructor has @deprecated tag and shouldn't.
it should trigger an error if the parameter is missing.
Additionally, DatabaseFileUsageBackend extends this class, and $config_factory is an optional third parameter in that class.
Proposed resolution
Remove @deprecated tag from FileUsageBase Constructor
Maintain the current BC layer and trigger an error if $config_factory is missing
Reorder the constructor arguments of DatabaseFileUsageBackend so that $config_factory is first and required.
Provide a BC layer if the arguments are passed in the old order and trigger an error.
Provide legacy tests to test the error triggering and that the BC layers work.
File a CR on the changing parameter order of DatabaseFileUsageBackend
File a follow-up against drupal 9 to restore type-hints and required status to parameters of both classes
Remaining tasks
review
commit
User interface changes
none
API changes
The signature of DatabaseFileUsageBackend has changed. A BC layer has been provided.
Data model changes
none
Release notes snippet
The constructor of DatabaseFileUsageBackend has had the order of its parameters changed.
Comment | File | Size | Author |
---|---|---|---|
#18 | interdiff.3069046.13-17.txt | 3.61 KB | mikelutz |
#18 | 3069046-17.drupal.Properly-manage-newly-required-parameter-of-FileUsageBaseconstruct.patch | 8.61 KB | mikelutz |
Comments
Comment #2
volegerAdded trigger_error with the message. Removed related rows from the docblock.
Comment #3
volegerComment #4
mikelutznit: Calling FileUsageBase::__construct() without the $config_factory parameter is deprecated in drupal:8.4.0 and the parameter will be required in drupal:9.0.0.......
Comment #5
andypostI bet here better use
__METHOD__
to get full namespaceComment #6
imalabyaAdded a patch to address to change the @trigger_error message. Keeping it in Needs work to add the test.
Comment #7
andypostthis should be fixed (not removed)
Comment #8
BerdirIt can't be fixed, @deprecated doesn't work for partial deprecations/changes, only for complete deprecations of a function or class.
Comment #9
mikelutzThe tag removal is correct. The method is not deprecated, it's a base class constructor that is part of the API. This just needs a legacy test now.
Comment #10
init90I've added test, but not sure if approach is correct.
Comment #11
init90Also, looks like we should deprecate empty
$config_factory
parameter forDrupal\file\FileUsage\DatabaseFileUsageBackend
.Comment #12
mikelutzYeah, I hadn't looked at that, that's going to be trickier than I thought. The order of arguments in the constructor need to be changed, and that is going to be a little more complicated..
Assigning to myself to take a look at.
Comment #13
mikelutzOkay, this patch changes the order of arguments of the DatabaseFileUsageBackend, which we have to do because $config_factory has to be required for proper DI . Proper errors are triggered, CR is made, follow-ups are filed, I think it looks good.
Comment #14
andypostGreat!
Comment #15
catchWhat about list($connection, $table, $config_factory) = func_get_args(); here?
Comment #16
BerdirWe usually don't document what we accept for BC?
I'm not quite sure why this is even necessary? The argument order doesn't have to match the parent, we've ben adding new arguments to the end of child class constructors before and it worked just fine before?
See \Drupal\Core\Entity\Sql\SqlContentEntityStorage::__construct for an example in HEAD.
Comment #17
mikelutzThe reordering is necessary because $config_factory needs to be required, and it currently is after an optional parameter.
+1 to reassigning the arguments via list, though I needed to wrap func_get_args() with array_pad due to the optional parameters.
I added the
|mixed
typehint to make it pass codesniffer tests (it complains if the signature doesn't match the annotation) I agree it makes more sense to document the expected parameters and make the mismatch with the signature a coding standards exception, so I disable codesniffer around the constructor signature.Doing that made me decide to restore some type safety and we now throw an InvalidArgumentException if the first parameter doesn't match either the legacy or current signature, and updated the test to check that exception, and to make sure the optional $table override gets reassigned correctly if passed.
Comment #18
mikelutzTIL @codingStandardsIgnoreLine :-)
Interdiff from #13 because api and caching and scripted patch generation and laziness..
Comment #19
mikelutzedit - double post, please ignore.
Comment #20
catch@codingStandardsIgnoreLine is handy here, TIL too :)
Back to RTBC.
Comment #21
larowlanComment #22
larowlanCommitted ae58cf0 and pushed to 8.8.x. Thanks!
Comment #25
quietone CreditAttribution: quietone at PreviousNext commentedpublish the change record