Problem/Motivation
As discovered in #2984782-34: Add an API for converting entity type schemas to (non-)revisionable/(non-)translatable, with or without data, the current API for installing an entity type (EntityDefinitionUpdateManagerInterface::installEntityType($entity_type)
) is insufficient because it doesn't allow developers to specify the field storage definitions that should be installed.
Quoting myself from that comment:
let's say in 8.7.0 we install a new content entity type in a hook_update_8701() function. The entity storage will use the "live" field storage definitions (from code) to install that entity type. Then in 8.8.0, we add a new base field to that entity type with a corresponding hook_update_8801() function. Now, if someone skips a minor version and updates from 8.6.x to 8.8.0 directly, which is not uncommon at all, hook_update_8701() will also install the new field added in 8.8.0 and hook_update_8801() will fail, unless the person who writes that update function is aware of all these shortcomings and makes the code as defensive as possible.
Proposed resolution
Add a new \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::installFieldableEntityType($entity_type, $field_storage_definitions)
method, similar to the update one that was added in #2984782: Add an API for converting entity type schemas to (non-)revisionable/(non-)translatable, with or without data.
Remaining tasks
Review.
User interface changes
Nope.
API changes
API addition: a new installFieldableEntityType($entity_type, $field_storage_definitions)
method added to EntityDefinitionUpdateManagerInterface
.
Data model changes
Nope.
Release notes snippet
Nope.
Comment | File | Size | Author |
---|---|---|---|
#14 | interdiff-14.txt | 5.64 KB | amateescu |
#14 | 3043455-14.patch | 19.36 KB | amateescu |
#14 | interdiff-test-only.txt | 3.12 KB | amateescu |
#14 | 3043455-14-test-only.patch | 19.36 KB | amateescu |
#9 | interdiff-9.txt | 3.47 KB | amateescu |
Comments
Comment #2
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThis should do it.
Comment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedNow with less fails :)
Comment #5
jibranThis looks ready to me. Let's create a change record. Issue title seems like it is a new feature or a task but IS makes it clear that it is a bug. Should we consider updating the title?
This is a blast from past.
Comment #6
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedJust a reroll.
Comment #8
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedFixed that deprecated call.
Comment #9
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedLet's add even more test coverage by fixing an upgrade path function from 8.8.x.
Comment #10
plachNo change record yet :)
Comment #11
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedHere we go: https://www.drupal.org/node/3086279
The patch from #3007669-15: Add publishing status to path aliases is now passing tests when combined with this one :)
Comment #12
jibranThanks, for the change notice.
Comment #13
plachShouldn't we dispatch the event after updating the installed definitions as we do in
::onFieldableEntityTypeUpdate()
? If so, we're missing some test coverage.This comment needs to be updated.
Is this comment a copy/paste?
Comment #14
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@plach, re #13:
Comment #16
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe non-test-only patch had a random fail, setting back to RTBC.
Comment #17
plachYep, the random failure is tracked at #3086001: CreateSampleEntityTest::testSampleValueContentEntity can randomly fail, confirmed locally that test is green.
The interdiffs look great, thanks! I will wait for the testbot for good measure and then commit this :)
Comment #19
plachCommitted 24e2236 and pushed to 8.8.x. Thanks!