Closed (fixed)
Project:
Drupal core
Version:
9.4.x-dev
Component:
media system
Priority:
Critical
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
9 Nov 2021 at 12:27 UTC
Updated:
5 Jan 2022 at 15:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
daffie commentedThe fix.
Comment #3
larowlanIsn't the default NULL? If so can we just use ?: Instead of calling ::all?
Comment #4
daffie commentedThe problem is that the method
get()needs to return a string, int or float value (only scalar values) and the methodall()only whats to return array values. Drupal likes to mix array values with string values and therefor we cannot use the methodget()any more. The key is to use the methodall()to get all values and then to select the value you need:all()['media_library_opener_parameters']. It then works for string values as for array values. The methodall()does not have a default return value. See: https://www.drupal.org/node/3213138Comment #5
larowlanSorry, I was asking is there a reason we can't write this as
And avoid calling ::all
But I get it now, its not about the 'null' case its about the 'value exists' case
should we store the return from the first call to :all and avoid calling it twice?
In fact, could we re-write this using one call to :all and array_intersect_key and remove the ::get calls too?
Comment #6
daffie commentedGood idea and fixed.
Comment #8
daffie commentedThe default value for the method Symfony\Component\HttpFoundation\ParameterBag::get() is NULL and not an empty string as used in the previous patch. See: https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/HttpFo...
Comment #9
larowlanLooks good to me
Comment #10
longwaveThe reason we use
all()instead ofall('key')orget('key')is when what we are retrieving really could either be a scalar or an array, and subsequent code is set up to handle both cases. Is it really the case that we don't know this for each of these values? Surely e.g. themedia_library_opener_idcan never be an array?Comment #11
longwaveThis was solved a cleaner way back in https://git.drupalcode.org/project/drupal/-/merge_requests/462/diffs#dif... - this was then reverted for other reasons but I think we can reintroduce the same fix for MediaLibraryState at least.
Comment #12
longwaveAlternative approach that uses
all()andget()as Symfony intends, this provides extra safety against a malicious user sending an array instead of a string or vice versa.The InputBag replacement in the test is done at runtime in bootstrap.php, this will be removed when we no longer need to support both versions of Symfony.
Comment #13
daffie commentedI am giving this current patch a RTBC, because it is a correct solution.
The solution from comment #12 looks like it is copying code from Symfony and it is needing a temporary fix in the test MediaLibraryStateTest.
Personally I like the solution from comment #8 more. To me, it is more in line with how Symfony thinks it should be used.
I leave it up to the committer to decide which solution should land.
Comment #14
alexpottWe should add an @todo to remove this. I agree with @longwave - I think using all(PARAM_NAME) when we expect an array and get(PARAM_NAME) when we expect a scalar is how this is intended to be used.
I would be great to have an InputBag clean up issue that we can link to.
This could link to the inputbag clean up issue.
Comment #15
catchInputbag clean-up issue should probably be this one #3162981: [Symfony 6] Use Symfony\Component\HttpFoundation\InputBag where appropriate instead of ParameterBag.
Comment #16
catchAdding #3254250: [Symfony 6] Retrieving a non-string value from "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated to related issues, was previously duplicating the fix here.
Comment #17
spokjeTried to address #14.1 and .2.
Comment #18
daffie commentedThe points of @alexpott from comment #14 are addressed.
Back to RTBC.
@Spokje: Thank you for working on this!
Comment #21
catchCommitted/pushed to 10.0.x, also cherry-picked to 9.4.x to keep the tests in sync.