From 4ca93c9ca8f7e1498f158f8b83b5342e9da81f2b Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 28 Dec 2021 10:12:12 +0000
Subject: [PATCH] Issue #3254250 by Spokje, longwave, catch, daffie: [Symfony
 6] Retrieving a non-string value from
 "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated

---
 .../Core/Ajax/AjaxResponseAttachmentsProcessor.php   |  2 +-
 .../Core/Cache/Context/QueryArgsCacheContext.php     |  2 +-
 .../Core/Render/MainContent/DialogRenderer.php       |  2 +-
 .../Drupal/Core/Render/MainContent/ModalRenderer.php |  2 +-
 .../Core/Render/MainContent/OffCanvasRenderer.php    |  2 +-
 .../lib/Drupal/Core/Theme/AjaxBasePageNegotiator.php |  4 ++--
 .../comment/src/Controller/CommentController.php     |  7 ++++---
 core/modules/contextual/src/ContextualController.php |  8 ++++----
 .../field_ui/src/Form/FieldConfigEditForm.php        |  2 +-
 .../field_ui/src/Form/FieldStorageConfigEditForm.php |  2 +-
 .../history/src/Controller/HistoryController.php     |  4 ++--
 .../jsonapi/src/Controller/EntityResource.php        |  6 +++---
 .../EventSubscriber/ResourceResponseSubscriber.php   |  4 ++--
 .../src/Kernel/Controller/EntityResourceTest.php     |  6 +++---
 .../menu_ui/src/Controller/MenuController.php        |  2 +-
 core/modules/quickedit/src/QuickEditController.php   | 12 ++++++------
 .../src/Render/MainContent/WideModalRenderer.php     |  2 +-
 .../Tests/Core/Theme/AjaxBasePageNegotiatorTest.php  |  5 +++++
 18 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php b/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php
