Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Some default configuration for the plupload widget is created at:
- File plupload.libraries.yml: Static
- hook_library_info_alter (): More or less dynamic, depending on server settings
These configurations should make their way to the Drupal.behaviors.plupload javascript behaviour, but they don't.
This can be easily tested around lines 32-34 from plupload.js:
var defaultSettings = settings.plupload['_default'] ? settings.plupload['_default'] : {};
var elementSettings = (id && settings.plupload[id]) ? settings.plupload[id] : {};
var pluploadSettings = $.extend({}, defaultSettings, elementSettings);
console.log(settings.plupload);console.log(pluploadSettings);
Only settings defined at PlUploadFile::preRenderPlUploadFile() appear on the javascript, so very useful settings like unique_names, max_file_size, chunk_size do not get an appropiate default.
Comment | File | Size | Author |
---|---|---|---|
#2 | default_settings_ignored-2592641-2.patch | 783 bytes | budalokko |
Comments
Comment #2
budalokko CreditAttribution: budalokko commentedAttached patch solves the problem. It loads the default settings on the form element too, so they are available in Drupal.behaviors.plupload.
I have compared our way of defining JavaScript settings with some other modules (color, locale, js_example) and they don't define their settings in MODULENAME.libraries.yml and hook_library_info_alter as we do. They usually build the settings directly at $element['#attached']['drupalSettings'].
In this patch I have kept the definitions in MODULENAME.libraries.yml and hook_library_info_alter because the dynamic parts of the settings (those calculated in plupload_library_info_alter) seem reasonable to be calculated once and kept until cache rebuild, instead of calculating them on each page load.
Comment #3
budalokko CreditAttribution: budalokko commented