Do you want to know how to Drupal?

Let's Drupal

How to update URL for migration programmatically in Drupal 8?

Sometimes we need to dynamically set URL for migrations, for example we have specific parameters restricting results.

We have default configuration

source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: json
  urls:
    - 'http://your_domain/data.php'

 

// Get configuration factory.
$config_factory = \Drupal::configFactory();
// Load your migration configuration.
// Replace with your migration ID.
$migration_config = $config_factory->getEditable('migrate_plus.migration.[MIGRATION_ID]');
// Set your URL here.
$migration_config ->set('source.urls', ['YOUR_URL']);
$migration_config ->save();