Issue #3162016 by longwave, andypost, Hardik_Patel_12, catch, alexpott, daffie, Kristen Pol: [Symfony 6] Retrieving a non-string value from "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated

merge-requests/629/head
Alex Pott 2021-05-27 21:07:25 +01:00
parent 2c709ec12f
commit 8b8fc1eff7
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
20 changed files with 74 additions and 40 deletions

View File

@ -128,7 +128,7 @@ class AjaxResponseAttachmentsProcessor implements AttachmentsResponseProcessorIn
* An array of commands ready to be returned as JSON. * An array of commands ready to be returned as JSON.
*/ */
protected function buildAttachmentsCommands(AjaxResponse $response, Request $request) { 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. // Aggregate CSS/JS if necessary, but only during normal site operation.
$optimize_css = !defined('MAINTENANCE_MODE') && $this->config->get('css.preprocess'); $optimize_css = !defined('MAINTENANCE_MODE') && $this->config->get('css.preprocess');

View File

@ -31,7 +31,7 @@ class QueryArgsCacheContext extends RequestStackCacheContextBase implements Calc
return ($value !== NULL) ? $value : ''; return ($value !== NULL) ? $value : '';
} }
elseif ($this->requestStack->getCurrentRequest()->query->has($query_arg)) { 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)) { if (is_array($value)) {
return http_build_query($value); return http_build_query($value);
} }

View File

@ -61,7 +61,7 @@ class DialogRenderer implements MainContentRendererInterface {
$title = isset($main_content['#title']) ? $main_content['#title'] : $this->titleResolver->getTitle($request, $route_match->getRouteObject()); $title = isset($main_content['#title']) ? $main_content['#title'] : $this->titleResolver->getTitle($request, $route_match->getRouteObject());
// Determine the dialog options and the target for the OpenDialogCommand. // 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); $target = $this->determineTargetSelector($options, $route_match);
$response->addCommand(new OpenDialogCommand($target, $title, $content, $options)); $response->addCommand(new OpenDialogCommand($target, $title, $content, $options));

View File

@ -31,7 +31,7 @@ class ModalRenderer extends DialogRenderer {
// Determine the title: use the title provided by the main content if any, // Determine the title: use the title provided by the main content if any,
// otherwise get it from the routing information. // otherwise get it from the routing information.
$options = $request->request->get('dialogOptions', []); $options = $request->request->all('dialogOptions');
$response->addCommand(new OpenModalDialogCommand($title, $content, $options)); $response->addCommand(new OpenModalDialogCommand($title, $content, $options));
return $response; return $response;

View File

@ -64,7 +64,7 @@ class OffCanvasRenderer extends DialogRenderer {
// Determine the title: use the title provided by the main content if any, // Determine the title: use the title provided by the main content if any,
// otherwise get it from the routing information. // 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)); $response->addCommand(new OpenOffCanvasDialogCommand($title, $content, $options, NULL, $this->position));
return $response; return $response;
} }

View File

@ -65,7 +65,7 @@ class AjaxBasePageNegotiator implements ThemeNegotiatorInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function applies(RouteMatchInterface $route_match) { 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']); return !empty($ajax_page_state['theme']) && isset($ajax_page_state['theme_token']);
} }
@ -73,7 +73,7 @@ class AjaxBasePageNegotiator implements ThemeNegotiatorInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function determineActiveTheme(RouteMatchInterface $route_match) { 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']; $theme = $ajax_page_state['theme'];
$token = $ajax_page_state['theme_token']; $token = $ajax_page_state['theme_token'];

View File

@ -337,11 +337,11 @@ class CommentController extends ControllerBase {
throw new AccessDeniedHttpException(); throw new AccessDeniedHttpException();
} }
$nids = $request->request->get('node_ids'); if (!$request->request->has('node_ids') || !$request->request->has('field_name')) {
$field_name = $request->request->get('field_name');
if (!isset($nids)) {
throw new NotFoundHttpException(); throw new NotFoundHttpException();
} }
$nids = $request->request->all('node_ids');
$field_name = $request->request->get('field_name');
// Only handle up to 100 nodes. // Only handle up to 100 nodes.
$nids = array_slice($nids, 0, 100); $nids = array_slice($nids, 0, 100);

View File

