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
Added support for editable association fields from type choice in Lis… #4449
Conversation
Controller/HelperController.php
Outdated
->getAssociationNames(); | ||
|
||
if (!in_array($field, $associations)) { | ||
return new JsonResponse(array( |
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.
Why not throw an exception instead ? This would be triggered by a programming error, right?
Controller/HelperController.php
Outdated
|
||
if (!$value) { | ||
return new JsonResponse(array( | ||
'status' => 'KO', |
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.
I was gonna say "use a status code, duh!", but then I saw that's what is being done in the whole class… anyway, please set the status code to 400.
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.
Statuscode 400 for all KO responses in method setObjectFieldValueAction(), right? Or only for my patched part?
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 a 404 would be even better in your case.
For other responses it depends, but it's not your responsability (of course if you want to rework that, it will a very welcome change though). Some should use 405, others should use 404, and others should use 400. Then, client-side, the statusCode
option of jQuery.ajax should be used instead of relying on this field status which contains… a code.
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.
Wow, nice job!! Tiny changes needed…
Controller/HelperController.php
Outdated
$context = $request->get('context'); | ||
|
||
$admin = $this->pool->getInstance($code); | ||
$admin->setRequest($request); | ||
|
||
// alter should be done by using a post method | ||
if (!$request->isXmlHttpRequest()) { | ||
return new JsonResponse(array('status' => 'KO', 'message' => 'Expected a XmlHttpRequest request header')); | ||
return new JsonResponse('Expected a XmlHttpRequest request header', 405); |
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.
"a" => "an" (the sound "ex" starts with a vowel)
Controller/HelperController.php
Outdated
|
||
if (!$value) { | ||
return new JsonResponse(sprintf('Edit failed, object with id "%s" not found in association "%s".', | ||
$originalValue, $field), 404); |
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.
This is not PSR-compliant, although not detected yet. Please put each sprintf
argument on its own line.
This is pedantic : it fixes no bug, and is not a visible improvement for the user (I think). If you agree, remove it from the changelog. |
Controller/HelperController.php
Outdated
'status' => 'KO', | ||
'message' => 'The field cannot be edit, editable option must be set to true', | ||
)); | ||
return new JsonResponse('The field cannot be edit, editable option must be set to true', 400); |
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.
"edit" => "edited"
Controller/HelperController.php
Outdated
} | ||
|
||
if ($request->getMethod() != 'POST') { | ||
return new JsonResponse('Expected a POST Request', 405); | ||
return new JsonResponse('Expected an POST Request', 405); |
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.
Post starts with a consonant sound, so "a"
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.
Oops!
Can you add some tests here : https://github.com/sonata-project/SonataAdminBundle/blob/3.x/Tests/Controller/HelperControllerTest.php ? Could be merged anyway if you can't, couldn't it @sonata-project/contributors ? |
@sonata-project/contributors please review |
@sonata-project/contributors how is this BC break compatible with semver? Tagging this as 3.17 broke compability with current |
Can you elaborate? Where precisely is the BC-break? |
The javascript explicitly checks for the I don't know if any other libraries depend on those responses. Changing API response syntax is a breaking change to me 🙂 |
It clearly isn't, I just wasn't aware that was part of a public API. Would you kindly make a PR that would restore the array, but keeps the status code? Also, we should deprecate this key, but I'm can't see how to achieve that with JSON. In the future, the page bundle and all other dependent bundles should rely on standard http status codes instead of custom |
Effectively it was a bc break in my code |
I am targeting this branch, because this is new feature with BC.
Changelog
To do
Subject
Added support for editable association fields from type choice in ListMapper, also added new field description option class. As example: