-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batch action $allItems needs to be an boolean #6251
Batch action $allItems needs to be an boolean #6251
Conversation
src/Controller/CRUDController.php
Outdated
$request->request->replace(array_merge($request->request->all(), $data)); | ||
} else { | ||
$request->request->set('idx', $request->get('idx', [])); | ||
$request->request->set('all_elements', $request->get('all_elements', false)); | ||
|
||
$action = $request->get('action'); | ||
$idx = $request->get('idx'); | ||
$allElements = $request->get('all_elements'); | ||
$allElements = (bool) $request->get('all_elements'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using $request->request->getBoolean('all_elements')
? There is other get just above that could be changed too.
This code is a bit strange BTW, it first get the all_elements, then sets it to the request with the same value, and then get it again to assign it to a var. 🤔
3f3d14b
to
4449997
Compare
src/Controller/CRUDController.php
Outdated
$request->request->set('all_elements', $request->get('all_elements', false)); | ||
|
||
$allElements = $request->request->getBoolean('all_elements'); | ||
$request->request->set('all_elements', $allElements); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$request->request->set('all_elements', $allElements);
Is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe is in another parameter bag? That is the only explanation I can find for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a look at 9949121#diff-b1f1981b1ed9490b32c9bc83360655c3R396 where all this started, looks like it started using Request::get()
method and it has been like that since then, but taking into account that some lines above there is this check:
if (Request::METHOD_POST !== $restMethod)
I would say we can use in this block $request->request
safely (batch actions are sent through POST
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oké is this meaning that the line $request->request->set('all_elements', $allElements);
(line 377) can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is used to allow a combination of POST and GET parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is used to allow a combination of POST and GET parameters?
https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Controller/CRUDController.php#L410, apparently only POST
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you can POST to a url for example /delete?all_elements=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but in this case:
all_elements
: https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/CRUD/base_list.html.twig#L167action
: https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/CRUD/base_list.html.twig#L172idx
:<input type="checkbox" name="idx[]" value="{{ admin.id(object) }}">
I don't think they are later modified by JavaScript and seeing the <form>
tag: https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/CRUD/base_list.html.twig#L37 I would say that the URL only contains filter parameters.
And looking at how the request is built in CRUDControllerTest when using idx
or all_elements
.
So I think we can change this to just use $request->request
.
8f10580
to
66ca282
Compare
$action = $request->get('action'); | ||
$idx = $request->get('idx'); | ||
$allElements = $request->get('all_elements'); | ||
$action = $request->request->getAlnum('action'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does the getAlnum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alpha numeric ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/**
* Returns the alphabetic characters and digits of the parameter value.
*
* @param string $key The parameter key
* @param string $default The default value if the parameter key does not exist
*
* @return string The filtered value
*/
public function getAlnum($key, $default = '')
{
return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default));
}
Returns the alphabetic characters and digits of the parameter value.
and returns a string
value. Ref: https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/HttpFoundation/ParameterBag.php#L127
I think we can do this on |
66ca282
to
906a8b1
Compare
Thank you @nieuwenhuisen |
Batch action $allItems needs to be an boolean
Exception:
Argument 4 passed to Sonata\AdminBundle\Admin\AbstractAdmin::preBatchAction() must be of the type bool, string given, called in /projects/sonata-sandbox/vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php on line 452
I am targeting this branch, because there is the typehint added.
Changelog