index 600a6dbd7163..4f6acbf9664f 100644
--- a/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php
+++ b/core/lib/Drupal/Core/Ajax/AjaxResponseAttachmentsProcessor.php
@@ -128,7 +128,7 @@ public function processAttachments(AttachmentsInterface $response) {
    *   An array of commands ready to be returned as JSON.
    */
   protected function buildAttachmentsCommands(AjaxResponse $response, Request $request) {
-    $ajax_page_state = $request->request->get('ajax_page_state');
+    $ajax_page_state = $request->request->all('ajax_page_state');
 
     // Aggregate CSS/JS if necessary, but only during normal site operation.
     $optimize_css = !defined('MAINTENANCE_MODE') && $this->config->get('css.preprocess');
diff --git a/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php b/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php
index a48664468db9..d9e5d67983d7 100644
--- a/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php
+++ b/core/lib/Drupal/Core/Cache/Context/QueryArgsCacheContext.php
@@ -31,7 +31,7 @@ public function getContext($query_arg = NULL) {
       return ($value !== NULL) ? $value : '';
     }
     elseif ($this->requestStack->getCurrentRequest()->query->has($query_arg)) {
-      $value = $this->requestStack->getCurrentRequest()->query->get($query_arg);
+      $value = $this->requestStack->getCurrentRequest()->query->all()[$query_arg];
       if (is_array($value)) {
         return http_build_query($value);
       }
diff --git a/core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php b/core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php
index e9dd1ed17539..3438d0fd27c7 100644
--- a/core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php
+++ b/core/lib/Drupal/Core/Render/MainContent/DialogRenderer.php
@@ -61,7 +61,7 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
     $title = $main_content['#title'] ?? $this->titleResolver->getTitle($request, $route_match->getRouteObject());
 
     // Determine the dialog options and the target for the OpenDialogCommand.
-    $options = $request->request->get('dialogOptions', []);
+    $options = $request->request->all('dialogOptions');
     $target = $this->determineTargetSelector($options, $route_match);
 
     $response->addCommand(new OpenDialogCommand($target, $title, $content, $options));
diff --git a/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php b/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php
index d903acf88d15..df80b7dce00c 100644
--- a/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php
+++ b/core/lib/Drupal/Core/Render/MainContent/ModalRenderer.php
@@ -31,7 +31,7 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
 
     // Determine the title: use the title provided by the main content if any,
     // otherwise get it from the routing information.
-    $options = $request->request->get('dialogOptions', []);
+    $options = $request->request->all('dialogOptions');
 
     $response->addCommand(new OpenModalDialogCommand($title, $content, $options));
     return $response;
diff --git a/core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php b/core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php
index 6c598ccb0a91..02a1b2329306 100644
--- a/core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php
+++ b/core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php
@@ -64,7 +64,7 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
 
     // Determine the title: use the title provided by the main content if any,
     // otherwise get it from the routing information.
-    $options = $request->request->get('dialogOptions', []);
+    $options = $request->request->all('dialogOptions');
     $response->addCommand(new OpenOffCanvasDialogCommand($title, $content, $options, NULL, $this->position));
     return $response;
   }
diff --git a/core/lib/Drupal/Core/Theme/AjaxBasePageNegotiator.php b/core/lib/Drupal/Core/Theme/AjaxBasePageNegotiator.php
index 5cd2ee305797..1c19472df868 100644
--- a/core/lib/Drupal/Core/Theme/AjaxBasePageNegotiator.php
+++ b/core/lib/Drupal/Core/Theme/AjaxBasePageNegotiator.php
@@ -65,7 +65,7 @@ public function __construct(CsrfTokenGenerator $token_generator, ConfigFactoryIn
    * {@inheritdoc}
    */
   public function applies(RouteMatchInterface $route_match) {
-    $ajax_page_state = $this->requestStack->getCurrentRequest()->request->get('ajax_page_state');
+    $ajax_page_state = $this->requestStack->getCurrentRequest()->request->all('ajax_page_state');
     return !empty($ajax_page_state['theme']) && isset($ajax_page_state['theme_token']);
   }
 
@@ -73,7 +73,7 @@ public function applies(RouteMatchInterface $route_match) {
    * {@inheritdoc}
    */
   public function determineActiveTheme(RouteMatchInterface $route_match) {
-    $ajax_page_state = $this->requestStack->getCurrentRequest()->request->get('ajax_page_state');
+    $ajax_page_state = $this->requestStack->getCurrentRequest()->request->all('ajax_page_state');
     $theme = $ajax_page_state['theme'];
     $token = $ajax_page_state['theme_token'];
 
diff --git a/core/modules/comment/src/Controller/CommentController.php b/core/modules/comment/src/Controller/CommentController.php
index 2cba4ac918df..9304e20009e1 100644
--- a/core/modules/comment/src/Controller/CommentController.php
+++ b/core/modules/comment/src/Controller/CommentController.php
@@ -337,11 +337,12 @@ public function renderNewCommentsNodeLinks(Request $request) {
       throw new AccessDeniedHttpException();
     }
 
-    $nids = $request->request->get('node_ids');
-    $field_name = $request->request->get('field_name');
-    if (!isset($nids)) {
+    if (!$request->request->has('node_ids') || !$request->request->has('field_name')) {
       throw new NotFoundHttpException();
     }
+    $nids = $request->request->all('node_ids');
+    $field_name = $request->request->get('field_name');
+
     // Only handle up to 100 nodes.
     $nids = array_slice($nids, 0, 100);
 
diff --git a/core/modules/contextual/src/ContextualController.php b/core/modules/contextual/src/ContextualController.php
index cd6ddb40a858..378b5236c4b5 100644
--- a/core/modules/contextual/src/ContextualController.php
+++ b/core/modules/contextual/src/ContextualController.php
@@ -60,15 +60,15 @@ public static function create(ContainerInterface $container) {
    * @see contextual_preprocess()
    */
   public function render(Request $request) {
-    $ids = $request->request->get('ids');
-    if (!isset($ids)) {
+    if (!$request->request->has('ids')) {
       throw new BadRequestHttpException('No contextual ids specified.');
     }
+    $ids = $request->request->all('ids');
 
-    $tokens = $request->request->get('tokens');
-    if (!isset($tokens)) {
+    if (!$request->request->has('tokens')) {
       throw new BadRequestHttpException('No contextual ID tokens specified.');
     }
+    $tokens = $request->request->all('tokens');
 
     $rendered = [];
     foreach ($ids as $key => $id) {
diff --git a/core/modules/field_ui/src/Form/FieldConfigEditForm.php b/core/modules/field_ui/src/Form/FieldConfigEditForm.php
index a0fa3d3f4cba..f2346e70697c 100644
--- a/core/modules/field_ui/src/Form/FieldConfigEditForm.php
+++ b/core/modules/field_ui/src/Form/FieldConfigEditForm.php
@@ -207,7 +207,7 @@ public function save(array $form, FormStateInterface $form_state) {
     $this->messenger()->addStatus($this->t('Saved %label configuration.', ['%label' => $this->entity->getLabel()]));
 
     $request = $this->getRequest();
-    if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
+    if (($destinations = $request->query->all('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
       $request->query->remove('destinations');
       $form_state->setRedirectUrl($next_destination);
     }
diff --git a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
index d70c0aadd4cb..d6dec922019a 100644
--- a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
+++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
@@ -229,7 +229,7 @@ public function save(array $form, FormStateInterface $form_state) {
       $this->entity->save();
       $this->messenger()->addStatus($this->t('Updated field %label field settings.', ['%label' => $field_label]));
       $request = $this->getRequest();
-      if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
+      if (($destinations = $request->query->all('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
         $request->query->remove('destinations');
         $form_state->setRedirectUrl($next_destination);
       }
diff --git a/core/modules/history/src/Controller/HistoryController.php b/core/modules/history/src/Controller/HistoryController.php
index c6a483490387..ca3498ead8a7 100644
--- a/core/modules/history/src/Controller/HistoryController.php
+++ b/core/modules/history/src/Controller/HistoryController.php
@@ -28,10 +28,10 @@ public function getNodeReadTimestamps(Request $request) {
       throw new AccessDeniedHttpException();
     }
 
-    $nids = $request->request->get('node_ids');
-    if (!isset($nids)) {
+    if (!$request->request->has('node_ids')) {
       throw new NotFoundHttpException();
     }
+    $nids = $request->request->all('node_ids');
     return new JsonResponse(history_read_multiple($nids));
   }
 
diff --git a/core/modules/jsonapi/src/Controller/EntityResource.php b/core/modules/jsonapi/src/Controller/EntityResource.php
index 9ce8a725ce2d..541fbd06795a 100644
--- a/core/modules/jsonapi/src/Controller/EntityResource.php
+++ b/core/modules/jsonapi/src/Controller/EntityResource.php
@@ -1235,13 +1235,13 @@ protected function entityExists(EntityInterface $entity) {
    */
   protected function getJsonApiParams(Request $request, ResourceType $resource_type) {
     if ($request->query->has('filter')) {
-      $params[Filter::KEY_NAME] = Filter::createFromQueryParameter($request->query->get('filter'), $resource_type, $this->fieldResolver);
+      $params[Filter::KEY_NAME] = Filter::createFromQueryParameter($request->query->all('filter'), $resource_type, $this->fieldResolver);
     }
     if ($request->query->has('sort')) {
-      $params[Sort::KEY_NAME] = Sort::createFromQueryParameter($request->query->get('sort'));
+      $params[Sort::KEY_NAME] = Sort::createFromQueryParameter($request->query->all()['sort']);
     }
     if ($request->query->has('page')) {
-      $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter($request->query->get('page'));
+      $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter($request->query->all('page'));
     }
     else {
       $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter(['page' => ['offset' => OffsetPage::DEFAULT_OFFSET, 'limit' => OffsetPage::SIZE_MAX]]);
diff --git a/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php b/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php
index 6d47e9d23437..742a57598a8b 100644
--- a/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php
+++ b/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php
@@ -146,10 +146,10 @@ protected static function generateContext(Request $request) {
       'account' => NULL,
       'sparse_fieldset' => NULL,
     ];
-    if ($request->query->get('fields')) {
+    if ($request->query->has('fields')) {
       $context['sparse_fieldset'] = array_map(function ($item) {
         return explode(',', $item);
-      }, $request->query->get('fields'));
+      }, $request->query->all('fields'));
     }
     return $context;
   }
diff --git a/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php b/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php
index 859cb805997a..1d43897ca912 100644
--- a/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php
+++ b/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\jsonapi\Kernel\Controller;
 
 use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\Http\InputBag;
 use Drupal\jsonapi\CacheableResourceResponse;
 use Drupal\jsonapi\ResourceType\ResourceType;
 use Drupal\jsonapi\JsonApiResource\Data;
@@ -13,7 +14,6 @@
 use Drupal\user\Entity\Role;
 use Drupal\user\Entity\User;
 use Drupal\user\RoleInterface;
-use Symfony\Component\HttpFoundation\ParameterBag;
 use Symfony\Component\HttpFoundation\Request;
 
 /**
@@ -187,7 +187,7 @@ protected function createEntityResource() {
    */
   public function testGetPagedCollection() {
     $request = Request::create('/jsonapi/node/article');
-    $request->query = new ParameterBag([
+    $request->query = new InputBag([
       'sort' => 'nid',
       'page' => [
         'offset' => 1,
@@ -216,7 +216,7 @@ public function testGetPagedCollection() {
    */
   public function testGetEmptyCollection() {
     $request = Request::create('/jsonapi/node/article');
-    $request->query = new ParameterBag(['filter' => ['id' => 'invalid']]);
+    $request->query = new InputBag(['filter' => ['id' => 'invalid']]);
 
     // Get the response.
     $resource_type = new ResourceType('node', 'article', NULL);
diff --git a/core/modules/menu_ui/src/Controller/MenuController.php b/core/modules/menu_ui/src/Controller/MenuController.php
index 7958c101ace4..e76ff6c5605e 100644
--- a/core/modules/menu_ui/src/Controller/MenuController.php
+++ b/core/modules/menu_ui/src/Controller/MenuController.php
@@ -50,7 +50,7 @@ public static function create(ContainerInterface $container) {
    */
   public function getParentOptions(Request $request) {
     $available_menus = [];
-    if ($menus = $request->request->get('menus')) {
+    if ($menus = $request->request->all('menus')) {
       foreach ($menus as $menu) {
         $available_menus[$menu] = $menu;
       }
diff --git a/core/modules/quickedit/src/QuickEditController.php b/core/modules/quickedit/src/QuickEditController.php
index 6a2a794ea2af..57982d8949ca 100644
--- a/core/modules/quickedit/src/QuickEditController.php
+++ b/core/modules/quickedit/src/QuickEditController.php
@@ -118,11 +118,11 @@ public static function create(ContainerInterface $container) {
    *   The JSON response.
    */
   public function metadata(Request $request) {
-    $fields = $request->request->get('fields');
-    if (!isset($fields)) {
+    if (!$request->request->has('fields')) {
       throw new NotFoundHttpException();
     }
-    $entities = $request->request->get('entities');
+    $fields = $request->request->all('fields');
+    $entities = $request->request->all('entities');
 
     $metadata = [];
     foreach ($fields as $field) {
@@ -196,10 +196,10 @@ private static function checkCsrf(Request $request, AccountInterface $account) {
    */
   public function attachments(Request $request) {
     $response = new AjaxResponse();
-    $editors = $request->request->get('editors');
-    if (!isset($editors)) {
+    if (!$request->request->has('editors')) {
       throw new NotFoundHttpException();
     }
+    $editors = $request->request->all('editors');
 
     $response->setAttachments($this->editorSelector->getEditorAttachments($editors));
 
@@ -257,7 +257,7 @@ public function fieldForm(EntityInterface $entity, $field_name, $langcode, $view
 
       // Re-render the updated field for other view modes (i.e. for other
       // instances of the same logical field on the user's page).
-      $other_view_mode_ids = $request->request->get('other_view_modes') ?: [];
+      $other_view_mode_ids = $request->request->all('other_view_modes');
       $other_view_modes = array_map($render_field_in_view_mode, array_combine($other_view_mode_ids, $other_view_mode_ids));
 
       $response->addCommand(new FieldFormSavedCommand($output, $other_view_modes));
diff --git a/core/modules/system/tests/modules/dialog_renderer_test/src/Render/MainContent/WideModalRenderer.php b/core/modules/system/tests/modules/dialog_renderer_test/src/Render/MainContent/WideModalRenderer.php
index 88f304e2bdde..1efc2570d087 100644
--- a/core/modules/system/tests/modules/dialog_renderer_test/src/Render/MainContent/WideModalRenderer.php
+++ b/core/modules/system/tests/modules/dialog_renderer_test/src/Render/MainContent/WideModalRenderer.php
@@ -60,7 +60,7 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
 
     // Determine the title: use the title provided by the main content if any,
     // otherwise get it from the routing information.
-    $options = $request->request->get('dialogOptions', []);
+    $options = $request->request->all('dialogOptions');
     // Override width option.
     switch ($this->mode) {
       case 'wide':
diff --git a/core/tests/Drupal/Tests/Core/Theme/AjaxBasePageNegotiatorTest.php b/core/tests/Drupal/Tests/Core/Theme/AjaxBasePageNegotiatorTest.php
index 3f7f4f41417a..5a51c0944173 100644
--- a/core/tests/Drupal/Tests/Core/Theme/AjaxBasePageNegotiatorTest.php
+++ b/core/tests/Drupal/Tests/Core/Theme/AjaxBasePageNegotiatorTest.php
@@ -3,6 +3,7 @@
 namespace Drupal\Tests\Core\Theme;
 
 use Drupal\Core\Access\CsrfTokenGenerator;
+use Drupal\Core\Http\InputBag;
 use Drupal\Core\Routing\RouteMatch;
 use Drupal\Core\Theme\AjaxBasePageNegotiator;
 use Drupal\Tests\UnitTestCase;
@@ -55,6 +56,7 @@ protected function setUp(): void {
    */
   public function testApplies($request_data, $expected) {
     $request = new Request([], $request_data);
+    $request->request = new InputBag($request->request->all());
     $route_match = RouteMatch::createFromRequest($request);
     $this->requestStack->push($request);
 
@@ -79,6 +81,7 @@ public function testDetermineActiveThemeValidToken() {
     $theme_token = 'valid_theme_token';
 
     $request = new Request([], ['ajax_page_state' => ['theme' => $theme, 'theme_token' => $theme_token]]);
+    $request->request = new InputBag($request->request->all());
     $this->requestStack->push($request);
     $route_match = RouteMatch::createFromRequest($request);
 
@@ -96,6 +99,7 @@ public function testDetermineActiveThemeInvalidToken() {
     $theme_token = 'invalid_theme_token';
 
     $request = new Request([], ['ajax_page_state' => ['theme' => $theme, 'theme_token' => $theme_token]]);
+    $request->request = new InputBag($request->request->all());
     $this->requestStack->push($request);
     $route_match = RouteMatch::createFromRequest($request);
 
@@ -115,6 +119,7 @@ public function testDetermineActiveThemeDefaultTheme() {
     $theme_token = '';
 
     $request = new Request([], ['ajax_page_state' => ['theme' => $theme, 'theme_token' => $theme_token]]);
+    $request->request = new InputBag($request->request->all());
     $this->requestStack->push($request);
     $route_match = RouteMatch::createFromRequest($request);
 
-- 
GitLab