Upgrade Your Drupal Skills
We trained 1,000+ Drupal Developers over the last decade.
See Advanced Courses NAH, I know EnoughSkip hooks during a Drupal 8 & 9 migration
When migrating content with the Drupal 8 migrate module, the creation and updating of new entities may fire lots of custom module hooks. This may or may not be desired; if you have found yourself here, it probably interferes with the source data in a problematic way, or unnecessarily slows down the migration process.
The cleanest way I found to stop specific hooks for specific migrations, is to add a dummy/meta field to the migration and check for its value in the hook.
Include a dummy field in the migration
In the process section of the migration, add a field with a name that will not interfere with any field name of the target entity:
# This is the field that will provide a custom hook
# with the information about the migration.
_migration:
- plugin: default_value
default_value: 'blog_categories'
This is an example migration with CSV as source and taxonomy terms as target:
id: blog_categories
label: 'Blog category migration'
migration_group: default
source:
plugin: csv
path: 'public://migrations/blog_categories.csv'
delimiter: ','
enclosure: '"'
header_row_count: 1
ids: [tid]
process:
name: name
# This is the field that will provide a custom hook
# with the information about the migration.
_migration:
- plugin: default_value
default_value: 'blog_categories'
destination:
plugin: entity:taxonomy_term
default_bundle: blog_categories
migration_dependencies:
required: {}
optional: {}
Check for the value in an entity hook
/**
* Implements hook_entity_update().
*/
function my_module_entity_update(Drupal\Core\Entity\EntityInterface $entity) {
return;
}
// Some undesired custom hook logic.
}
In this case the hook will never fire for this specific migration, but may fire for other migrations. Skipping the second condition will make sure the hook will never fire for migrations where the _migration dummy field is defined.
About Drupal Sun
Drupal Sun is an Evolving Web project. It allows you to:
- Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
- Facet based on tags, author, or feed
- Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
- View the entire article text inline, or in the context of the site where it was created
See the blog post at Evolving Web