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.
We can now persist field storages. We should not create comment body field storage in code since that means it is possible to deploy a field storage different from the type assumed in CommentManager::addBodyField(). It also means that contrib or custom modules can rely on the field storage being present. See #1426804: Allow field storages to be persisted when they have no fields.
Comment | File | Size | Author |
---|---|---|---|
#35 | 2374087.35.patch | 27.85 KB | alexpott |
#35 | 33-35-interdiff.txt | 1.91 KB | alexpott |
#33 | 2374087.33.patch | 28.1 KB | alexpott |
#33 | 28-33-interdiff.txt | 9.7 KB | alexpott |
#28 | 2374087.28.patch | 35.5 KB | alexpott |
Comments
Comment #1
alexpottComment #3
alexpottFixing the tests.
Comment #5
alexpottFinal test fix
Comment #6
yched CreditAttribution: yched commentedDo we have a similar issue for block_content bodies ?
Comment #7
alexpottYep
Comment #8
alexpottLet's also remove the automatic creation of body fields when you create a type and remove the addition of comment fields to forum and article. CMI all the way. I think we need #2321385: Creation of node body field in postSave() incompatible with default config and overrides to land first so that everything can be in CMI
Comment #10
alexpottWeird we had a file called
rdf.mapping.comment.node__comment.yml
but the ID wascomment.comment
which should result in files with the namerdf.mapping.comment.comment.yml
- I think this is a hang up of pre-comment type days.Comment #12
larowlanI think there's an existing issue to move comment field for forum to cmi, we should close as duplicate of this, leave it with me
Comment #13
alexpottCan't fix the migrate tests - the comment_body field is being added and nothing should have changed :(
This patch will get considerably smaller once #2321385: Creation of node body field in postSave() incompatible with default config and overrides lands.
Comment #15
benjy CreditAttribution: benjy commentedThe body field needed creating in the test since it is no longer automatically created when the comment type is created. Patch attached should fix migrate fails.
Comment #16
larowlanSo this moves the logic from the Entity to the submit handler. What happens if you (for example) create a comment-type using the API - or via REST. Are we sure we want to go this way? Logic in form submissions handlers is something we've been moving away from.
Also given how much cruft is added to work around #2321385: Creation of node body field in postSave() incompatible with default config and overrides - I think it would be worth postponing this one on that?
Comment #17
larowlanJust read #2321385: Creation of node body field in postSave() incompatible with default config and overrides and realise my comment above is contra to that - i.e. creating fields in post-save is bad. But I'm not sure creating them via the form is that hot either. How about a check-box in the form 'Add body field' that if checked adds the field? Still comes down to logic in the form - but makes it clear that its associated with a given form, rather than a particular API operation.
Comment #18
larowlanOf course feel free to say 'shut up larowlan and just rtbc the damn patch' :)
Comment #19
benjy CreditAttribution: benjy commentedI also don't like the pattern of doing stuff like this in form submit handlers, it caused an issue with the book module as well #2363647: Cannot programatically update books. Migrate is particularly good at finding bugs that are hidden by form submit handlers.
The checkbox is a nice idea, conceptually I think that does feel better.
Comment #20
benjy CreditAttribution: benjy commentedMigrateDrupal6Test will still fail because it runs all the migrations without their setup methods. Lets add a CommentType destination and add the body field there.
Comment #21
alexpottActually
\Drupal::service('comment.manager')->addDefaultField('node', 'story');
should take care of this.Comment #22
alexpottCalling an API function like addDefaultField() or addBodyField from a form submit function is fine. Putting API logic in a submit function is not. Putting other config entity type creation logic inside another config entity is also not good. imo this is nothing like #2363647: Cannot programatically update books
Comment #23
larowlanUnless bot disagrees, I'm happy with this - committers - please put #2321385: Creation of node body field in postSave() incompatible with default config and overrides in before this (also rtbc) and then this can be re-rolled.
@alexpott++
Comment #24
benjy CreditAttribution: benjy commentedIn regards to #22, I think it's clearer if the form handlers don't make assumptions about what you need.
For example, if I'm using the UI to create comment types and I always get a body field and then I create one from a REST call, i'd be Googling, "Why doesn't body field get created from REST call". However, if it was a separate action, like the checkbox larowlan mentioned, or you had to manually add the field, I think that would then register with me that it was two actions and i'd need to handle the body field creation myself.
Not trying to hold this issue up, just wanted to share my thoughts on this. The last patch should still fail until we add a CommentType destination that creates the body/default field.
Comment #26
benjy CreditAttribution: benjy commentedHow come we don't also replace the second instance with an addDefaultField/addBodyField call?
I don't quite understand how adding this to setUp fixed MigrateDrupal6Test, is it possible something else also changed that isn't in the interdiff for #21? My patch in #15 had failures only in MigrateDrupal6Test which does not call setUp for tests. Your interdiff shows a change only in setUp but then the tests pass?
Comment #27
alexpottI went a bit mad #21 is mostly #2321385: Creation of node body field in postSave() incompatible with default config and overrides - so my changes do fix MigrateCommentTest but don't fix MigrateDrupal6Test (as @benjy expected - and so did I)
Comment #28
alexpottHere's a fix for all the migrate test fails.
Comment #29
benjy CreditAttribution: benjy commentedCan we inject this like we do for the UrlAlias destination? Otherwise the rest looks much more like what I was expecting. RTBC for the migrate stuff.
Comment #30
yched CreditAttribution: yched commentedGreat cleanup, only minor remarks :
Minor, but the line spacing groups code blocks in a way that obscures what is being done (and code comments do not really help) :
& Same in the duplicated code in StandardProfileTest, StandardTest, UserPictureTest.
Also, maybe I'm missing something, but those all have a @todo "Remove after #2321385: Creation of node body field in postSave() incompatible with default config and overrides", but not clear how that issue there about node body will let us remove that code about comments here. Should we commit that other issue first to see clearer ?
Can we preserve the line spacing that was there ?
OK, it was expected that this code would become more complex once we deal with comment bodies (custom blocks to come), but ouch...
Side note:
- missing space after foreach
- could be simplified to:
(and same in EntityUnitTestBase)
Comment #31
yched CreditAttribution: yched commentedThat issue just got committed, so looks like we can take care of the @todo now ?
Comment #32
yched CreditAttribution: yched commentedSide note about #30.1 : this code was copy/pasted from CommentManager::addDefaultField(), which could use some cleanup itself. Patch posted in #2376581: Cleanup CommentManager::addDefaultField().
Comment #33
alexpottThanks for the review @yched
The interdiff is post rebase with conflicts in forum.install.
Comment #34
yched CreditAttribution: yched commentedThanks @alexpott.
Code remarks in #30.3 still apply though - at least the missing space for code standards :-)
Comment #35
alexpottYep they do :)
Comment #36
yched CreditAttribution: yched commentedThanks !
Comment #37
catchFixes a critical so fine per #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase?.
Committed/pushed to 8.0.x, thanks!