Problem/Motivation

Dropzone upload widget does not provide any information about limitations set up on configuration page. Default image field has some additional information below upload field so the user is notified about limitations.

Default image field upload widget
Image Field

Current implementation of Dropzone upload widget
Dropzone Default

Proposed resolution

Implement similar functionality for Dropzone Widget, all the data is accessible in DropzoneJsEbWidget::getForm method in configuration of the widget, a form element that will show them is missing.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork dropzonejs-2852808

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

SurfinSpirit created an issue. See original summary.

apugacescu’s picture

Status: Active » Needs review
StatusFileSize
new1.18 KB
zerolab’s picture

Status: Needs review » Needs work
  1. +++ b/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php
    @@ -126,6 +126,18 @@ class DropzoneJsEbWidget extends WidgetBase {
    +      $descriptions[] = t('@size limit.', array('@size' => format_size(Bytes::toInt($config['settings']['max_filesize']))));
    

    Use array shorthand ['@size' => ...]

  2. +++ b/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php
    @@ -126,6 +126,18 @@ class DropzoneJsEbWidget extends WidgetBase {
    +      $descriptions[] = t('Allowed types: @extensions.', array('@extensions' => $config['settings']['extensions']));
    

    Use array shorthand ['@extensions' => ...]

  3. +++ b/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php
    @@ -126,6 +126,18 @@ class DropzoneJsEbWidget extends WidgetBase {
    +    $form['descriptions'] = [
    

    Would be cleaner not to add this if $descriptions is empty.

apugacescu’s picture

StatusFileSize
new1.21 KB

@zerolab Thanks for noticing this, it was inspired from field module, I've updated the patch.

apugacescu’s picture

Status: Needs work » Needs review
primsi’s picture

Thanks for this improvement. Would it make sense to add that in the dropzone element in dictDefaultMessage? This would then apply to all widgets and it might be a bit better from UX perspective.

primsi’s picture

Status: Needs review » Needs work

Putting this to Needs work. IMHO that's the right approach, happy to hear other arguments though.

apugacescu’s picture

StatusFileSize
new1.09 KB

@Primsi the initial thought was to have a consistent state with image field but use of dictDefaultMessage makes sense.

apugacescu’s picture

Status: Needs work » Needs review
a.milkovsky’s picture

StatusFileSize
new1.22 KB

Tried #8 - the
tags are rendered as a plain text. Adding a new patch

a.milkovsky’s picture

StatusFileSize
new1.38 KB
imclean’s picture

Hard coding these in the template doesn't seem flexible enough to me. Could it be abstracted in some way so it's easy to extend in future or by other modules? Something like:

$variables['file_info']['max_filesize'] = [
  'label' => t('Maximum filesize') . ': ',
  'value' => format_size(Bytes::toInt($element['#max_filesize']))
];
$variables['file_info']['extensions'] = [
  'label' => t('Extensions') . ': ',
  'value' =>  $element['#extensions']
];
{% for item in file_info %}
  <div>{{ item.label }}{{ item.value }}<div>
{% endfor %}
a.milkovsky’s picture

@imclean anybody can easily extend any template by simply copying it in the theme folder.

imclean’s picture

@a.milkovsky, true but there's less to modify if we don't have to update the template each time. I guess I was thinking longer term it could be good to extract any extra field information provided by any modules (e.g. base file field settings) from the context and automatically display them with no modifications to DropzoneJS.

roshkovanv’s picture

StatusFileSize
new5.85 KB

Added fields where description text can be adjusted

Status: Needs review » Needs work

The last submitted patch, 15: widget_upload-2852808-15.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

imclean’s picture

As an example of what I mean in #14, say you've installed a module which adds certain specific information. You then want to install another module which can also add some of its own information. How could either module modify the template so the data from both modules is displayed?

There can be only one template file used. If the data can be added in a hook somewhere then the information from both modules could easily be displayed without interfering with the other.

a.milkovsky’s picture

@imclean, I agree. Makes sense. Could you provide a patch? The idea of #15 looks good as well.

vitalym’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new6.65 KB
new809 bytes

Added missing schema changes for the description configs from #15. Also re-lolled the patch for the latest version - it should fix failing tests as well.

Status: Needs review » Needs work

The last submitted patch, 19: widget_upload-2852808-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

vitalym’s picture

Status: Needs work » Needs review
StatusFileSize
new7.33 KB
new700 bytes

Oops, forgot to adjust the test form. Here is new patch.

chuyenlv’s picture

StatusFileSize
new7.39 KB

Here is new patch for version 8.x-2.1. I recreate from #21.

mitchel432’s picture

StatusFileSize
new8.82 KB

Here is the new patch for version 8.x-2.3. I recreated from #22.

Status: Needs review » Needs work

The last submitted patch, 23: widget_upload-2852808-23.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

edysmp’s picture

Status: Needs work » Needs review
StatusFileSize
new8.82 KB

reroll

Status: Needs review » Needs work

The last submitted patch, 25: 2852808-25.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

edysmp’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 KB
new9.97 KB

Getting `Maximum size of files: 0 bytes`
Fixing this by checking if the field has a max_filesize setting set. fallback to the environment value set in the base plugin.

Status: Needs review » Needs work

The last submitted patch, 27: 2852808-26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

heddn’s picture

Status: Needs work » Needs review
StatusFileSize
new9.17 KB
heddn’s picture

StatusFileSize
new9.29 KB

Needed a re-roll.

hieuntnguyen’s picture

Version: 8.x-2.x-dev » 8.x-2.6
StatusFileSize
new7.53 KB
hieuntnguyen’s picture

StatusFileSize
new6.88 KB
hieuntnguyen’s picture

StatusFileSize
new7.55 KB
tim-diels’s picture

@hieuntnguyen, could you please elaborate why you uploaded 3 patches and what is different with #30?

heddn’s picture

Patch in #30 still applies just fine. I'm hiding 31-33.

tim-diels’s picture

Version: 8.x-2.6 » 8.x-2.x-dev
Status: Needs review » Reviewed & tested by the community

Thanks @heddn, we're using patch from #30 and works as expected and is a really nice addition.
Setting version to 2.X-dev as this only applies on latest dev. Let's hope this is added quickly.

The last submitted patch, 30: 2852808-30.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tim-diels’s picture

Status: Reviewed & tested by the community » Needs work

The patch needs work for coding standards and the dependency for the module token is missing in the test module.

heddn’s picture

Status: Needs work » Needs review
StatusFileSize
new9.07 KB

Re-roll of #30.

Status: Needs review » Needs work

The last submitted patch, 39: 2852808-39.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

chuyenlv’s picture

Re-roll of #39

heddn’s picture

Status: Needs work » Needs review
StatusFileSize
new9.95 KB
new1.37 KB

A little bit of a safer approach since render element is used in several places.

tim-diels’s picture

Status: Needs review » Needs work

Looks good, but will need config schema update as this prints out an error when validating with Config Inspector.

tim-diels’s picture

Status: Needs work » Needs review

Apologies, looks good for the schema part.

tim-diels’s picture

StatusFileSize
new9.99 KB

Re-roll of #42

tim-diels’s picture

In our eyes this is an important improvement to the module. We would love to see this committed. What can be done to get this committed?

pasha3371’s picture

StatusFileSize
new2.57 KB

Updated patch for D11 format_size() deprecation - the only difference in this patch and #45 is the inclusion of:
use Drupal\Core\StringTranslation\ByteSizeMarkup;
&
$replacements[$original] = ByteSizeMarkup::create(Bytes::toNumber($data['max_filesize']));

mitchel432’s picture

StatusFileSize
new10.05 KB

It appears that patch #47 missed a few files, but it does resolve the D11 issue.

tim-diels’s picture

Status: Needs review » Needs work

Thanks for the updated patch. I added this as a MR for a start point.

But we should build in the BC as this module still supports ^9.3 and ^10 and the new method only exist from 10.2 and upwards, see https://www.drupal.org/node/2999981

Please work in the MR from now on.

tim-diels’s picture

tim-diels’s picture

Made patch from #45 visible again as that is the one supporting untill D11.