locale_config_batch_build

locale_config_batch_build(array $names, array $langcodes, array $options = array())

Creates a locale batch to refresh specific configuration.

Parameters

array $names: List of configuration object names (which are strings) to update.

array $langcodes: List of language codes to refresh.

array $options: (optional) An array with options that can have the following elements:

  • 'finish_feedback': Whether or not to give feedback to the user when the batch is finished. Defaults to TRUE.

Return value

array The batch definition.

See also

locale_config_batch_refresh_name()

File

core/modules/locale/locale.bulk.inc, line 558
Mass import-export and batch import functionality for Gettext .po files.

Code

function locale_config_batch_build(array $names, array $langcodes, array $options = array()) {
  $options += array('finish_feedback' => TRUE);
  $i = 0;
  $batch_names = array();
  $operations = array();
  foreach ($names as $name) {
    $batch_names[] = $name;
    $i++;
    // During installation the caching of configuration objects is disabled so
    // it is very expensive to initialize the \Drupal::config() object on each
    // request. We batch a small number of configuration object upgrades
    // together to improve the overall performance of the process.
    if ($i % 20 == 0) {
      $operations[] = array('locale_config_batch_refresh_name', array($batch_names, $langcodes));
      $batch_names = array();
    }
  }
  if (!empty($batch_names)) {
    $operations[] = array('locale_config_batch_refresh_name', array($batch_names, $langcodes));
  }
  $batch = array(
    'operations' => $operations,
    'title' => t('Updating configuration translations'),
    'init_message' => t('Starting configuration update'),
    'error_message' => t('Error updating configuration translations'),
    'file' => drupal_get_path('module', 'locale') . '/locale.bulk.inc',
  );
  if (!empty($options['finish_feedback'])) {
    $batch['completed'] = 'locale_config_batch_finished';
  }
  return $batch;
}
doc_Drupal
2016-10-29 09:24:13
Comments
Leave a Comment

Please login to continue.