Problem/Motivation
Consider this code in CckMigration.php (lines 107-118):
foreach ($source_plugin as $row) {
$field_type = $row->getSourceProperty('type');
if (!isset($this->processedFieldTypes[$field_type]) && $this->cckPluginManager->hasDefinition($field_type)) {
$this->processedFieldTypes[$field_type] = TRUE;
// Allow the cckfield plugin to alter the migration as necessary so
// that it knows how to handle fields of this type.
if (!isset($this->cckPluginCache[$field_type])) {
$this->cckPluginCache[$field_type] = $this->cckPluginManager->createInstance($field_type, [], $this);
}
call_user_func([$this->cckPluginCache[$field_type], $this->pluginDefinition['cck_plugin_method']], $this);
}
}
In the line with createInstance, the field type is passed and checked correctly. However, the type hint for the property cckPluginManager is misleading. It is actually the base class which has different semantics for the createInstance method. Navigation in IDE is confusing and it takes effort to figure out the mix-up between field_type and plugin_id, which may be different.
Proposed resolution
Type hint the property correctly. The CckMigration is created with the service plugin.manager.migrate.cckfield which is/should be \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManager or its subclasses.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | cckmigration_does_not-2787619-19.patch | 18.75 KB | hussainweb |
| #19 | interdiff-18-19.txt | 3.2 KB | hussainweb |
| #18 | cckmigration_does_not-2787619-18.patch | 17.94 KB | hussainweb |
Comments
Comment #2
hussainwebAttaching a patch with the change.
Comment #3
hussainwebI found some more places where this plugin manager is used and not hinted correctly.
Comment #4
benjy commentedFixes make sense, just a question regarding dependencies.
Can someone remind me how we know the FieldType process plugin is dependant on migrate_drupal? I know we've had an issue for this in the past but I thought that was only for the migrations themselves, not the process plugins.
Comment #5
hussainwebSure, I thought about this issue too and I did not delve too deep into that issue (I'm guessing this is the one you mean: #2560795: Source plugins have a hidden dependency on migrate_drupal). However, I concluded that doesn't matter in the scope of this issue because all these files depend on a service provided by migrate_drupal anyway. The below snippet is from FieldType.php and there are equivalent calls in other classes as well.
Comment #6
phenaproxima<yoda>Sense, this patch makes. Commit it we should.</yoda>
Comment #7
alexpottI think we should add an interface for migrate's plugin manager's because they all do this... see \Drupal\migrate\Plugin\MigrateDestinationPluginManager and then they should implement this interface... this interface should extend PluginManagerInterface.
Comment #8
hussainwebHere is an interface for MigratePluginManager and this documents as well as provides type safety. The original problem still remains however, unless we add another interface for MigrateCckFieldPluginManager for the changed parameter.
Comment #9
alexpottHow is
different from
Ah I see you want to change it for field type - fine another interface if we think that is worth it.
Still way too much typehinting on the concretes in the patch.
Comment #10
hussainweb@alexpott: I think another interface is worth it, especially considering #2787639: MigrateCckFieldPluginManager mixes up its behaviour for creating and loading definitions, which is a bigger issue.
Comment #11
hussainwebAdding an interface for
MigrateCckFieldPluginManagerand changing all references.Comment #12
phenaproximaIf all complaints are addressed, and it seems to me like they are, I think this is good to go.
Comment #13
alexpottWe can't mix inheritdoc with other doc... we need to repleat the full documentation here.
Comment #14
hussainwebFixing for #13. I think at least the first style is being used elsewhere in core, IIRC but I am anxious to get this committed soon as I am waiting to reroll other patches based on this.
Comment #15
phenaproximaPre-emptively re-RTBCed in the quite likely event that this passes all the tests.
Comment #16
alexpott#2787639: MigrateCckFieldPluginManager mixes up its behaviour for creating and loading definitions seems to make parts of this patch invalid.
Comment #17
hussainwebI always thought that this would go in first, considering it was simple. I was always going to reroll the other, so I'll do that now. :) Thanks!
Comment #18
hussainwebI am starting with a reroll. The new interfaces needs the method introduced in #2787639: MigrateCckFieldPluginManager mixes up its behaviour for creating and loading definitions
Comment #19
hussainwebAnd now, changing the interface. We don't need to override definition of
createInstanceanymore as that is now exactly the same as the parent.Comment #20
phenaproximaI think that looks okay.
Comment #21
alexpottCommitted and pushed 0d74926 to 8.3.x and 6a38601 to 8.2.x and df8e15a to 8.1.x. Thanks!