@ -60,15 +60,15 @@ class ContextualController implements ContainerInjectionInterface {
* @see contextual_preprocess() * @see contextual_preprocess()
*/ */
public function render(Request $request) { public function render(Request $request) {
$ids = $request->request->get('ids'); if (!$request->request->has('ids')) {
if (!isset($ids)) {
throw new BadRequestHttpException('No contextual ids specified.'); throw new BadRequestHttpException('No contextual ids specified.');
} }
$ids = $request->request->all('ids');
$tokens = $request->request->get('tokens'); if (!$request->request->has('tokens')) {
if (!isset($tokens)) {
throw new BadRequestHttpException('No contextual ID tokens specified.'); throw new BadRequestHttpException('No contextual ID tokens specified.');
} }
$tokens = $request->request->all('tokens');
$rendered = []; $rendered = [];
foreach ($ids as $key => $id) { foreach ($ids as $key => $id) {

View File

@ -206,7 +206,7 @@ class FieldConfigEditForm extends EntityForm {
$this->messenger()->addStatus($this->t('Saved %label configuration.', ['%label' => $this->entity->getLabel()])); $this->messenger()->addStatus($this->t('Saved %label configuration.', ['%label' => $this->entity->getLabel()]));
$request = $this->getRequest(); $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'); $request->query->remove('destinations');
$form_state->setRedirectUrl($next_destination); $form_state->setRedirectUrl($next_destination);
} }

View File

@ -229,7 +229,7 @@ class FieldStorageConfigEditForm extends EntityForm {
$this->entity->save(); $this->entity->save();
$this->messenger()->addStatus($this->t('Updated field %label field settings.', ['%label' => $field_label])); $this->messenger()->addStatus($this->t('Updated field %label field settings.', ['%label' => $field_label]));
$request = $this->getRequest(); $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'); $request->query->remove('destinations');
$form_state->setRedirectUrl($next_destination); $form_state->setRedirectUrl($next_destination);
} }

View File

@ -28,10 +28,10 @@ class HistoryController extends ControllerBase {
throw new AccessDeniedHttpException(); throw new AccessDeniedHttpException();
} }
$nids = $request->request->get('node_ids'); if (!$request->request->has('node_ids')) {
if (!isset($nids)) {
throw new NotFoundHttpException(); throw new NotFoundHttpException();
} }
$nids = $request->request->all('node_ids');
return new JsonResponse(history_read_multiple($nids)); return new JsonResponse(history_read_multiple($nids));
} }

View File

@ -1217,13 +1217,13 @@ class EntityResource {
*/ */
protected function getJsonApiParams(Request $request, ResourceType $resource_type) { protected function getJsonApiParams(Request $request, ResourceType $resource_type) {
if ($request->query->has('filter')) { 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')) { 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'] ?? NULL);
} }
if ($request->query->has('page')) { 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 { else {
$params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter(['page' => ['offset' => OffsetPage::DEFAULT_OFFSET, 'limit' => OffsetPage::SIZE_MAX]]); $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter(['page' => ['offset' => OffsetPage::DEFAULT_OFFSET, 'limit' => OffsetPage::SIZE_MAX]]);

View File

@ -146,10 +146,10 @@ class ResourceResponseSubscriber implements EventSubscriberInterface {
'account' => NULL, 'account' => NULL,
'sparse_fieldset' => NULL, 'sparse_fieldset' => NULL,
]; ];
if ($request->query->get('fields')) { if ($request->query->has('fields')) {
$context['sparse_fieldset'] = array_map(function ($item) { $context['sparse_fieldset'] = array_map(function ($item) {
return explode(',', $item); return explode(',', $item);
}, $request->query->get('fields')); }, $request->query->all('fields'));
} }
return $context; return $context;
} }

View File

