Compare commits
No commits in common. "9df071a382e144e47a94542e2b7c271d75a08fec" and "126db730374f7c500b4978b3295e6f4334429afe" have entirely different histories.
9df071a382
...
126db73037
2 changed files with 4 additions and 39 deletions
|
@ -2,4 +2,3 @@ name: Migration Helpers
|
|||
type: module
|
||||
description: Provides helpers to migrate data into modern Drupal.
|
||||
core_version_requirement: ^9 || ^10
|
||||
php: 8.0
|
||||
|
|
|
@ -3,25 +3,18 @@
|
|||
/**
|
||||
* Entity query helper.
|
||||
*/
|
||||
function migration_helpers_entity_query(
|
||||
$entity_type = 'node',
|
||||
$bundle = NULL,
|
||||
$field = NULL,
|
||||
) {
|
||||
function migration_helpers_entity_query($entity_type, $bundle, $field = '') {
|
||||
|
||||
/** @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();
|
||||
|
||||
if ($bundle) {
|
||||
$bundle_key = $entity_storage->getEntityType()->getKey('bundle');
|
||||
$entity_query->condition($bundle_key, $bundle);
|
||||
}
|
||||
|
||||
if ($field) {
|
||||
if (!empty($field)) {
|
||||
// Check that field BOTH is present on entity bundle AND has a value saved.
|
||||
$entity_query->exists($field);
|
||||
}
|
||||
|
@ -34,33 +27,6 @@ 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
|
||||
|
||||
|
|
Reference in a new issue