Error message
> Drupal\Core\Config\ConfigException: Used entity browser selection display does not support preselection. in Drupal\entity_browser\SelectionDisplayBase->checkPreselectionSupport() (line 130 of modules/contrib/entity_browser/src/SelectionDisplayBase.php).
Cause
(from https://www.lullabot.com/articles/common-pitfalls-when-configuring-entit...)
Field widgets have a setting that allows you to define how the selection should be handled during the update process. This is called “Selection mode” and you can choose between the options “Append to selection,” “Prepend selection,” and “Edit selection”. As somewhat expected, if you choose an option like “Edit selection,” your browser must have been configured to have a “selection” available, which currently is only possible with the “Multi-step Selection Display” plugin. For example, if you choose the “No selection” plugin in the browser configuration while leaving this “Edit selection” setting on the field widget, you will end up with an error such as “Used entity browser selection display does not support pre-selection.”
Problems
A crash with a somewhat esoteric error message, in response to picking the wrong value in a UI form somewhere else, is not a good sitebuilder experience.
Comments
Comment #2
joachim commentedComment #3
slashrsm commentedThis happens because of misconfiguration. You are trying to use preselection with a plugin that does not support it.
Comment #4
joachim commentedIt's a bug that a misconfiguration causes a crash.
Comment #5
slashrsm commentedIt was done on purpose. We'd detect misconfiguration on entity browser creation time, but that is unfortunately not possible. When user is creating entity browser you can't predict in what kind of situations it will be used and this is the best solution that we've figured out so far.
Another option would be to silently ignore preselection, but that could lead to data loss. I think that failing loudly is still better than that.
I am open for ideas of course.
Comment #6
joachim commented> We'd detect misconfiguration on entity browser creation time, but that is unfortunately not possible.
Well there are two ways the problem can happen:
- A. User creates an EB, then uses it in a field widget and sets the configuration there in a way that's not compaible.
For that, it looks to me like you can use an '#element_validate' callback on your field widget's settingsForm(). Example in core: core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php
- B. User creates an EB, then uses it in a field widget, and then goes back to the EB and changes the configuration there in a way that's not compatible.
Here I guess you'd need to check where the EB is being used, and restrict the options for the Selection display plugin.
Comment #7
geerlingguy commentedThat'd be me. Just ran into this issue when trying to jigger the entity browser for a photo upload form into a more usable state. Instead it became a white screen of death state.
Comment #8
scotwith1tDitto. Certainly surprised me that this would crash the node edit form for the type using the "misconfigured field"...I'm trying to decipher just what "Used entity browser selection display does not support preselection" even means, can someone interpret the error message for me in layman's terms? What specifically isn't supported that I was able to select or set that the module now sees it as "misconfigured" for the field?
Comment #9
jonathanshawComment #10
gribnif commentedIf it's not possible to prevent the user from creating an entity browser that induces this error in the first place, you should at least report it in a more friendly way. The current method of throwing an uncaught exception is very bad UX. Show the error message at the top of the node edit page and include more details about what settings are wrong. Perhaps even include a direct link to the settings for the EB instance.
Comment #11
Angry Dan commentedThis wasted a few hours for me yesterday. At the very least you should put in an intelligible exception message because right now it makes no sense at all. Actually my workaround for most of the day was to just comment out the line that throws the exception in checkPreselectionSupport, and that worked fine for me.
And that there has to be an article entitled "Common Pitfalls When Configuring Entity Browser in Drupal 8" is absurd.
Marking as a bug because exceptions are never an expected behaviour
Marking as major because it "Trigger a PHP error through the user interface, but only under rare circumstances or affecting only a small percentage of all users, even if there is a workaround.". See https://www.drupal.org/node/45111.
Comment #12
joachim commented> Marking as a bug because exceptions are never an expected behaviour
+1 to that, and to the severity.
Comment #13
samuel.mortensonComment #14
eyal shalevThis issue was posted 2 years ago, and was marked as a major bug 7 months ago.
Comment #15
eyal shalevI've also noticed that there was not a single commit in 4 months, the module page directs to an archived github repository, the roadmap refers to version 1.0 (and not the current 3.0) - Was this module silently abandoned?
Comment #16
samuel.mortensonHi @eyal-shalev - we sprinted on Entity Browser issues last week at Drupalcon Nashville and didn't have enough time (or people) to get to this issue. Entity Browser issues will still be worked on based on priority and age (by created date), so yes this will get fixed. One thing that would help push this issue forward is a patch that prevents mis-configuration of Entity Browsers, or that handles this error in a more human-readable way (hide the widget and show a message, for example).
This module has not been abandoned, but many team members have been focusing on pushing core Media forward which takes up a lot of our time. Recently we've been relying on the community to help us out and get patches into a reviewable state, but I want to dedicate more of my time to the project to make sure the queue stays manageable and the module is usable. I'm a co-maintainer and work on Drupal core so my time is often split between a lot of tasks.
Comment #17
mmbkI dug into this problem an found the following:
The Drupal\entity_browser\Element\EntityBrowserElement wants to check whether the SelectionDisplay supports Preselection, but the method checkPreselectionSupport just throws this Eception, that ist not handled, if the Selection display does not support Preselection.
modules/contrib/entity_browser/src/Element/EntityBrowserElement.php Line 147
modules/contrib/entity_browser/src/WidgetSelectorBase.php Line 132
I think that the 'checkPreselectionSupport'-Method should return a boolean, and should noct throw the Exception. The caller must check the answer, and react respectively.
I will provide a patch for this shortly.
This method is called only once in the module, so I don't expect any sideeffects
Comment #18
mmbkHere comes a patch as a starter, at least the entity_form is not crashing anymore, and a warning messages is displayed, that the browser widget is not configured correctely.
The Javscripts-tests fail on my local system, but as unpatched version is also failing, I consider not a part of this issue.
OK it is my test environment!
To get rid of the warning I think the EntityReferenceBrowserWidget may not the option 'edit selection' when the browser does not support this.
Comment #19
marcoscanoThis would be a BC-breaking change... Not sure many people rely on this method, but if we can avoid breaking BC, it would be ideal.
IMHO the best approach for this would be to prevent a configuration that we know will not work from happening in the first place. I think this could be done in two steps:
1) When building the field widget settings form, loop over all browsers and only include as options those that support pre-selection
2) When saving an existing browser, if it supported pre-selection previously and after it doesn't, fail validation if it is being used in a field widget that would be broken with the new configuration.
Does that make sense?
Comment #20
samuel.mortenson@marcoscano We could catch the exception in the UI and show a warning, but keep the API method the same right?
Comment #21
mmbkBreaking BC is an issue, I was thinking of catching the exception an reacting appropriately, but my personal feeling is that Exceptions should be used for rather exceptional states. Here is a capability of the object queried, which is not exceptional, but a rather normal process. Querying this with a simple 'if' statement shows the normality of this process.
Maybe we could introduce a method like SelectionDisplayBase::supportsPreselection() that is querying this capability and leave the checkPreselectionSupport as was and mark it deprecated.
As the module is still in alpha-phase, an api-change should not be completely forbidden.
For my personal interest I already modified the widget, And there I think it's even more approriate to query the capability instead of catching an exception.
The EntityBrowserElement then should implement something like:
This will need some JS-actions - unfortunately I could not help there, my JS-skills are not good enough
If s.b. gives me a hint, how I can validate the field widget (sorry, never written a widget yet) I would happyly work on this issue (Probably a follow-up?)
Comment #22
marcoscano@samuel.mortenson
I thought about this too, but then realized that this wouldn't even be necessary. If we don't expose to the UI options that will break things, we would never reach the mis-configured scenario through normal use of the UI. (which is what we are trying to improve here: the site-builder experience when experimenting with the module)
@mmbk
Unfortunately the module has a stable release (8.x-1.4), and the 2.x branch is supposed to be BC with the 1.x branch, if I recall correctly.
Comment #23
mmbkIf the exception is not catched, the exception is useless. So we don't even need to check the condition, assuming that everything will work correctly. Probably it would do less harm, passing the selected items to a selectionDisplay, that does not support this mode and ignores the list. I'm not sure that this is a good idea.
The widget will still need a method to decide if the SelectionDisplay supports the SELECTION_MODE_EDIT, and here I still think querying a method that returns a boolean value is the better way. Because we have to know if the mode is supported, and in this way it is expressed explicitly. (Sorry I can't explain it better in the moment - I need to practice my englsh)
Comment #24
mmbkComment #25
damienmckennaRan into this when loading the entity-add form for ECK for a custom entity bundle that used entity browser for an image field. The patch resolves the issue for me.
Comment #26
damienmckennaThis problem happens in Entity Browser 2.x too.
Comment #27
ismail cherri commentedThe patch in #18 fixes the issue for version 8.2-dev
Comment #28
ismail cherri commentedComment #29
oknateHere's an updated patch
On node form:

On field widget config:

Comment #31
oknateFailure was random, setting back to Needs Review.
Comment #32
oknateAdding test coverage.
Comment #34
oknateFixing test coverage. Last patch failed because links that start/admin/ etc doesn't work on testbot. Drupal is installed in a subdirectory, so it would have to be /subdirectory/admin/ etc. I changed the assertion to use pageTextContains to get around this difference. The most important thing is that the error message is displayed.
Comment #35
mmbkNice work, the changes are working as expected.
- The field-widget forbids to use an entity_browser w/o selection display, when SELECTION_MODE_EDIT is wanted. I htink the message shown is clear enough for the sidebuilder to take the appropriate actions.
However, a new problem arose.
If you've added an entity browser with preselection to a form successfully and change the entity browser later, you can enter the form (this was not pssible originally) . The form and the message concerning the configuration problem ist displayed.
In the the step when you try to open the entity browser, the browser crashes again.
Comment #36
mmbkThe status with patch #34 is so much better, than the original. A sitebuilder should know what to do next, to get rid of the warning messages.
The situation where the exception is thrown, is rather exotic. Only for testing here I changed the browser back to 'No selection display'. I doubt that it will happen to often. That's why I think we shoul handle that eception in a follow-up, and consider this done.
The exception is similar to the checkPreselectionSupport() Exception. The exception is used as flow control. The function should return a boolean that can be tested by the caller.
EntityBrowserForm line 195ff.
Called only once, in the same saource
Comment #37
berdirMessage should be on the same line and end with a ".". core guidelines are to always specify when it has been deprecated and when it will be removed, but we don't know that yet.
Maybe also add a @trigger_error() in the methods, so that anyone calling that in test will be notified?
Comment #38
oknateThanks, updated.
Comment #40
oknateRerunning test on #38. It was a random failure.
Comment #41
oknateComment #42
berdirComment #45
oknateCommitted! Thanks!