Migrate Drupal's BlockPluginId plugin is hard to read and awkward to use. It depends on being placed in a specific spot in a process pipeline, after a specific plugin (static_map). This is all unnecessary -- it can be easily refactored into a much sleeker and better-integrated plugin by extending StaticMap and taking advantage of the inherited functionality.
This patch turns BlockPluginId into a subclass of StaticMap. BlockPluginId's specialized processing happens first, and if no plugin ID can be derived from that logic, it falls back to static mapping.
If the static mapping is bypassed on failure, the plugin will create a new plugin ID from the input values, in the form $module:$delta
, which will be saved with the migrated block. Chances are, a plugin with this composite ID will not actually exist, so when the block is displayed in the migrated site, the block system will use the fallback (broken) plugin. This means more blocks can be migrated into their correct theme and region, giving the site owner a chance to set the correct plugin ID later.
As of #5, this patch does not break BC.
Comment | File | Size | Author |
---|---|---|---|
#23 | 2796165-23.patch | 7.35 KB | quietone |
#23 | diff-18-23.txt | 6.2 KB | quietone |
#18 | 2796165-18.drupal.Refactor-BlockPluginId-to-improve-data-integrity-flexibility-and-maintainability.patch | 11 KB | mikelutz |
Comments
Comment #2
phenaproximaFirst attempt. Chances are, this will break
the plugin's unitsome test. (BlockPluginId has no unit test.)Comment #4
phenaproximaComment #5
phenaproximaAdded an is_scalar() check to BlockPluginId for backwards compatibility, and removed the bypass flag from the d6_block and d7_block migrations so that, out of the box, they'll behave the way they did before the refactoring.
Comment #6
phenaproximaComment #7
phenaproximaComment #8
phenaproximaComment #9
mikeryancreate() definitely needs some comments to explain why we're resorting to moduleExists() and reflection here.
Hardcoded migration IDs make this plugin unusable for custom migration scenarios, let's make these configurable (a la #2640842: Make related file migration ID configurable in d6_cck_file).
Comment #10
phenaproximaBoth addressed. Still needs tests, though...
Comment #11
heddnI've used the patch in #10 on a live site and it seems to function fine. However, I didn't use any of the advanced features or capabilities of the patch so leaving at needs review.
Comment #12
phenaproximaNW for tests.
Comment #17
mikelutzComment #18
mikelutzStarting with a re-roll for 8.7.x
Comment #23
quietone CreditAttribution: quietone as a volunteer commentedAlways wondered about this one so I rerolled it.