Problem/Motivation
While working on #3189481: [Meta] Add source plugin documentation to the codebase, I discovered that d6/ViewMode source plugin uses targetEntityType constant to calculate migration dependencies. I wanted to document this constant, but noticed that DrupalSqlBase does something similar, but it takes entity_type constant instead.
Proposed resolution
We can simplify d6/ViewMode plugin by delegating dependency calculation to parent DrupalSqlBase class.
It requires renaming constant from targetEntityType to entity_type.
It might look like a breaking change, but I don't see how it hurts existing migrations. If someone copied this file and made a custom migration, I suspect that node module is already enabled on the destination website.
Remaining tasks
Review, commit.
Issue fork drupal-3206932
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3206932-d6-view-modes-rename-constant
changes, plain diff MR !490
Comments
Comment #3
matroskeenComment #4
quietone commentedSuch a lovely find! And I agree with the solution.
Just to be clear, this could be done without changing the yml file by adding this
to DrupalSqlBase::calculateDependencies. That just allows the d6_view_modes.yml to define targetEntityType in the constants in the yml. There is nothing gained by keeping that constant name.
Comment #5
quietone commentedMeant to make this RTBC
Comment #6
alexpottWhat about any custom migrations using this plugin? I think we need to deprecate and tell people to update the migration. I.e do something like:
Comment #7
matroskeenSometimes I feel like we're overcomplicating things trying to catch those edge cases, but I agree it's better safe than sorry.
Added a draft change record (https://www.drupal.org/node/3208135) and deprecation notice as suggested in #6.
Comment #8
quietone commented@alexpott, thanks. As Matroskeen says better to be safe than sorry.
I reviewed the latest changes to the patch and they restore the method and add the deprecation notice. I read the change record and made a few modifications for readability and shortened the title.
I think this is ready.
Comment #9
alexpottI'm not sure that the BC layer is quite right here. See comment on the MR.
Comment #10
matroskeenI have some mixed feelings about the suggested change.
Wouldn't it break the migration if someone already has
entity_typeconstant in custom migration for a different purpose?Comment #11
quietone commentedThe change alexpott suggests is needed for anyone with a configured migration. They won't have a constant 'entity_type' on the row and that is what calculateDependencies() expects.
Comment #12
matroskeenIt would work on both cases, because we had this in child class:
We just added a deprecation message to the existing method, nothing was really changed.
And we had this in parent class, which supports
entity_typeconstant.Anyway, I applied the suggested changes, but I'd like to share my concerns about the following case:
Let's imagine someone defined
entity_typeconstant for a different purpose, e.g. the value is 'foo'.In this case, in
calculateDependencies()we overwrite this constant with value specified intargetEntityTypeconstant, which is 'bar', for example.Comment #14
quietone commented@Matroskeen, sorry, my comment in #11 isn't right. It is true the parent uses the constant entity_type but in first BC version the dependency was calculated correctly.
Yea, not sure I like overwriting a constant in a configured migration, it could break some custom code. Much better to let any existing constant stay and warn the user, which is what the first BC version did. In that first version a configured migration using entityTargetType would trigger an error but allow both the calculation of dependencies and any custom code to continue to work as is. In the second version bad things could happen.
Comment #15
matroskeen@quietone, thanks for confirming my assumptions.
I'm reverting the last commit and moving it back to "RTBC" per #8.
Comment #16
alexpottIf
entity_typeandentityTargetTypeare different then bad things are going to happen when we remove support forentityTargetType. But I guess the point is you can have that pain when we remove the deprecation and at least you've been warned it is going to happen.Committed and pushed bd2a1eabe0 to 9.3.x and 577be8956e to 9.2.x. Thanks!
Comment #20
matroskeenThanks!
Closed the merge request and published a change record.