Allow batch options to be alterable

Created on 22 October 2024, about 1 month ago

Problem/Motivation

We had a use case where a client wanted the sync option on their uploads, so that entries not present in the upload would be deleted.

In order to provide greater flexibility it seemed the best approach would be to allow the batch options sent to MigrateBatchExecutable to be an alterable array, so that other modules can provide additional options.

API changes

Provides a migrate_source_ui_batch_options_alter hook

Usage

An example usage would be to alter both the form and the batch options based on the new form field

/**
 * Implements hook_form_FORM_ID_alter()
 */
function MODULE_form_migrate_source_ui_form_alter(&$form, $form_state) {
  $form['sync_records'] = [
    '#type' => 'checkbox',
    '#title' => t('Sync records'),
    '#default_value' => 0,
    '#description' => t('Will delete previously migrated records that are not present in the current upload'),
    '#weight' => 1,
  ];
  $form['import']['#weight'] = 2;
}
/**
 * Implements hook_migrate_source_ui_batch_options_alter()
 */
function MODULE_migrate_source_ui_batch_options_alter(&$options, $form, $form_state) {
  // Sync records
  if ($form_state->getValue('sync_records')) {
    $options['sync'] = TRUE;
  }
}
Feature request
Status

Active

Version

1.1

Component

Code

Created by

🇳🇿New Zealand somatick

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024