From 097611f89a41cc081a8a74fc74f8ef3a34bdf760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?benjamin=20melan=C3=A7on?= Date: Thu, 16 Nov 2023 10:01:54 -0500 Subject: [PATCH 1/3] Require PHP 8 so we can do named parameters --- migration_helpers.info.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/migration_helpers.info.yml b/migration_helpers.info.yml index 7855059..1d74e40 100644 --- a/migration_helpers.info.yml +++ b/migration_helpers.info.yml @@ -2,3 +2,4 @@ name: Migration Helpers type: module description: Provides helpers to migrate data into modern Drupal. core_version_requirement: ^9 || ^10 +php: 8.0 From e845aa76aa2ffb6bd4bc1bbd91776c72c0a271d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?benjamin=20melan=C3=A7on?= Date: Thu, 16 Nov 2023 10:04:03 -0500 Subject: [PATCH 2/3] Make entity query bundle optional and entity type default to node --- migration_helpers.module | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/migration_helpers.module b/migration_helpers.module index 9a6f597..c99ed2b 100644 --- a/migration_helpers.module +++ b/migration_helpers.module @@ -3,18 +3,25 @@ /** * Entity query helper. */ -function migration_helpers_entity_query($entity_type, $bundle, $field = '') { +function migration_helpers_entity_query( + $entity_type = 'node', + $bundle = NULL, + $field = NULL, +) { /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = \Drupal::service('entity_type.manager'); $entity_storage = $entity_type_manager->getStorage($entity_type); - $bundle_key = $entity_storage->getEntityType()->getKey('bundle'); $entity_query = $entity_storage->getQuery(); - $entity_query->condition($bundle_key, $bundle); - if (!empty($field)) { + if ($bundle) { + $bundle_key = $entity_storage->getEntityType()->getKey('bundle'); + $entity_query->condition($bundle_key, $bundle); + } + + if ($field) { // Check that field BOTH is present on entity bundle AND has a value saved. $entity_query->exists($field); } From 9df071a382e144e47a94542e2b7c271d75a08fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?benjamin=20melan=C3=A7on?= Date: Thu, 16 Nov 2023 10:04:59 -0500 Subject: [PATCH 3/3] Begin giant move terms function with test of named parameters As we move this function in from custom code. --- migration_helpers.module | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/migration_helpers.module b/migration_helpers.module index c99ed2b..b443a0b 100644 --- a/migration_helpers.module +++ b/migration_helpers.module @@ -34,6 +34,33 @@ function migration_helpers_entity_query( } +/** + * Move (and optionally filter/transform) terms between term reference fields. + */ +function migration_helpers_move_terms( + $source_vocabulary, + $destination_vocabulary, + $source_field, + $destination_field, + $source_bundle, + $destination_bundle = NULL, + $source_entity_type = 'node', + $destination_entity_type = 'node', + $mapping = [], +) { + // Destination bundle is also required but we default to making it + // the same as the source bundle. + $destination_bundle ??= $source_bundle; + print(" + $source_entity_type, + $source_bundle, + $source_field, + $destination_entity_type, + $destination_bundle, + $destination_field, + $source_vocabulary, + $destination_vocabulary"); +} // The below almost serve more as examples that can be followed