public function SiteSettingsReplicator::processBatch in Site Settings and Labels 8
Process callback for the batch set the export form.
Parameters
array $settings: The settings from the export form.
array $context: The batch context.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Drupal\Core\Entity\EntityStorageException
File
- src/SiteSettingsReplicator.php, line 67 
Class
- SiteSettingsReplicator
- Class SiteSettingsReplicator.
Namespace
Drupal\site_settingsCode
public function processBatch($settings, &$context) {
  if (empty($context['sandbox'])) {
    // Clean settings.
    $settings = $this
      ->cleanSettings($settings);
    // Store data in results for batch finish.
    $context['results']['settings'] = $settings;
    // Set initial batch progress.
    $context['sandbox']['settings'] = $settings;
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['current_id'] = 0;
    $context['sandbox']['max'] = count($settings['values']['new_settings']);
  }
  else {
    $settings = $context['sandbox']['settings'];
  }
  if ($context['sandbox']['max'] == 0) {
    // If we have no settings to process, immediately finish.
    $context['finished'] = 1;
  }
  else {
    // Load the optional services.
    $this->replicateReplicator = \Drupal::service('replicate.replicator');
    $this->fieldToolsFieldCloner = \Drupal::service('field_tools.field_cloner');
    $this->fieldToolsDisplayCloner = \Drupal::service('field_tools.display_cloner');
    // Replicate the next setting.
    $key = $context['sandbox']['progress'];
    $setting = $settings['values']['new_settings'][$key];
    $this
      ->replicateSetting($setting, $settings['values']['setting']);
    $context['results']['current_id'] = $key;
    $context['sandbox']['progress']++;
    $context['sandbox']['current_id'] = $key;
    // Set the current message.
    $context['message'] = $this
      ->t('Processed @num of @total new settings.', [
      '@num' => $context['sandbox']['progress'],
      '@total' => $context['sandbox']['max'],
    ]);
    // Check if we are now finished.
    if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
      $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
    }
  }
}