Spin off from #2403873-7: FileFormatterBase does not retain unsaved entities (files).
Core has an entity_reference field type, but no formatters for it.
Only entity_reference.module provides formatters, there's no reason for that, they could be in Core.
Same reasoning applies to widgets (only provided by entity_ref.module), but the current implementations are tied to the notion of "selection handlers", so they can't be moved to Core so simply.
Beta phase evaluation
| Issue category | Task: code reorg to allow greater reusability (provide a generic base class about EntityRef field type in Core rather than in a non-required module) |
|---|---|
| Issue priority | Normal |
| Disruption | Disruptive for contributed and custom modules that define custom formatters for ER fields (base class changes namespace) Note : As mentioned in #26 / #27, this is part of a larger trend to get rid of entity_reference.module completely |
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | interdiff.txt | 2.23 KB | yched |
| #30 | 2404021-e_r_formatters_Core-30.patch | 12.91 KB | yched |
Comments
Comment #1
yched commentedComment #2
yched commentedAttached patch moves the formatters and their base class to Core
Comment #4
yched commentedNeed to update the remaining formatter that is based on EntityReferenceFormatterBase
Comment #5
yched commentedComment #6
dawehnermh?
Comment #7
yched commentedOh, right, that :-)
Yeah, I guess we need to move RecursiveRenderingException into Core as well, but having that exception class, dedicated to one very specific case in one specific formatter for one specific field type, lie around among the other formatter classes in Drupal\Core\Field\Plugin\Field\FieldFormatter feels a bit weird.
@amateescu, do you think we could get rid of that specific exception and use a more generic one ?
Or even : do we really want to throw an exception when rendering a reference tree too deep ? Shouldn't we rather silently stop rendering down the treee ?
Assigning to @amateescu for feedback
Comment #8
amateescu commentedI think that this specific exception is useful to keep because
1) it's not really tied to a single field type, file/image references could have the same problem via the file_entity module
and 2) it forces the site builder/content editor to address the problem instead of letting it go potentially unnoticed and maybe melting down the server if the "silently stop rendering down the tree" threshold is not low enough.
Otherwise, +1 to this issue!
Comment #9
jibranCan we also move the ER formatters tests to core as well here?
Comment #10
larowlanYeah EntityReferenceItemTest is also in the er module
Comment #11
yched commented@amateescu :
I don't get the reasoning. Either "Exception when threshold reached" or "silently stop rendering down when threshold reached" do not change anything about "if threshold too high, server melts" ?
Throwing an exception means "site broken" on rare but random conditions (deep reference chain in the user submitted content) that are hard to prevent or fix.
Silently stopping the rendering at least means that nothing breaks in the rare case where this happens ?
Comment #12
amateescu commentedSure, nothing will "break" in that case, except that it will be much harder to figure out why some content is not displayed, while the exception clearly states (in the dblog) what happened. We need to keep in mind that production sites will not display the exception itself (if configured properly), but a nice message that something went wrong and the site admin can easily see the problem in watchdog.
Comment #13
amateescu commentedI think my reply above is actually making a case to at least emit a warning in watchdog if we decide to get rid of the exception :)
Comment #14
amateescu commentedThought a bit more about this and I realized that I was considering only the site builder/admin perspective, but this issue can also come up when a regular site user has access to edit an entity form with a reference field, in which case he cannot easily "do something about it".
So yes, let's drop the exception and switch to "silently stop rendering down when threshold reached" + logging.
Should we do it in this issue or in #2073753: Fix and add tests for the recursive rendering protection of the 'Rendered entity' formatter?
Comment #15
yched commentedSomething like this ?
[edit: wrong interdiff, see next comment]
Comment #16
yched commentedThe correct interdiff :-)
Comment #17
yched commentedComment #19
yched commentedContainerFactoryPluginInterface, silly !
Comment #20
yched commentedComment #21
jibranThis looks good. Can you answer #9 and #10? Other then that it is RTBC.
Comment #22
amateescu commentedYes, exactly! Looks perfect to me. Let's move those tests as well and get this in.
Comment #23
yched commentedThanks @amateescu, I couldn't get to back to it these last couple days :-)
Note - two things I wasn't fully sure about the logging are:
- what to use for "channel"; patch goes with 'entity', but I'm not sure if there is an existing channel that would be more appropriate
- which logging level to use (alert / error / warning / notice...); patch does 'error'
Comment #24
amateescu commentedFor the logging level, 'error' looked appropriate to me because the output of some pages is potentially broken. As for the channel, I don't have anything better than 'entity' in mind :)
Comment #25
alexpottThis issue is a normal task so we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary.
Comment #26
berdirthis issue makes me wonder how long we will actually continue to have entity_reference.module ;)
I think we're just left with widgets, the selection plugin, views integration and support for configurable entity reference fields in general (I recently noticed that it is not possible to have one, e.g. in a kernel test, due to missing/incomplete config schema support in core).
Comment #27
amateescu commentedNot too long in fact :) I'll finish that patch for #entity_autocomplete and #entity_select Form API elements soon which means the selection plugins will also be moved to Core, and after that moving everything else should be trivial.
Comment #28
yched commentedDrupal 8 beta phase evaluation template added
Comment #29
alexpottShould any of entity reference's config schema be moving too?
Comment #30
yched commented@alexpott : indeed, good call.
Comment #31
jibranThanks back to RTBC.
Comment #32
alexpottThis makes things easier for contrib and core - less dependencies.
Committed 3fe7cb5 and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation to the issue summary.
Comment #35
dave reidCount me as part of the very confused party that I thought I needed a dependency on entity_reference from contrib D8 code, but 8 months later have realized that core provides the field type now.