Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
- Right now fields are coupled to content entities, while there might be use-cases to have them on config entities as well. If possible we should avoid hard-coding fieldability on content entities and allow experiments in contrib.
- Message module in d7 already provides a use-case + d7 implementation for fields on config entities.
- Other capabilities of content entities are already implemented in separate interfaces, e.g. we've got RevisionableInterface and TranslatableInterface.
Proposed resolution
Introduce FieldableEntityInterface and make ContentEntityInterface extend it.
Remaining tasks
Do it.
User interface changes
-
API changes
- Mostly API additions (new Interface)
- It changes some methods to type-hint to FieldableEntityInterface
instead of ContentEntityInterface
, what is an API change for everyone overriding those methods. Those methods are:
- EntityViewDisplayInterface::build()
- EntityViewDisplayInterface::build()
- FieldDefinitionInterface::getDefaultValue()
- FieldStorageDefinitionInterface::getOptionsProvider
- FieldItemListInterface::processDefaultValue()
- CommentLinkBuilderInterface::buildCommentedEntityLinks()
- CommentStatisticsInterface::create()
- CommentStorageInterface::getNewCommentPageNumber()
Comment | File | Size | Author |
---|---|---|---|
#51 | d8_fieldable.patch | 80.54 KB | fago |
#48 | d8_fieldable.patch | 80.54 KB | fago |
#48 | d8_fieldable.interdiff.txt | 3.46 KB | fago |
#43 | d8_fieldable.patch | 77.31 KB | fago |
#43 | d8_fieldable.interdiff.txt | 778 bytes | fago |
Comments
Comment #1
BerdirWe would need to make it FieldableEntityInterface extends EntityInterface, because we can not just type hint on FieldableInterface in the relevant methods on the entity storage interface for example?
Comment #2
fagoExactly, that is what I was thinking. There is no point in having FieldableInterface without an EntityInterface, so that's fine imho.
Comment #3
yched CreditAttribution: yched commented+1, and also +1 on FieldableEntityInterface rather than FieldableInterface ;-)
Comment #4
fagoLet's see how that goes then.
Comment #6
fagoComment #7
yched CreditAttribution: yched commentedWasn't aware of that requirement - but is it still valid ? Coz it's not what ContentEntityInterface does now :-)
Otherwise, looks good.
Comment #8
fagoI think it is, ContentEntityBase does - it's the implementation that has to do it.
Comment #9
yched CreditAttribution: yched commentedMakes sense. Thanks !
Comment #10
catchApart from initTranslation which has a @todo to remove, this is going to be an empty interface soon
I agree with splitting the interface out, but I'm really not sure about changing all these type hints. Are you 100% sure that all the places relying on ContentEntityInterface at the moment don't require Revisionable/Translatable compared to just Fieldable?
Comment #11
fagoYeah, I think we really should type-hint to what's really required, i.e. FieldableEntityInterface if that's enough. Else, implementing the interface would not allow you to use your entities with all that implementation what would render the interface useless.
I guess this needs a re-roll now.
Comment #14
fagore-rolled and also updated the interface for the new default value method(s) of fields.
Comment #16
fagore-rolled.
Comment #19
fagore-rolled patch and worked over latest additions.
Comment #20
dawehnerThere seems to be basically nothing left here. Can't we add some description, that for example explains when you use this interface? Content, which should be stored in the database.
Is there a possibility to rename the class or at least extract the fieldableEntity specific concepts out of it?
Are you sure about this change? This method is used to identify whether an entity ID is numeric or not. Afaik this is unrelated to the concept of fieldability. Yes, this is a genera assumption of internal details, but the content entity interface seems to mach a bit better ...
Comment #21
fagoThanks for the review!
Yep, I worked on the docs a bit and improved them - in particular I clarified when one would use content entity interface (always). The entity interfaces in general lack doc, but that should be dealt with in its own issue - so I just put the basic stuff there.
Well, there is also translation in this class which is not in fieldableinterface. Given that, the conversion you quoted is actually wrong - I reverted this one. Generally, I think we should look into extracting fieldable parts into e.g. traits that match the interfaces, but given that's sometimes intertangled with translation or revision stuff it might not be always easy / doable. That said, that's something we should look at generally for entity classes, but this can be dealt with in separate issues and is not API changing as we can easily use the traits in the existing base classes.
True, reverted this one also.
Comment #23
fagoadding beta target tag as I think it would make a lot of sense to have the interfaces settled then, even though this is not an API change.
Comment #25
fagoRe-rolled patch, had quite some conflicts.
Comment #26
BerdirThis change is wrong, as it is about content entity storage and relies on TranslatableInterface.
Looking at the remaining uses of ContentEntityInterface:
- StringFormatterTest could use FieldableEntityInterface I guess but no biggie.
- EntityReferenceItem::schema() should go with FieldableEntityInterface I think?
- entity reference autocomplete widget has a pretty weird isContentEntity check, but I think changing that is out of scope.
- ContentEntityNormalizer could maybe just be about fieldable, not sure. Ok with doing that elsewhere too.
- CommentLinkBuilderInterface has a wrong docblock
- entity.api.php has a suboptimal reference, which assumes that there is nothing else than config or content entities, but not too problematic.
Comment #27
fagoThanks, fixed the invokeFieldMethod issue as well as the following two:
- StringFormatterTest could use FieldableEntityInterface I guess but no biggie.
- EntityReferenceItem::schema() should go with FieldableEntityInterface I think?
Comment #28
fagoalso, quickly opened #2346435: Improve interface-related instructins for providing an entity type to be accurate - so we do not forget that.
Comment #31
fagoRe-rolled and worked over recent additions as well. Attached is the merge-interdiff for those fixes also.
Comment #33
fagoops - missed to adapt for quite important change :-) No complex data interface any more for fieldable entities.
Comment #35
tim.plunkettComment #36
pgautam CreditAttribution: pgautam commentedRerolled Patch #33
1) Changed mock Test in EntityManagerTest.php
2) Changed entity.api.php file dependency from ContentEntityInterface to FieldableEntityInterface also make Drupal\Component\Utility\String dependency intact.
Comment #37
fago#36 does not account for the include computed change by #2346433: $entity iterators omit computed fields by default, so here is a re-roll which does. It does not fix the fail for me yet though :/
Comment #38
fago@pgautam: Could you roll patch based on #37 with your other changes and provide an interdiff for that? That would help a lot to review them.
Comment #39
fagoSomehow the reference in comment_entity_predelete() was changed back to ContentEntityInterface, fixed that. Attached patch also moves the new EntityAdapter to FieldableEntityInterface.
Comment #42
fagoand re-rolled again for #2346635: Content entities are iteratable but do not implement Traversable - merge resolving commit interdiff attached.(duplicate)Comment #43
fagoand re-rolled again for #2346635: Content entities are iteratable but do not implement Traversable - merge resolving commit interdiff attached.
Comment #44
fagoComment #45
fagoFigured this represents an API changes for classes extending and overriding methods which get the new type-hint. Updating summary.
Comment #46
BerdirStill looks good to me. API Changes need to be signed off, but otherwise good to go.
Comment #47
alexpottIn OptionsWidgetBase looks like it should be typehinted on FieldableEntityInterface
In FieldItemInterface looks like it should be typehinted on FieldableEntityInterface
In EntityManager looks like it should be typehinted on FieldableEntityInterface
In EntityDataDefinition looks like it should be typehinted on FieldableEntityInterface
Comment #48
fagoThanks for the great review, fixed those.
Comment #49
plachBack to RTBC
Comment #51
fagore-rolled.
Comment #52
plachComment #53
alexpottCommitted ba2b869 and pushed to 8.0.x. Thanks!
Comment #55
fagoThanks, published the change record: https://www.drupal.org/node/2346875