Problem/Motivation
Currently File Browser and File Entity both implement a Field Widget that allows users to use Entity Browsers on File and Image fields. This happened because I (as the maintainer of File Browser) wanted the Field Widget, but didn't want a hard dependency on the File Entity module. I forked the Widget back in February (2016), and since then there have been some minor changes and bugfixes applied to both browsers. As far as I know File Browser has a larger user base (for the Widget) and has more bugfixes, but we'll need to review the changes in this issue to validate that.
Ultimately these modules are accomplishing the same task, and none of the code is module-specific, so I propose that we move this into Entity Browser to consolidate efforts.
File Entity's Field Widget: http://cgit.drupalcode.org/file_entity/tree/src/Plugin/Field/FieldWidget...
File Browser's Field Widget: http://cgit.drupalcode.org/file_browser/tree/src/Plugin/Field/FieldWidge...
Proposed resolution
Remove the individual Field Widgets and create a new Widget in Entity Browser for File and Image fields.
Remaining tasks
1) Write a patch to add a new Field Widget for using Entity Browser on Files and Images.
2) Write test coverage for this Widget to check that normal usage works.
3) File issues/patches for File Browser and File Entity to remove their individual Widgets and provide an upgrade path for users (not sure how this can be accomplished easily).
User interface changes
Existing users of each Field Widget may see small changes in the form, but for the most part the experiences are the same.
API/Data model changes
We're removing two Field Widgets and adding a new one, and we need to come up with a good way to migrate current users off of the old Widgets.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | interdiff.txt | 11.19 KB | slashrsm |
| #14 | 2763505_14.patch | 46.1 KB | slashrsm |
| #13 | entity-browser-file-2763505-13.patch | 41.93 KB | samuel.mortenson |
| #13 | interdiff-2763505-12-13.txt | 735 bytes | samuel.mortenson |
Comments
Comment #2
berdirFine with me :) Not sure what we'll do about the widget ID, though? Renaming it will break existing configuration?
Comment #3
samuel.mortensonThere are many options I can think of, none of which are perfect. My best idea is probably to:
1) Create a new Field Widget in Entity Browser that contains the best of both existing widgets.
2) Remove the body of both widgets in File Browser and Entity Browser and have them extend the new Entity Browser Field Widget.
3) Use a form alter in both File browser and Entity Browser to hide the deprecated widgets from the Form Display tab (unless it was already selected).
This has the benefit of not confusing new users with three widgets, and not requiring any action for existing users.
Thoughts?
Comment #4
samuel.mortensonSo I've been working no #3.2 and #3.3 by implementing a funny isApplicable method which only returns TRUE if the field definition is already using the file_browser field widget. It's pretty unique, so I'd like to get feedback on it as a solution for both File Browser and File Entity:
The alternative to this from my understanding is a form alter which checks if file_browser/file_entity_browser is already selected, and if it's not hide it from the dropdown.
Comment #5
samuel.mortensonHere's a first shot at this. My notes:
displayEntityBrowser()generic so that developers can pass any data they want to persist between reloads.file_validate()function. Core constraints were not used here as the formatting of our values can not easily match what core's FileValidationConstraintValidator expects. We typically deal with arrays of entities, and core expects a FileItem, which is hard to generate in non-field use-cases like form elements and CKEditor.getForm()implementation that child classes can call to override Widget configuration on-the-fly using a "widget_context" provided by something high up the chain (in this case, the field widget). This is useful for other use cases because now there's a generic way to override Widget configuration based on where it's used, without hard-coding anything. If widgets don't callWidgetBase::getForm(), they can still use widget_context or any other form state key in creative ways.I'm putting the issue into needs review so I can get some eyes on it.
Comment #8
samuel.mortensonFix tests.
Comment #9
berdirWe should use clearer widget class names IMHO, especially for "File" (FileBrowserWidget or so?). Also for EntityReference really, but that's a separate topic.
Per current coding standards, the purpose/context of classes should be clear even without the namespace.
Comment #10
samuel.mortenson@Berdir Agreed and fixed. Changing the EntityReference class name would cause many other problems (like breaking every contrib Field Widget) so I think we should address that in a new issue.
Comment #11
slashrsm commentedShould we document possible keys? At least in case of "selected_entities" it is quite important that key follows exactly the pattern that the rest of EB is using.
Maybe document "selected_entities" and "validators" + state that arbitrary values can be added?
Missing doc descriptions.
Image style is only used if this is image field and view mode is default. We should explain that or (even better) hide it when it is not relevant.
Also using both short and long array syntax.
Comment #12
samuel.mortenson#11.1/#11.2 - Done.
#11.3 - I did both - hid the settings form element if the field type wasn't image, made the description for "preview_image_style" more descriptive and hid the image style from the settings summary if it isn't relevant.
Interdiff is huge because I realized that I change the class name of the Field Widget without changing the file name.
Comment #13
samuel.mortensonStupid mistake, for some reason I remembered #hidden being a valid form api setting.
Comment #14
slashrsm commentedReroll after #2766663: Rename "EntityReference" widget class name to something more meaningful and CodeSniffer fixes.
Comment #16
slashrsm commentedCommitted. Thank you!
Also created a follow-up in File entity: #2767185: [Follow-up] Deprecate file/image field widgets which were moved in the Entity browser.
Comment #17
samuel.mortenson#2767373: FileBrowserWidget improperly limits validation errors on the remove button. is a quick follow up bugfix that could use a review/commit.