Problem/Motivation
From #2935951-43: Copy migrate source plugin from migrate_drupal_d8 into migrate_drupal, we discussed extracting getDefinitionFromEntity from ContentEntity and EntityContentBase into a re-usable trait. Let's do it.
Proposed resolution
Remaining tasks
Extract the method into a trait.
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | 2937782-23.patch | 7.49 KB | quietone |
| #23 | interdiff-20-23.txt | 2.76 KB | quietone |
| #20 | 2937782-20.patch | 5.92 KB | quietone |
| #20 | interdiff-18.20.txt | 738 bytes | quietone |
| #18 | 2937782-18.patch | 5.88 KB | quietone |
Comments
Comment #2
heddnThis is no longer blocked.
Comment #3
ioana apetri commentedI will work on. What name to use for the trait? Thanks
Comment #4
heddnEntityFieldDefinitionTrait?
Comment #5
ioana apetri commentedHere is the trait. Please review. thanks
Comment #6
heddnSome initial thoughts below. Also, let's see this in use by swapping out the previous uses in ContentEntity and EntityContentBase to use the new trait. That will even give us some test coverage.
Un-used variable.
If we assume that $this->entityType exists, then we can probably also assume the entityFieldManager service/variable is also in existence.
Comment #7
mohit1604 commentedComment #8
mohit1604 commented@heddn, Thanks for reviewing patch. Removed un-used variable as mentioned in #6, Please review it :)
Comment #9
quietone commentedDidn't review the code, just saw that it needs work for the comment in #6 about using the new trait in ContentEntity and EntityContentBase.
Comment #10
jofitzAww pants! It's only as I'm about to upload the patch that I notice this was tagged 'Novice'. Sorry.
I've taken a bit of a punt on this one: ContentEntity uses EntityFieldManager while EntityContentBase uses (deprecated) EntityManager so I have made changes to EntityContentBase (even though there are a number of other classes that extend it) rather than returning EntityFieldManager to (deprecated) EntityManager in ContentEntity.
After all that, perhaps this isn't as 'Novice' as it first seems (or I've missed a simple way to do it ... perhaps a conditional). Anyway I'll put this out there for review.
Comment #14
quietone commentedNeeded a reroll and added some logic to the trait to get the entity_type_id from with the static function for destination plugins or the entity type for source plugins.
Comment #15
heddnCould this be a ternary?
Comment #16
quietone commentedOn a closer look maybe this is better, add a getEntityTypeId() method to ContentEntity, the only source plugin that uses the trait.
Comment #17
heddnCould this trait have a basic
getEntityTypeIdmethod in it that splits onPluginBase::DERIVATIVE_SEPARATORand returns the 2nd part? That way it is more generally useful and we don't need to modify ContentEntity at all?Comment #18
quietone commentedSounds good. The only reservation I decided not to use
PluginBase::DERIVATIVE_SEPARATORbecause this isn't operating on derivatives. In one case it is the destination, like 'entity:file' and the other is the d8 source 'content_entity:node'.Comment #19
heddnre #18: both of those examples are derivatives from what I can tell.
Comment #20
quietone commentedSigh, I was only thinking about the d7 node derivers at the time.My mistake.
Comment #21
heddnYeah! Back to RTBC.
Comment #22
catchContentEntityBase is still defining ::getEntityTypeId() after this patch - should that also be removed here?
Comment #23
quietone commentedRight, fixed the item in #22.
Here are the results of searching for 'function getEntityTypeId' with the patch in #23.
The methods in Book.php and EntityFieldStorageConfig.php return specific strings, 'node' and 'field_storage_config'.
Comment #24
heddnAnd the test classes return satic values 'foo'. So I think this can safely pass back to RTBC.
Comment #26
wim leersNice clean-up here!
This is also a soft blocker to #2746541: Migrate D6 and D7 node revision translations to D8.
Comment #27
xjmThe trait seems like a great idea based on the diff, but I see a lot of red on protected methods, including on a base class. There's been no discussion on issue of whether these are the BC breaks they appear, or whether there's a way to deprecate instead?
Comment #28
wim leersThis patch adds a trait with two methods. Then it removes pre-existing implementations of those two methods from a number of classes. So we need to check for BC implications. Let's do that:
Method signature remains identical ⇒ no backwards compatibility break! 🥳
Method signature remains identical ⇒ no backwards compatibility break! 🥳
These positive BC observations are confirmed by the fact that zero function calls are being modified.
Hence confirming RTBC.
Comment #29
wim leersJust to make 100% certain that #28 is correct and that even subclasses are not affected:
outputs
See https://3v4l.org/6gLqn
Comment #30
xjmExcellent, thanks @Wim Leers!
I was concerned more about behavior changes.
I carefully read over each removed implementation and confirmed that the trait method should have the same result based on the new combined API. I especially like that we're replacing magic numbers with actual use of existing APIs. Nice work!
I thought about whether this needs a CR about the new trait, but since most folks will be using the base class and just get it that way, I think there's no need.
Updating the issue credit. Not sure if @heddn or @quietone had deliberately made some changes to the credit, but I'm crediting @yo30 for the initial patch, and @heddn, @Wim Leers, and @catch as reviewers.
For @mohit1604, nice work on providing a patch that removed the unused use statement! Next time though be sure to read carefully address both the reviewers comments, even if for the second one it's just asking for clarification.
Comment #36
xjmSorry for the extra commit noise; the policy has been that BC Migrate fixes are backported to the production branch, but then I noticed the issue is filed against 8.9.x. I confirmed with @catch that he also has been backporting Migrate fixes. So backported to 8.8.x (again). Thanks!
Comment #37
quietone commented@Wim Leers, thanks for the excellent explanations so this could be committed.
Comment #38
wim leersYou're most welcome, @quietone 😊