Problem/Motivation
Despite its name, SelectionBase is in fact not a base class for the "entity_ref selection handler" plugins, but an actual implementation of a specific selection logic (restrict referenceable entities by bundle)
ViewsSelection provides a completely different logic (restrict referenceable entities by the results of a View), yet it extends SelectionBase, and has to undo all the parent selection logic to implement its own.
It seems this was mostly done to be able to share the code from validateAutocompleteInput::validateAutocompleteInput(), but that is generic code, agnostic about the actual selection logic, and could instead live in the Drupal\Core\Entity\Element\EntityAutocomplete FAPI element.
Proposed resolution
Patch :
- Moves SelectionBase to a new DefaultSelection class (the old SelectionBase is preserved as an empty class extending from it for BC, and is marked deprecated)
- Renames the associated plugin deriver to DefaultSelectionDeriver
- Makes ViewsSelection no longer extend SelectionBase
- Removes SelectionInterface::validateAutocompleteInput(), and move the former implementation in SelectionBase to EntityAutocomplete::matchEntityByTitle()
API changes
- One method is removed from SelectionInterface, which is not an API break. Potential existing implementations become dead code, but the method had no real value for being overriden anyway.
Beta phase evaluation
| Issue category | Task: code cleanup, removing an inheritance between two plugin implementations that has no justification and is cumbersome, and renaming a "false" base class for clarity |
|---|---|
| Issue priority | Normal |
| Disruption | None |
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | 2578559-ER_SelectionBase-30.patch | 36.76 KB | yched |
| #25 | 2578559-ER_SelectionBase-25.patch | 22.28 KB | yched |
| #24 | interdiff.txt | 722 bytes | yched |
| #24 | 2578559-ER_SelectionBase-24.patch | 35.18 KB | yched |
| #21 | interdiff.txt | 859 bytes | yched |
Comments
Comment #2
yched commentedPatch :
- Moves SelectionBase to a new DefaultSelection class (the old SelectionBase is preserved as an empty class extending from it for BC, and is marked deprecated)
- Renames the associated plugin deriver to DefaultSelectionDeriver
- Makes ViewsSelection no longer extend SelectionBase
- Removes SelectionInterface::validateAutocompleteInput(), and move the former implementation in SelectionBase to EntityAutocomplete::matchEntityByTitle()
Comment #3
yched commentedMeh, 3rd person in phpdoc
Comment #4
jibranTagging.
Comment #5
yched commented- facepalm on inconsistent rename between class & file
- I was being too smart with my "array_flattener", wanrings if the array is empty. array_walk() works, too.
@jibran : ViewsSelection is not "VDC", really, it's just some integration code for ER fields. It ships in views because it's meaningless if Views is disabled, but it's really ER code that the Views people most likely never even looked at :-)
Will add the beta eval.
Comment #6
yched commentedbeta evaluation added
Comment #9
jibranThanks @yched.
Comment #10
yched commentedNice, green.
Last adjustment : Core classes that righfully extended SelectionBase are better off extending DefaultSelection rather than the now empty BC class.
Comment #11
amateescu commentedThe patch makes sense but are you sure this will be allowed to go in 8.0.x before RC?
Also, the issue summary doesn't mention that a method is removed from SelectionInterface, which is technically an API change...
Comment #12
yched commentedYes it does ;-)
Hmm, API change but no API break ? Removing a method from an interface won't break any existing code, you less have conditions to fullfill to implement the interface - in that sense it's closer to an API addition ;-). Existing implementations just become dead code ?
Comment #13
amateescu commentedSorry I wasn't clear enough, it doesn't mention it in the 'API changes' block :P
Edit: and your reasoning sounds good, it doesn't break anything :)
Comment #14
yched commentedAh, true. Added.
Comment #15
jibranJust need a change notice then it's RTBC.
Comment #16
yched commentedCRs :
https://www.drupal.org/node/2578749
https://www.drupal.org/node/2578753
Comment #19
jibranThank @yched.
Comment #20
yched commentedReroll after #2281533: Entity Reference default selection plugin ignores matches if an entity type has no label key, and moves the new PhpSelection to extend DefaultSelection rather than the deprecated SelectionBase.
Comment #21
yched commentedOops, and adjusts the @see in PhpSelection accordingly.
Interdiff is with #10 for clarity.
Comment #23
claudiu.cristeaNit: Double back-slash.
Comment #24
yched commentedIndeed :-)
Comment #25
yched commentedReroll after #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted
Comment #28
jibranBack to RTBC.
Comment #29
alexpottLet's leave SelectionBase and gut it and deprecate it and make it extend DefaultSelectionDeriver to do a nicer BC compatible change.
Comment #30
yched commentedDamn. That was the plan, but it disappeared in the last reroll. Sorry about that.
Comment #31
jibranRTBC once again.
Comment #32
alexpottOkay so we have a BC layer and whilst I don't think this is super important for RC I think it'll be nicer to not live with this for the next x years. And we have less code to maintain. Committed 4ea2fc7 and pushed to 8.0.x. Thanks!
Comment #34
amateescu commentedThanks, Alex! Published the CR.