Updated: Comment #N
Problem/Motivation
In preparation for #2031717: Make entity module not required - let's make sure all interfaces exposed by the entity API are below the core component.
Solution
Move the entity display interface below the core component and separate them from their config entities, as being a config-entity is nothing that we require for entity display.
Changes:
entity\EntityDisplayBaseInterface -> Core\Entity\Display\EntityDisplayInterface
entity\EntityDisplayInterface -> Core\Entity\Display\EntityViewDisplayInterface
entity\EntityDisplayInterface -> Core\Entity\Display\EntityViewDisplayInterface
entity\EntityFormDisplayInterface -> Core\Entity\Display\EntityFormDisplayInterface
entity\EntityDisplayBaseInterface -> Core\Entity\Display\EntityDisplayInterface
EntityViewDisplayInterface, EntityFormDisplayInterface do not extend ConfigEntityInterface any more
The patch does not add separate EntityViewDisplay or EntityFormDisplay interfaces just for the config entities (what we usually do) as we figured you'd usually type-hint on the general non-entity type specific interfaces anyway.
Follow-up tasks
Rename the "entity_display" config entity, along with its class name and hook_entity_display_alter() to entity_view_display.
User interface changes
None.
API changes
ViewBuilder, FormController, as well as entity-view hooks are slightly changed to use the interfaces below the core component now.
Original report by @username
Attached patch separates the existing entity-display config-entity interfaces CRUD stuff from the actualy display-related logic that imho belongs in the API only and moves the general interfaces to the core component. The object being passed in is a CMI object is an implementation detail and nothing that should be required for being able to render/edit a simple entity.
With that patch all interfaces part of entity.api.php are in the core component.
Comment | File | Size | Author |
---|---|---|---|
#87 | d8_entity_display.interdiff.txt | 3 KB | fago |
#87 | d8_entity_display.patch | 47.37 KB | fago |
#83 | d8_entity_display.patch | 48.86 KB | fago |
#72 | d8_entity_display.patch | 47.31 KB | fago |
#64 | d8_entity_display.interdiff.txt | 2.8 KB | fago |
Comments
Comment #2
fagoMissed a few type-hints.
Comment #3
Berdir#2: d8_interface.patch queued for re-testing.
Comment #5
fgmRerolled for today's HEAD.
Comment #6
fagoThis seems wrong.
As discussed, let's follow the actions example and add the "ConfigEntity" suffix to interface extending the ConfigEntityInterface.
-> e.g. EntityFormDisplayConfigEntityInterface
Comment #7
fgmThis should be it.
Comment #9
fgmShould be better: I had missed one replacement.
Comment #11
fgmMight be a transient error: the test which fails here passes locally on my machine and passes on simpletest.me too. Retrying.
Comment #12
fgm#9: 0001-Issue-2031725-by-fago-fgm-Move-entity-API-interfaces.patch queued for re-testing.
Comment #13
BerdirLeft-over debugs()
Comment #14
fgmOoooppppsssss....
Comment #15
BerdirTagging.
Comment #16
fagoWe should not use the config entities in the EntityFormController API, but go with our new interfaces now. This should be the case for interfaces + hooks - hook documentations are already fine.
Ideally, implementations provided Core/Entity would not have any reference to the module also, but this is out-of-scope for this issue for now. So if it's a simple fix we can include it, else it's stuff for #2031717: Make entity module not required.
Comment #17
fgmThis seems to do it. Does it still pass ?
Comment #19
fgmLooks like I missed one replacement.
Comment #20
fgmForgot to attach interdiff with previous patch.
Comment #21
fgmRerolled after conflicting commits to 8.x yesterday. No changes.
Comment #22
fagoThis seems wrong.
This seems wrong.
Again.
Again.
Also, \Drupal\entity\Entity\EntityDisplay does not seem to implement the respective interface. But there is a file for EntityDisplayInterface in entity.module which defines it at core namespace.
Comment #23
fgmRerolled accordingly.
Comment #24
fgmoops, patch upload didn't make it.
Comment #25
fagoThanks, patch looks good to me now. However we'll need someone else to RTBC as I did the initial patch.
Comment #26
amateescu CreditAttribution: amateescu commentedDiscussed this a bit with fago and we agreed that there's really not much use for the new
Entity[Form]DisplayConfigEntityInterface
provided by the entity module. I guess only field_ui could typehint with them if we decide to do something crazy related to the config storage side, but I'd prefer to wait until that happens. In the meantime, they seem a bit over the top so let's remove them :)Comment #27
fgmOnly users were
EntityDisplay
andEntityFormDisplay
. Rerolled according to #26.Comment #28
amateescu CreditAttribution: amateescu commentedThanks, I think it's ready now.
Comment #29
Berdir#27: 0001-Issue-2031725-by-fago-fgm-Move-entity-API-interfaces.patch queued for re-testing.
Comment #31
fgmRerolling in a moment.
Comment #32
fgmRerolled on latest head. Does it still pass ? The only change appears to be the TranslatableInterface on TypedData.
Comment #34
fgmSeems I has missed one line to remove.
Comment #35
BerdirPatch is almost identical to the previous one, just a tiny context change.
Comment #36
catch#34: 0001-Issue-2031725-by-fago-fgm-Move-entity-API-interfaces.patch queued for re-testing.
Comment #38
BerdirRe-roll.
Comment #40
Berdir#38: field-interfaces-2031725-38.patch queued for re-testing.
Comment #41
tstoecklerI like that, that makes a ton of sense. Both the naming and the removed interface.
++
If this were simply following the rename it would be EntityViewDisplay now. But a) this is in EntityDisplayInterface, which knows nothing EntityViewDisplay(Interface) b) typehinting the interface is of course preferred.
In other words, this should have been EntityBaseDisplayInterface before, so it is in fact a (minor) bugfix.
Nice!
This, though should be EntityViewDisplayInterface, if I'm not mistaken.
I'm pretty sure EntityDisplay should extend EntityViewDisplayInterface and by extension, be called EntityViewDisplay.
EntityDisplayBase can then be just EntityDisplay. Also that should directly implement ConfigEntityInterface I think.
Also, below:
Interfaces++
(Again, this is a minor fix of the previous code)
Comment #42
vladan.me CreditAttribution: vladan.me commentedTrying to reroll #38
Comment #43
vladan.me CreditAttribution: vladan.me commentedComment #45
vladan.me CreditAttribution: vladan.me commentedTake 2, re-roll #38
Comment #46
vladan.me CreditAttribution: vladan.me commentedComment #47
vladan.me CreditAttribution: vladan.me commentedIn DisplayOverviewBase.php instead of
+use Drupal\entity\EntityDisplayInterface;
should be probably
+use Drupal\Core\Entity\Display\EntityDisplayInterface;
Despite that, are there any other issues you see with this re-roll?
Comment #49
vladan.me CreditAttribution: vladan.me commentedApplying quick fix #47
Comment #50
tstoeckler#41.3 and #41.4 are not adressed as far as I can see.
Comment #51
vladan.me CreditAttribution: vladan.me commentedI've just done re-roll of previous patch since I was not quite sure how to implement those mentioned in #41.3 and #41.4
Can you please guide me by giving some steps of execution, what exactly needs to be done?
Comment #52
yched CreditAttribution: yched commentedWould be nice to update the issue with a summary with of the renames / moving around that the patch does ?
Also, minor:
Apparently we now can use "@return self" for those cases.
Comment #53
Nebel54Rerolling #49 + inline doc update from #52. It's my first reroll… lets see if this passes…
Comment #55
fago53: field_interfaces-2031725-53.patch queued for re-testing.
Comment #57
Nebel5453: field_interfaces-2031725-53.patch queued for re-testing.
Comment #58
fagoYep, however that would mean re-naming the whole configuration files and the config entity type.
That seems reasonable to me, but this could use it's own discussion and follow-up as it goes beyound fixing the interfaces. This goes along with that there is hook_entity_display_alter() which could deserve a rename to hook_entity_view_display_alter() also.
Thus, I left it like that for now as the class name should match the entity type name.
It implements the interface already by extending the base class.
I had a closer look at the patch and noted that there were quite some uses of entity-displays without respective interfaces left, so I fixed those and re-rolled it.
Comment #60
fagoAdding a summary and change the title, as the patch actually just has to care about entity display interfaces.
Comment #61
fago58: d8_entity_display.patch queued for re-testing.
Comment #63
tstoecklerI'm fine with renaming EntityDisplay to EntityViewDisplay in a follow-up. This is still wrong, though: It should implement EntityViewDisplayInterface.
This is what I meant above: Both EntityDisplay and EntityFormDisplay implement ConfigEntityInterface, so I don't see why EntityDisplayBase doesn't implement it. It's totally minor, but I don't see a reason against it.
The actual interfaces used to extend ConfigEntityInterface, which can be seen from the patch, but they don't in the above patches (and they shouldn't!)
Comment #64
fagoThat could be the case ;-) thanks.
Right, fixed that.
EntityDisplayBase extends ConfigEntityBase, thus implements the interface already. So what's wrong is that the specific class do so *again* - removed that.
Updated patch including interfaces attached.
Comment #65
amateescu CreditAttribution: amateescu commentedWhy are we changing the name of this interface when the name of the entity class stays the same? Can't we just move the interfaces like the issue title says and discuss whether this renaming is a good idea?
Comment #66
yched CreditAttribution: yched commentedWell, I'm not sure I see why we keep specific empty Entity(View)DisplayInterface and EntityFormDisplayInterface interfaces for the "view" and "form" flavors ?
The design is that they work just the same with the same APIs, we could just keep the single EntityDisplayBaseInterface (and rename it to EntityDisplayInterface) ?
Comment #67
amateescu CreditAttribution: amateescu commentedThat would be even better.
Comment #68
tstoecklerI totally missed that, you are of course correct. Thanks for setting me straight.
I disagree with removing the specialized interfaces. It's awesome that we have the generic interface which should be used in many cases. But in certain cases it's just wrong to type hint the generic interface. hook_entity_view() for example is conceptually tied to view displays. Receiving a form display there is bogus.
Comment #69
amateescu CreditAttribution: amateescu commentedI'm sorry but I don't see how a "combined"
EntityDisplayInterface
ties anything to a view or a form display.Both entity types (EntityDisplay and EntityFormDisplay) have the same methods and share a lot of code already through the base class..
Comment #70
fagoComment #71
fagoI'm not sure about this. True, they are all equal right now - but will it stay that way and should it? It's fine that they share the common base, but e.g. getRenderer() seems weird to me. There is no RendererInterface object or something that returns, so instead there should be getFormatter() and getWidget() methods in the respective interface. I wasn't able to find a generic use of getRenderer() either.
That rename is already part of the patch, but was missing from the summary. I added it there.
It doesn't as long as it stays generic, but I could see the respective displays getting more helpful methods for their specific usecase. E.g. getFormatter(), getWidget() or the display object could even take over form element generation in future, i.e. receive a getFormElements() method.
Comment #72
fagoRe-rolled patch.
Comment #73
amateescu CreditAttribution: amateescu commentedThe use case for having a single method name for both of them (which, looking in retrospective, is pretty weak) is the Field UI base form class for the "Manage Display" and "Manage Form Display" forms, but those could just switch to use an internal helper method.
Comment #74
yched CreditAttribution: yched commentedThe intent of the generic getRenderer() is that it will return a FieldGroupRendererPlugin (or whatever field_group.module D8 will chose to call its "field groups formatter" plugins) on components that are field_groups.
#1875974: Abstract 'component type' specific code out of EntityDisplay is all about making the "components" in EntityDisplays be of different, pluggable types - field_groups, Display suite custom fields, ...
So, yes, that's intentional, there's no RendererInterface, what the getRenderer() method returns depends on the component type. EntityDisplay lets the ComponentHanlders generate them, and persists them throughout the multiple entity rendering.
And so, no, there's no intention to add EntityViewDisplay::getFormatter() / EntityFormDisplay::getWidget()...
Comment #75
yched CreditAttribution: yched commentedAlso:
Yes, not sure we'll get there in D8, but that could totally be the case at some point - and then the ComponentHandler takes care of applying the "renderer" internally, and just return a render array.
Still, Field UI's "Manage dispay" screens need to present a list of heterogeneous rows (fields, field groups...) and display settings form - hence the need to access a 'render plugin for the row", whatever that is.
Comment #76
tstoecklerRe #69: I was arguing that by only having a single interface, you cannot type-hint whether you want to receive a view display or a form display in your functions. entity_view() is one case where this is weird, because it conceptually makes little sense to pass a form display.
Comment #77
yched CreditAttribution: yched commented@tsoeckler: true - I don't see that as a big issue, but TBH I have no strong opinion.
As long as the patch renames / gets rid of EntityDisplayBaseInterface, I'm fine with two separate interfaces. And also +1 on renaming entity_display / EntityDisplay to entity_view_display / EntityViewDisplay, here or later.
So unless @amateescu is strongly opposed, RTBC for me.
Comment #78
amateescu CreditAttribution: amateescu commentedWell, since it appears that we have an agreement on renaming EntityDisplay to EntityViewDisplay in a followup, then renaming only the interface here doesn't hurt anyone :)
Comment #79
fagoAfaik, getRenderer() is only used in the view/form specific implementations.
I see. So getFormatter/getWidget() would be wrong given #1875974: Abstract 'component type' specific code out of EntityDisplay - yep. Still, I don't see how I'd use a general getRenderer() method without knowing what I get there. Anyway, that's another issue so I'll stop now ;)
Comment #80
tstoecklergit diff
is just stupid... :-)Looked through the patch again, and all is well. RTBC++
Comment #81
fago72: d8_entity_display.patch queued for re-testing.
Comment #83
fagoRe-rolled and fixed conflicts.
Comment #85
vladan.me CreditAttribution: vladan.me commented83: d8_entity_display.patch queued for re-testing.
Comment #87
fagoLooks like Git merging messed a few hunks up - fixed those.
Comment #88
fagoThis API change is required for fixing the entity module / component confusion, so let's make sure it's in before beta.
Comment #89
yched CreditAttribution: yched commentedRTBC if green.
Several patches are working on EntityDisplay stuff, would be good to have this cleanup first.
Comment #90
alexpottWe need to ensure that any existing change notices that reference these interfaces are updated.
Committed dd663c4 and pushed to 8.x. Thanks!
Comment #91
tstoecklerI looked through all existing change notices that contained the word 'display' and updated some of them for the new interface name:
https://drupal.org/node/2018597/revisions/view/2731159/6808489
https://drupal.org/node/1907792/revisions/view/2549206/6808513
https://drupal.org/node/1875952/revisions/view/2721457/6808523
I'm not sure whether we need a separate change notice for this, #90 seems to imply that not to be the case.
Comment #92
fagothanks, that looks good. No, I don't think we need a separate change notice for this, thus setting to fixed.
Comment #93
tstoecklerI also remembered that we wanted to do: #2165835: Rename EntityDisplay to EntityViewDisplay in accordance with its interface
Comment #95
BerdirNote: #2175517: Entity displays are themselves config entities did re-add the extends ConfigEntityInterface to EntityDisplayInterface and I can see why, if you type hint on the interface, then you can not use methods from EntityInterface, which is a problem.