-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
Block validation doesn't work properly in page composer #1318
Comments
For the record, the validate method is deprecated in Sonata 3 and will be removed in Sonata 4. |
Hi @VincentLanglet , I know. What's the suggested alternative method and will it solve the issue describred? |
I don't know the ImmutableArrayType But if it was an classic TextType, the recommended way would be
like you would have done with a Symfony form |
Ok @VincentLanglet I'll give it a try. BTW, where I can find an example of how correctly implement a block service (I mean without deprecations etc.)? Because all sonata packages, even the sandbox, are missing that or are quite outdated. Even the documentation here: https://sonata-project.org/bundles/block/master/doc/reference/your_first_block.html is using the |
Oh, I thought it was an admin. I saw @jordisala1991 using it in sonata-project/SonataMediaBundle#1963 BTW, in the doc it's And shouldn't be this issue in SonataBlockBundle instead ? |
@VincentLanglet I think is still relevant to SonataPageBundle because (if I'm right) it's something related how to returned JSON is parsed / error has shown. I'll try with |
@VincentLanglet with - EDIT: found a clue: Basically, the problem is that page Composer works with HTML returned by the server, with error messages displayed inside it. But that commit changed the returned response to be JSON instead. |
@VincentLanglet I've found the issue and the resolution 🥳 . I can't make a PR because What's happening then? Well, this commit changed the way Ajax requests are threated. This is the related PR. To put it simple:
private function handleXmlHttpRequestErrorResponse(Request $request, FormInterface $form): ?JsonResponse
{
if (empty(array_intersect(['application/json', '*/*'], $request->getAcceptableContentTypes()))) {
// Do not handle the XmlHttpRequest
return null;
}
// Return a JSON response
} Before that commit, the same methods looks like: private function handleXmlHttpRequestErrorResponse(Request $request, FormInterface $form): ?JsonResponse
{
if (!\in_array('application/json', $request->getAcceptableContentTypes(), true)) {
// Do not handle the XmlHttpRequest
return null;
}
// Return a JSON response
}
Easy fix is adding an headers: {
Accept: 'text/html, application/xhtml+xml;'
}, |
Shouldn't you edit directly |
Well I think that one should edit For some reason when i run that command, assets are not created, that is sonata-page.back.js
sonata-page.back.min.js |
@VincentLanglet do you need anything else? |
Someone with the time to do a PR to edit all of these files ^^' |
I'll do it if someone (who?) can explain me the build process for the assets 🤣 |
Is this project still active? It's a majoir issue I think, it's so sad seeing no one cares :( |
The asset |
Thanks @VincentLanglet I've submitted the PR, can you please check it and maybe release, so we can see if |
It will be in the next release: #1321 |
I confirm that it works now, thanks @VincentLanglet |
Environment
Sonata packages
show
Symfony packages
show
PHP version
Subject
Block validation doesn't work properly in page composer. I've used Sonata in many projects and block validation was working properly; I can't track which update broke that thing.
Steps to reproduce
NotBlank
constraintExpected results
The error (a red error text) is show right down the field itself.
Actual results
No errors is shown. The (browser) network console tab reports a 400 HTTP error. It seems that the returned JSON is fine, but the JavaScript fails updating the view:
On the other hand, creating the same block from the interface under "blocks" works just fine:
The text was updated successfully, but these errors were encountered: