Problem/Motivation

Symfony 5.1 added an InputBag class to store user input. In Drupal core we have a number of places - mostly tests, but not all - where we directly refer to ParameterBag, and at first glance these seem to often be used to store or mock user supplied input.

Proposed resolution

Replace relevant instances of ParameterBag with InputBag for Symfony 5.

Remaining tasks

  • Identify which instances need to be replaced
  • Determine if we can do this in Drupal 9 with a BC layer or can wait for Symfony 5/6 in Drupal 10

User interface changes

API changes

Data model changes

Release notes snippet

Comments

longwave created an issue. See original summary.

andypost’s picture

Nearly the same we faced in https://www.drupal.org/node/2743809

The semantics of Request::get() have changed in Symfony 3. Request attributes are now examined first before request query parameters. The use of $request->get() is highly discouraged, use $request->query->get() instead if you need to access request query parameters.

andypost’s picture

On first look
- \Drupal\media_library\MediaLibraryState extends it but now mismatch with InputBag
- \Drupal\Core\Form\FormBuilder::doBuildForm() also affected as creating request
- \Drupal\Core\Security\RequestSanitizer::sanitize() processing exactly affected bags so needs shim
- other usage in tests but around ~40 places

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

gábor hojtsy’s picture

Title: [Symfony 5] Use Symfony\Component\HttpFoundation\InputBag where appropriate instead of ParameterBag » [Symfony 6] Use Symfony\Component\HttpFoundation\InputBag where appropriate instead of ParameterBag
Issue tags: +Symfony 6
andypost’s picture

Status: Active » Needs review
StatusFileSize
new629 bytes
new1.93 KB

Primary usage looks is for _raw_variables ~20

Here's 2 approaches to replace it - patches are examples for one of tests

- aliasing to core namespace as _raw_variables is core's concept (could use separate issue to dig)
- replace the class directly (patch 2) - more changes but easy to catch remains

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

daffie’s picture

+1 for replacing the class directly (patch 2).

longwave’s picture

Also +1 to replacing the class instead of aliasing, it will make it less confusing in the future.

daffie’s picture

Status: Needs review » Needs work

I asked @catch on slack about with which solution we should go and his answer was also option 2. It looks to me that we have consensus about the which solution to choose. Putting this issue back to needs work for implementation solution #2.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

paulocs’s picture

Status: Needs work » Needs review
StatusFileSize
new25.73 KB

Please check if all places were properly replaced.

Status: Needs review » Needs work

The last submitted patch, 13: 3162981-13.patch, failed testing. View results

murilohp’s picture

StatusFileSize
new27.34 KB
new1.46 KB

Hey @paulocs, I think you forgot to update one place, you updated the tests but not on the implementation, this new patch can fix the testing error.

murilohp’s picture

Status: Needs work » Needs review

Forgot to chante the status.

murilohp’s picture

StatusFileSize
new1.46 KB

I'm so sorry for my previous interdiff, here's the correct one.

murilohp’s picture

Status: Needs review » Needs work

The last submitted patch, 15: interdiff_13-15.patch, failed testing. View results

murilohp’s picture

Status: Needs work » Needs review

Moving to needs review due to my mistake with interdiff.

lucienchalom’s picture

Status: Needs review » Needs work
StatusFileSize
new238 KB

I found an inconsistency in the documentation on file core/lib/Drupal/Core/Routing/RouteMatch.php
lines 41:

  /**
   * A key|value store of raw parameters.
   *
   * @var \Symfony\Component\HttpFoundation\ParameterBag
   */
  protected $rawParameters;

and line 64:
$this->rawParameters = new InputBag($raw_parameters);

Can someone confirm if this is how was supposed to be?

Besides that, there was no addition of coding standards and the code looks to be working fine.
As soon this is resolved I can move to RTBC

murilohp’s picture

StatusFileSize
new27.59 KB
new408 bytes

@lucienchalom good catch! I've updated the code, here's a new patch.

murilohp’s picture

Status: Needs work » Needs review
lucienchalom’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @murilohp!
Everything looks good to me.
RTBC

longwave’s picture

Not sure if we want to do this now and use \Drupal\Core\Http\InputBag or wait until we are on Symfony 5.4 when we can use \Symfony\Component\HttpFoundation\InputBag instead?

The Symfony InputBag is final so we can't do a backward compatible switch by extending it.

catch’s picture

I'm also not sure how much we're gaining here compared to waiting for Symfony 5.4 - we're not actually removing any deprecation messages with this, and we'll want to switch away from \Drupal\Core\Http\InputBag including where it's currently used in core one we're on 5.4 too.

Leaving RTBC but will try to get a third opinion.

catch’s picture

Title: [Symfony 6] Use Symfony\Component\HttpFoundation\InputBag where appropriate instead of ParameterBag » [PP-1] [Symfony 6] Use Symfony\Component\HttpFoundation\InputBag where appropriate instead of ParameterBag

Discussed briefly with @alexpott.

If we were able to make the Drupal InputBag a real forward compatibility layer, this might have been fine, but instead it was purely an internal layer so we could update calling code (which isn't necessary for the examples here). Given that, going to mark this postponed on #3197482: Update Drupal 10 to depend on Symfony 5.4 (as a stepping stone to Symfony 6, for deprecation checking support). Once that's in, updating this patch should just be switching the use statements.

catch’s picture

Status: Reviewed & tested by the community » Postponed

Updating the status helps.

daffie’s picture

murilohp’s picture

Version: 9.4.x-dev » 10.0.x-dev
Issue tags: -Needs reroll
StatusFileSize
new32.28 KB
new20.11 KB

Hey, I rerolled the patch, and also removed the \Drupal\Core\Http\InputBag class, since SF 5.4 landed, I don't think this is necessary anymore. If you think this is not part of the scope of this issue, I can revert and we create a new issue just for the InputBag clean up.

murilohp’s picture

Status: Needs work » Needs review
daffie’s picture

Title: [PP-1] [Symfony 6] Use Symfony\Component\HttpFoundation\InputBag where appropriate instead of ParameterBag » [Symfony 6] Use Symfony\Component\HttpFoundation\InputBag where appropriate instead of ParameterBag
catch’s picture

also removed the \Drupal\Core\Http\InputBag class, since SF 5.4 landed, I don't think this is necessary anymore.

We marked that internal for removal in 10.0.0, so it's fine to remove here!

daffie’s picture

Status: Needs review » Needs work

The testbot is failing for D10.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new1.26 KB
new33.65 KB

Just did composer update.

longwave’s picture

+++ b/core/tests/Drupal/TestTools/PhpUnitCompatibility/ClassWriter.php
@@ -98,7 +98,7 @@ private static function alterTestCase(ClassLoader $autoloader): void {
-    $directory = __DIR__ . '/../../../../../../sites/simpletest';
+    $directory = __DIR__ . '/../../../../../sites/simpletest';

This seems out of scope.

longwave’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php
    @@ -53,7 +53,8 @@ public function enhance(array $defaults, Request $request) {
    +   *   Returns a container for key/value pairs based.
    

    This sentence doesn't quite make sense.

  2. +++ b/core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php
    @@ -66,7 +67,7 @@ protected function copyRawVariables(array $defaults) {
    -    return new ParameterBag($raw_variables);
    +    return new InputBag($raw_variables);
    

    Should we be backporting this sort of thing to 9.x, or does it not really matter?

murilohp’s picture

Status: Needs work » Needs review
StatusFileSize
new32.88 KB
new1.15 KB

My bad @longwave, I was having some problems testing locally then I changed the /core/tests/Drupal/TestTools/PhpUnitCompatibility/ClassWriter.php and forgot to rollback. Thanks for pointing this out!

About #37:

1. I changed the return comment on this new patch.
2. IMHO I don't think we should backport this to 9.x. Just focus on D10.

longwave’s picture

CSpell appears to be complaining that a file no longer exists, but why did it not do this before?

CSpell: Files checked: 23, Issues found: 0 in 0 files
Path /var/www/html/core/lib/Drupal/Core/Http/InputBag.php does not exist


Oh, that's not the issue - it is just

Running PHPStan on changed files.

PHPStan: failed
catch’s picture

On backporting - it's been good to do as much as we can in 9.x prior to 10.x (we already made a lot of changes along these lines), but I don't we need to worry too much about extracting changes for backport now that 10.x is open (unless there's an additional specific reason to do so).

longwave’s picture

murilohp’s picture

#3259142 landed, now I'm rerunning #38, hope it passes now.

Status: Needs review » Needs work

The last submitted patch, 38: 3162981-38.patch, failed testing. View results

spokje’s picture

Looks like a random test fail, restarting test

spokje’s picture

Status: Needs work » Needs review

And @catch beat me to it :)

longwave’s picture

Status: Needs review » Reviewed & tested by the community

This looks good now.

  • catch committed c022827 on 10.0.x
    Issue #3162981 by murilohp, andypost, quietone, paulocs, lucienchalom,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

This looks great. Removing usages and one internal class rather than deprecations as such so good to go in before the alpha.

Committed c022827 and pushed to 10.0.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.