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.
All content entities that extend ContentEntityBase
should inherit fields from ContentEntityBase::baseFieldDefinitions()
.
This allows us to have more consistent code, more consistent entities, more consistent fields, and sets a better example.
The patch updates the following entity types:
- Feed
- Item
- BlockContent
- Comment
- Message
- File
- MenuLinkContent
- Shortcut
- Term
- User
Comment | File | Size | Author |
---|---|---|---|
#26 | all_content_entities-2707255-26.patch | 19.83 KB | timmillwood |
Comments
Comment #3
timmillwoodThe Bundle field on MenuLinkContent was slightly different to the one set in ContentEntityBase, therefore this new patch still pulls everything from the parent (ContentEntityBase), but then overrides the Bundle field with the original.
Comment #5
dawehnerThis will now get a language form potentially, which is not necessarily bad. Just let's think us of the consequences for a bit.
This removal should cause an issue ...
Comment #6
timmillwoodRe-running tests,
\Drupal\node\Tests\NodeTypeTranslationTest
passes locally.1) The Item entity doesn't have a form.
2) This is the bundle entity reference, the only changes will be it will lose it's description and become read only.
Comment #7
dawehnerSeems fair for me. I would like to RTBC it, but I'm not sure whether this causes no issues with entities that want to be updated, but it seems not (as we have a test for that).
Comment #8
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedFor #5.2, I wonder if having the bundle field as read-only will cause any problems for #1997692: Create contact form block, but it's easy enough to change it back whenever we would need to.
And the same for their bundle field?
I think we should remove the view and form display options for this field.
Comment #9
timmillwoodComment #10
timmillwoodComment #11
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedNice, looks good to me now.
Comment #13
timmillwoodMenuLinkContent bundle needs max_length and is_ascii settings.
Comment #14
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThird time's the charm :)
Comment #15
BerdirIs there a reason to not have those two settings by default in the base class? At least for fieldable entity types, we definitely don't support non-ascii or longer bundles.
And if someone wants to do something crazy, they still can change it, but seems like a better default?
Comment #16
alexpottTo get an answer to #15
Also will this result in some changes on the labels of those fields which in turn can show up in views and forms?
Comment #17
timmillwood#15 - We could add this to the base class. That would however update the schema, which is something I was trying to avoid in this issue. Maybe we could do that in a follow up issue?
#16- Yes, unfortunately some of the labels will change, things like "Language Code" will change to "Language", or "{Entity type label} ID" will change to "ID".
For ID maybe we could update ContentEntityBase to use the following for the ID field label:
->setLabel(new TranslatableMarkup("@label ID", ['@label' => $entity_type->getLabel()]))
Comment #18
BerdirWe discussed the ID and I think agreed that just ID is better in the original issue. So I think it's OK to stick with that. I think label changes are OK for minor updates.
Right, possible schema changes due to those settings is indeed a problem. I'd be OK with that being a follow-up but as far as I know, the only case in core that doesn't use entity types/reference for bundles beside menu are test entities. So as far as core is concerned, it wouldn't actually be a schema change for any real entity type.
Contrib is a bit a different story, but this shows an interesting problem anyway. Adding the baseFieldDefinitions() method was unproblematic, as it was completely opt-in. But making changes or additions there will immediately and automatically result in changes for them. Changes that they however have to manually update to in update functions. So when exactly will they do that? after 8.2.0 is released, with a dependency on that version?
Comment #19
BerdirWe opened #2713545: [policy, no patch] Are changes to ContentEntityBase base field definitions API breaking to discuss this further. Lets avoid changes that could be API/schema changes here.
Comment #20
catchHmm I'm not really convinced by changing the labels here either - this issue hasn't had any usability review for a start.
What about restoring the label overrides here, then a separate issue to use the default ones which can then be reviewed for the string/interface changes?
Comment #21
timmillwoodUpdated based on #20.
Added labels and descriptions back in where appropriate.
Comment #22
dawehnerIs it okay to drop the UUID description?
For minimal BC break I would vote to add a new issue to add the UUID field to Item but remove it for now explitly
Comment #23
timmillwoodCurrently I only kept the description if I kept an ID. I don't mind keeping description or not.
#2149851: Remove todo about GUID field on the 'aggregator_item' entity and add UUID field is the open issue for an Item UUID.
Comment #24
timmillwoodAdded all the descriptions back in as suggested by @dawehner in #22.
Comment #25
dawehnerI feel bad for even mentioning it! :(
That one is missing
Comment #26
timmillwoodDamn!
Comment #27
dawehnerNo worries. Thank you for the quick patching
Comment #28
alexpottCommitted d7b430a and pushed to 8.2.x. Thanks!