The "entity_browser_file" Field Widget currently uses a table when displaying the current selection. This feels complex when you have a single-cardinality field, which can't be re-ordered and won't take up so much vertical space that a table header will be useful.
I've uploaded a patch which adds some conditionals logic to FileBrowserWidget::displayCurrentSelection(), as well as cleaning up the logic in FileBrowserWidget::massageFormValues() to fix a notice I encountered while making this change in addition to reducing the number of is_array calls in that function.
Let me know what you think!
Before

After

| Comment | File | Size | Author |
|---|---|---|---|
| #20 | entity_browser-single-value-widget-ux-2825555-20-D8.patch | 6 KB | Anonymous (not verified) |
| #20 | entity_browser-single-value-widget-ux-2825555-18-20.interdiff.txt | 575 bytes | Anonymous (not verified) |
| #17 | 1.4-2825555-14.patch | 2.47 KB | christiansanders |
Comments
Comment #2
slashrsm commentedNice improvement! Note that I wasn't able to test this yet so just general feedback.
How this behaves on mobile? I suspect it should work nice but we should check.
Can we add a bit of test coverage (for both notice and field widget UX change)?
With this kind of issues it is nice to have screenshots in the IS. Adding that.
Comment #3
marcoscanoI have the feeling that this issue has become obsolete with the latest improvements. @samuel.mortenson could you please confirm?
At least I'm not able to reproduce the "Before" screenshot indicated above with the latest -dev.
Thanks!
Comment #4
samuel.mortenson@marcoscano Yes, this is still a valid issue. You can replicate the before screenshot by installing the entity_browser_example module, visiting /node/add/entity_browser_test, expanding the "Image" fieldset (which is the only Image field), and uploading an Image.
Comment #5
marcoscanoTrue, thanks for that, and sorry for missing it.
I can confirm that the patch still applies, and that it passes manual testing :)
I also checked that apparently nothing looks broken on a mobile viewport:

Comment #7
saltednutDoes this need a 2.x reroll?
(From acquia/df, after switching to using acquia/lightning:dev-8.x-3.x)
Comment #8
samuel.mortensonRe-roll.
Comment #9
samuel.mortensonComment #10
saltednutWhat's left to get this in? Is there anything outstanding? It seems like a very simple, yet effective patch that is completely in line with the "future state" described by @dries in the keynote this week. We have been using this patch in front of prospects and customers on the Demo Framework distro for about a year and a half now.
Right now I have two patches both for this same view and it is an absolute nightmare getting composer patches to work in every scenario. We're ignoring patches and using a consolidated patch, but that doesn't always work. E.g. try making a composer project and including BLT + Lightning together with this patch. See #2877751: Inform users how many items they can add to a field that uses an entity browser as the failing/conflicting patch. Also proposed for the current sprint.
Perhaps you guys should just commit Sam's consolidated patch here: https://www.drupal.org/files/issues/2018-03-27/2877751-17_2825555-8_comb... and we can close both of these long standing, annoying issues that have been making my life hell with regard to composer trying to patch.
In short: Entity Browser needs these patches and it needs a new release. ✌️
Comment #11
phenaproximaLooks great, except for a couple of small things. Oh, and it needs tests :)
We should probably add a little help text in this case -- "No file selected" or something like that. Just to keep it consistent with the table.
This will cut off access to unlimited-cardinality fields. We should probably just check if $cardinality !== 1.
Nit: for flexibility, we could change explode() to preg_split() by whitespace.
Comment #12
christiansanders commentedSo I came across this issue whereby tabledrag.js was failing to re-order my files in the table. I've identified the issue (as discussed in this issue queue) with the #access key on the _weight element being incorrectly calculated.
I've added a patch that takes into account phenaproxima's comments.
I've left out point 1 because I personally can't see why this is needed (see my attached screenshot for why) - very open to being wrong btw! :)
Comment #13
christiansanders commentedOkay, so my colleague has pointed out I should have created the patch in a more sensible way! Ive also included point one as I didn't take into account the fact the cardinality might be 1.
Comment #14
james.williams:-)
Comment #16
james.williamsJust a guess here, I wonder if the test is failing because of the hardcoded '1' in these lines of
ImageFieldTest::: testImageFieldUsage():I think the '1' should be $this->image->id() maybe? That's only a total guess though. I don't know whether it's the node that's failed to load, or the image field list object, or even the first field item in it.
In terms of testing this change, I guess we need to ensure there's a test for a single-value image field, assert that the appropriate bits of text show before & after uploading the image to it and the multivalue field, as well as ensuring the ordering works for the multivalue field.
We could even go as far as adding a finite multivalue field to be tested in the same way too. Do we really want/need all those possible tests?
Comment #17
christiansanders commentedHere is a patch for the same issue but for the current stable version 1.4.
Comment #18
Anonymous (not verified) commentedComment #19
Anonymous (not verified) commentedComment #20
Anonymous (not verified) commentedRemoved the invalid "g" modifier from the `preg_split` call, updated the empty messages, renamed the render array empty message key and reduced code indentation.
Comment #21
Vidushi Mehta commentedComment #22
saltednutI think this might need a re-roll now that #2877751: Inform users how many items they can add to a field that uses an entity browser is in. Those two patches had always conflicted for us.
Comment #23
phenaproxima@brantwynn: I tried applying this patch to the HEAD of Entity Browser 8.x-2.x with
git apply --check, and it seemed to work without complaint...Comment #24
kevinfunk@SchnWalter's patch from #20 has been working great. Is there any reason this can't get committed?