@ -3,6 +3,7 @@
namespace Drupal\Tests\jsonapi\Kernel\Controller; namespace Drupal\Tests\jsonapi\Kernel\Controller;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Http\InputBag;
use Drupal\jsonapi\CacheableResourceResponse; use Drupal\jsonapi\CacheableResourceResponse;
use Drupal\jsonapi\ResourceType\ResourceType; use Drupal\jsonapi\ResourceType\ResourceType;
use Drupal\jsonapi\JsonApiResource\Data; use Drupal\jsonapi\JsonApiResource\Data;
@ -13,7 +14,6 @@ use Drupal\Tests\jsonapi\Kernel\JsonapiKernelTestBase;
use Drupal\user\Entity\Role; use Drupal\user\Entity\Role;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
use Drupal\user\RoleInterface; use Drupal\user\RoleInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
@ -186,7 +186,7 @@ class EntityResourceTest extends JsonapiKernelTestBase {
*/ */
public function testGetPagedCollection() { public function testGetPagedCollection() {
$request = Request::create('/jsonapi/node/article'); $request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag([ $request->query = new InputBag([
'sort' => 'nid', 'sort' => 'nid',
'page' => [ 'page' => [
'offset' => 1, 'offset' => 1,
@ -215,7 +215,7 @@ class EntityResourceTest extends JsonapiKernelTestBase {
*/ */
public function testGetEmptyCollection() { public function testGetEmptyCollection() {
$request = Request::create('/jsonapi/node/article'); $request = Request::create('/jsonapi/node/article');
$request->query = new ParameterBag(['filter' => ['id' => 'invalid']]); $request->query = new InputBag(['filter' => ['id' => 'invalid']]);
// Get the response. // Get the response.
$resource_type = new ResourceType('node', 'article', NULL); $resource_type = new ResourceType('node', 'article', NULL);

View File

@ -3,7 +3,9 @@
namespace Drupal\media_library; namespace Drupal\media_library;
use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Crypt;
use Drupal\Core\Http\InputBag;
use Drupal\Core\Site\Settings; use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\InputBag as SymfonyInputBag;
use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@ -94,15 +96,20 @@ class MediaLibraryState extends ParameterBag {
*/ */
public static function fromRequest(Request $request) { public static function fromRequest(Request $request) {
$query = $request->query; $query = $request->query;
// Replace ParameterBag with InputBag for compatibility with Symfony 5.
// @todo Remove this when Symfony 4 is no longer supported.
if (!($query instanceof InputBag || $query instanceof SymfonyInputBag)) {
$query = new InputBag($query->all());
}
// Create a MediaLibraryState object through the create method to make sure // Create a MediaLibraryState object through the create method to make sure
// all validation runs. // all validation runs.
$state = static::create( $state = static::create(
$query->get('media_library_opener_id'), $query->get('media_library_opener_id'),
$query->get('media_library_allowed_types', []), $query->all('media_library_allowed_types'),
$query->get('media_library_selected_type'), $query->get('media_library_selected_type'),
$query->get('media_library_remaining'), $query->get('media_library_remaining'),
$query->get('media_library_opener_parameters', []) $query->all('media_library_opener_parameters')
); );
// The request parameters need to contain a valid hash to prevent a // The request parameters need to contain a valid hash to prevent a
@ -222,7 +229,7 @@ class MediaLibraryState extends ParameterBag {
* The media type IDs. * The media type IDs.
*/ */
public function getAllowedTypeIds() { public function getAllowedTypeIds() {
return $this->get('media_library_allowed_types'); return $this->all('media_library_allowed_types');
} }
/** /**
@ -266,7 +273,29 @@ class MediaLibraryState extends ParameterBag {
* An associative array of all opener-specific parameter values. * An associative array of all opener-specific parameter values.
*/ */
public function getOpenerParameters() { public function getOpenerParameters() {
return $this->get('media_library_opener_parameters', []); return $this->all('media_library_opener_parameters');
}
/**
* Returns the parameters.
*
* @param string|null $key
* The name of the parameter to return or null to get them all.
*
* @return array
* An array of parameters.
*/
public function all(string $key = NULL): array {
if ($key === NULL) {
return $this->parameters;
}
$value = $this->parameters[$key] ?? [];
if (!is_array($value)) {
throw new \UnexpectedValueException(sprintf('Unexpected value for parameter "%s": expecting "array", got "%s".', $key, get_debug_type($value)));
}
return $value;
} }
} }

View File

@ -50,7 +50,7 @@ class MenuController extends ControllerBase {
*/ */
public function getParentOptions(Request $request) { public function getParentOptions(Request $request) {
$available_menus = []; $available_menus = [];
if ($menus = $request->request->get('menus')) { if ($menus = $request->request->all('menus')) {
foreach ($menus as $menu) { foreach ($menus as $menu) {
$available_menus[$menu] = $menu; $available_menus[$menu] = $menu;
} }

View File

@ -116,11 +116,11 @@ class QuickEditController extends ControllerBase {
* The JSON response. * The JSON response.
*/ */
public function metadata(Request $request) { public function metadata(Request $request) {
$fields = $request->request->get('fields'); if (!$request->request->has('fields')) {
if (!isset($fields)) {
throw new NotFoundHttpException(); throw new NotFoundHttpException();
} }
$entities = $request->request->get('entities'); $fields = $request->request->all('fields');
$entities = $request->request->all('entities');
$metadata = []; $metadata = [];
foreach ($fields as $field) { foreach ($fields as $field) {
@ -147,7 +147,7 @@ class QuickEditController extends ControllerBase {
// If the entity information for this field is requested, include it. // If the entity information for this field is requested, include it.
$entity_id = $entity->getEntityTypeId() . '/' . $entity_id; $entity_id = $entity->getEntityTypeId() . '/' . $entity_id;
if (is_array($entities) && in_array($entity_id, $entities) && !isset($metadata[$entity_id])) { if (in_array($entity_id, $entities, TRUE) && !isset($metadata[$entity_id])) {
$metadata[$entity_id] = $this->metadataGenerator->generateEntityMetadata($entity); $metadata[$entity_id] = $this->metadataGenerator->generateEntityMetadata($entity);
} }
@ -168,10 +168,10 @@ class QuickEditController extends ControllerBase {
*/ */
public function attachments(Request $request) { public function attachments(Request $request) {
$response = new AjaxResponse(); $response = new AjaxResponse();
$editors = $request->request->get('editors'); if (!$request->request->has('editors')) {
if (!isset($editors)) {
throw new NotFoundHttpException(); throw new NotFoundHttpException();
} }
$editors = $request->request->all('editors');
$response->setAttachments($this->editorSelector->getEditorAttachments($editors)); $response->setAttachments($this->editorSelector->getEditorAttachments($editors));
@ -229,7 +229,7 @@ class QuickEditController extends ControllerBase {
// Re-render the updated field for other view modes (i.e. for other // Re-render the updated field for other view modes (i.e. for other
// instances of the same logical field on the user's page). // 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)); $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)); $response->addCommand(new FieldFormSavedCommand($output, $other_view_modes));

View File

@ -60,7 +60,7 @@ class WideModalRenderer extends ModalRenderer {
// Determine the title: use the title provided by the main content if any, // Determine the title: use the title provided by the main content if any,
// otherwise get it from the routing information. // otherwise get it from the routing information.
$options = $request->request->get('dialogOptions', []); $options = $request->request->all('dialogOptions');
// Override width option. // Override width option.
switch ($this->mode) { switch ($this->mode) {
case 'wide': case 'wide':

View File

@ -66,7 +66,7 @@ class QueryParameter extends ArgumentDefaultPluginBase implements CacheableDepen
$current_request = $this->view->getRequest(); $current_request = $this->view->getRequest();
if ($current_request->query->has($this->options['query_param'])) { if ($current_request->query->has($this->options['query_param'])) {
$param = $current_request->query->get($this->options['query_param']); $param = $current_request->query->all()[$this->options['query_param']] ?? NULL;
if (is_array($param)) { if (is_array($param)) {
$conjunction = ($this->options['multiple'] == 'and') ? ',' : '+'; $conjunction = ($this->options['multiple'] == 'and') ? ',' : '+';
$param = implode($conjunction, $param); $param = implode($conjunction, $param);

View File

@ -3,6 +3,7 @@
namespace Drupal\Tests\Core\Theme; namespace Drupal\Tests\Core\Theme;
use Drupal\Core\Access\CsrfTokenGenerator; use Drupal\Core\Access\CsrfTokenGenerator;
use Drupal\Core\Http\InputBag;
use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Theme\AjaxBasePageNegotiator; use Drupal\Core\Theme\AjaxBasePageNegotiator;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
@ -55,6 +56,7 @@ class AjaxBasePageNegotiatorTest extends UnitTestCase {
*/ */
public function testApplies($request_data, $expected) { public function testApplies($request_data, $expected) {
$request = new Request([], $request_data); $request = new Request([], $request_data);
$request->request = new InputBag($request->request->all());
$route_match = RouteMatch::createFromRequest($request); $route_match = RouteMatch::createFromRequest($request);
$this->requestStack->push($request); $this->requestStack->push($request);
@ -79,6 +81,7 @@ class AjaxBasePageNegotiatorTest extends UnitTestCase {
$theme_token = 'valid_theme_token'; $theme_token = 'valid_theme_token';
$request = new Request([], ['ajax_page_state' => ['theme' => $theme, 'theme_token' => $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); $this->requestStack->push($request);
$route_match = RouteMatch::createFromRequest($request); $route_match = RouteMatch::createFromRequest($request);
@ -96,6 +99,7 @@ class AjaxBasePageNegotiatorTest extends UnitTestCase {
$theme_token = 'invalid_theme_token'; $theme_token = 'invalid_theme_token';
$request = new Request([], ['ajax_page_state' => ['theme' => $theme, 'theme_token' => $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); $this->requestStack->push($request);
$route_match = RouteMatch::createFromRequest($request); $route_match = RouteMatch::createFromRequest($request);
@ -115,6 +119,7 @@ class AjaxBasePageNegotiatorTest extends UnitTestCase {
$theme_token = ''; $theme_token = '';
$request = new Request([], ['ajax_page_state' => ['theme' => $theme, 'theme_token' => $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); $this->requestStack->push($request);
$route_match = RouteMatch::createFromRequest($request); $route_match = RouteMatch::createFromRequest($request);