function LocaleImportBatch::buildBatch

Same name and namespace in other branches
  1. 11.x core/modules/locale/src/LocaleImportBatch.php \Drupal\locale\LocaleImportBatch::buildBatch()

Build a locale batch from an array of files.

Parameters

array $files: Array of file objects to import.

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

Return value

array|bool A batch structure or FALSE if $files was empty.

File

core/modules/locale/src/LocaleImportBatch.php, line 66

Class

LocaleImportBatch
Provides the locale import batch services.

Namespace

Drupal\locale

Code

public function buildBatch(array $files, array $options) : array|bool {
  $options += [
    'overwrite_options' => [],
    'customized' => LocaleDefaultOptions::NOT_CUSTOMIZED,
    'finish_feedback' => TRUE,
  ];
  if (count($files)) {
    $batch_builder = (new BatchBuilder())->setTitle($this->t('Importing interface translations'))
      ->setErrorMessage($this->t('Error importing interface translations'));
    foreach ($files as $file) {
      // We call self::batchImport for every batch operation.
      $batch_builder->addOperation(self::class . ':batchImport', [
        $file,
        $options,
      ]);
    }
    // Save the translation status of all files.
    $batch_builder->addOperation(self::class . ':batchSave', []);
    // Add a final step to refresh JavaScript and configuration strings.
    $batch_builder->addOperation(self::class . ':batchRefresh', []);
    if ($options['finish_feedback']) {
      $batch_builder->setFinishCallback(self::class . ':batchFinished');
    }
    return $batch_builder->toArray();
  }
  return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.