I'd like to introduce the EntityTypeAwareInterface that brings two methods: getEntityType()
and getEntityInfo()
.
The goal of this is having a natural object oriented API which allows, whenever we are working with any entity controller or entity object to fetch the entity type and info easily.
One use case where it could be useful is there: #1781372: Add an API for listing (configuration) entities. Having this would avoid "entity type" and "entity storage" parameters duplication, because the storage is supposed to know on which entity type it works.
I wrote a simple patch, that make all of EntityStorageControllerInterface
, EntityInterface
and EntityFormControllerInterface
implementing this new EntityTypeAwareInterface
interface.
Also wrote an abstract base class, and used it in every of the default implementations. I manually tested and right now it works gracefully when working with nodes, comments and taxonomy tags.
Ideally, this goes into the direction of injecting the entity info (eventually materializing it as an object/interface too) instead of letting all those objects doing direct global state procedural calls. The idea behind this is in the mid-term getting rid of the procedural API calls in the object oriented code.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1797740-1-entity_type_aware.patch | 10.58 KB | pounard |
Comments
Comment #1
pounardComment #2
tstoecklerNice patch. Looks really good already. Per our semi-new standards it should be
EntityTypeAwareBase
instead ofAbstractEntityTypeAware
, though. Marking needs work for that.Comment #3
pounardI want to keep close to world wide standard when considering naming, I don't recall this to be specified anywhere solid. But, I'm not closed to changing name. I just prefer the abstract prefix which seems clearer IMO. Let's see other people's reaction about this!
To go further, I'd want to push EFQ being an "entity type aware" object as well, and making it being provided by the
EntityStorageControllerInterface
(such asEntityControllerStorageInterface::getEntityFieldQuery()
) instead of being an object of its own, but I don't know if this makes sense considering that field API is today decoupled from entity system?Comment #4
tim.plunkettThe suffix of Base signifies an abstract class. It is required for test classes, but is only suggested for non-test classes.
However, Abstract should never be used a prefix.
Comment #5
pounardWhat?
Comment #18
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis seems like something that could still be useful. Could someone confirm?