Unverified Commit 8f0f57f3 authored by alexpott's avatar alexpott
Browse files

Issue #3162016 by longwave, andypost, Hardik_Patel_12, catch, alexpott,...

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

(cherry picked from commit 8b8fc1ef)
parent fbcaae76
......@@ -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');
......
......@@ -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);
}
......
......@@ -61,7 +61,7 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
$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.
$options = $request->request->get('dialogOptions', []);
$options = $request->request->all('dialogOptions');
$target = $this->determineTargetSelector($options, $route_match);
$response->addCommand(new OpenDialogCommand($target, $title, $content, $options));
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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'];
......
......@@ -337,11 +337,11 @@ 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);
......
......@@ -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) {
......
......@@ -206,7 +206,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);
}
......
......@@ -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);
}
......
......@@ -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));
}
......
......@@ -1217,13 +1217,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'] ?? NULL);
}
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]]);
......
......@@ -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;
}
......
......@@ -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;
/**
......@@ -186,7 +186,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,
......@@ -215,7 +215,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);
......
......@@ -3,7 +3,9 @@
namespace Drupal\media_library;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Http\InputBag;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\InputBag as SymfonyInputBag;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
......@@ -94,15 +96,20 @@ public static function create($opener_id, array $allowed_media_type_ids, $select
*/
public static function fromRequest(Request $request) {
$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
// all validation runs.
$state = static::create(
$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_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
......@@ -222,7 +229,7 @@ public function getOpenerId() {
* The media type IDs.
*/
public function getAllowedTypeIds() {
return $this->get('media_library_allowed_types');
return $this->all('media_library_allowed_types');
}
/**
......@@ -266,7 +273,29 @@ public function getAvailableSlots() {
* An associative array of all opener-specific parameter values.
*/
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;
}
}
......@@ -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;
}
......
......@@ -116,11 +116,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) {
......@@ -147,7 +147,7 @@ public function metadata(Request $request) {
// If the entity information for this field is requested, include it.
$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);
}
......@@ -168,10 +168,10 @@ public function metadata(Request $request) {
*/
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));
......@@ -229,7 +229,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));
......
......@@ -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':
......
......@@ -66,7 +66,7 @@ public function getArgument() {
$current_request = $this->view->getRequest();
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)) {
$conjunction = ($this->options['multiple'] == 'and') ? ',' : '+';
$param = implode($conjunction, $param);
......
......@@ -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 @@ public 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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment