Fix summernote fields#5946
Conversation
Improve the Summernote CRUD field: detect Backpack UI theme and load corresponding Summernote theme (bs5/bs4/lite), map app locales to Summernote locale codes and conditionally include language files, and set the editor lang option. Add explicit ajax-upload endpoint attribute and improve image upload handling (use ajax-upload-endpoint fallback, support repeatable field param names, better XHR error handling, remove previous error messages and render server validation errors as invalid-feedback). Minor options/defaults and formatting tweaks for CSS/JS asset inclusion and callbacks initialization.
Add CSS to ensure the Summernote toolbar (card-header.note-toolbar) is displayed in the editor frame. Also tidy up template indentation and formatting in the blade file and JS basset block for readability; no functional changes to the upload handling or callbacks were made.
Use PHP string concatenation for @basset calls so $summernoteTheme and $fullLocale resolve correctly, and make the bassetBlock locale-specific for per-locale JS. Add type="text/css" to the style tag, tidy up indentation/whitespace and normalize JS function spacing and event handler signatures. These changes ensure correct asset loading and improve code consistency.
|
@tabacitu Could you please review the code for me? |
|
Hello @TanNhatCMS, Thanks for the PR. I agree there are some improvements we can do in this field. There is a known issue when using We worked on a possible solution in Basset v2, but we are not totally happy with it. It works, but the ergonomics are not great: CRUD/src/BackpackServiceProvider.php Line 71 in 43dcca5 It’s also used to load those config files because they require run-time evaluation. We haven’t really “publicized” this feature because, like I said, we are not 100% happy with it, and we probably need to spend more time on this topic. But the main idea is something similar to what we are doing for the elFinder manager: When you run As you can see, the usability is not very good or polished. If we now wanted to add the same “map” for the Summernote languages, we would need to add more logic to the provider… and I don’t think that’s a good approach. I think we probably need something similar to a “routing” system, but for assets. Something like this: // say you create an assets.php file in your app.
// basset knows how to replace the `lang` placeholder by looping through
// the available languages in your app, but it does not know how to resolve
// `custom`. So you should be able to register "resolvers" for custom
// parameters that basset does not know about.
Basset::resolveWith('custom', function () {
// if theme is core ui bla bla bla
return 'bs5';
});
// now that you registered the `custom` resolver, you can register
// your "dynamic asset":
Basset::asset('my-dynamic-asset', 'https://myasset.{lang}.something.{custom}.js');
// and then use it in your views like:
@basset('my-dynamic-asset')In the above example (and similar to what currently happens with With the current state of the I hope I will have some time soon to work on this. I think it’s a very important missing feature, but it needs to be solved upstream in Sorry for the late response. Feel free to ask any questions 👍 |
Pull Request Description
WHY
BEFORE – What was wrong?
Summernote always loaded the
summernote-litebuild, which is not fully compatible with Backpack themes based on Bootstrap 4 or Bootstrap 5.No automatic language loading based on the application's locale.
No safe fallback when the locale is not supported by Summernote.
The image upload logic was unclear and partially duplicated.
Critical issue:
data-ajax-upload-endpointwas previously defined inside a<script>wrapped in@bassetBlock, which caused Basset compilation errors:@bassetBlock.AFTER – What is happening now?
Summernote now automatically loads the correct build based on the active Backpack theme (
lite,bs4, orbs5).Automatic loading of the correct Summernote language file based on the application's locale.
Unsupported locales safely fall back to
en-US.Image upload works reliably because:
data-ajax-upload-endpointis now placed directly in the HTML markup.Cleaner, more maintainable code.
Improved compatibility with multiple Backpack themes and multilingual setups.
HOW
Technical explanation
data-ajax-upload-endpointout of the@bassetBlockand into the textarea’s HTML attributes, solving Basset compilation issues.onChange,disable,enable, etc.) intact.Is this a breaking change?
No.
Existing Summernote fields continue working normally.
This PR only introduces improvements, better compatibility, and a fix for the upload endpoint bug.
Testing Instructions
Image Upload
Theme Compatibility
backpack.theme-coreuiv2(Bootstrap 4)backpack.theme-coreuiv4andbackpack.theme-tabler(Bootstrap 5)Locale Support
APP_LOCALE=vi→ loadssummernote-vi-VN.jsAPP_LOCALE=ko→ loadssummernote-ko-KR.jsen-USRepeatable Fields
Modal Rendering