function TranslationStatusForm::prepareUpdateData

Same name and namespace in other branches
  1. 10 core/modules/locale/src/Form/TranslationStatusForm.php \Drupal\locale\Form\TranslationStatusForm::prepareUpdateData()
  2. 11.x core/modules/locale/src/Form/TranslationStatusForm.php \Drupal\locale\Form\TranslationStatusForm::prepareUpdateData()
  3. 8.9.x core/modules/locale/src/Form/TranslationStatusForm.php \Drupal\locale\Form\TranslationStatusForm::prepareUpdateData()

Prepare information about projects with available translation updates.

Parameters

array $status: Translation update status as an array keyed by Project ID and langcode.

Return value

array Translation update status as an array keyed by language code and translation update status.

File

core/modules/locale/src/Form/TranslationStatusForm.php, line 188

Class

TranslationStatusForm
Provides a translation status form.

Namespace

Drupal\locale\Form

Code

protected function prepareUpdateData(array $status) {
  $updates = [];
  // @todo Calling locale_translation_build_projects() is an expensive way to
  //   get a module name. In follow-up issue
  //   https://www.drupal.org/node/1842362 the project name will be stored to
  //   display use, like here.
  $this->moduleHandler
    ->loadInclude('locale', 'compare.inc');
  $project_data = locale_translation_build_projects();
  foreach ($status as $project) {
    foreach ($project as $langcode => $project_info) {
      // No translation file found for this project-language combination.
      if (empty($project_info->type)) {
        $updates[$langcode]['not_found'][] = [
          'name' => $project_info->name == 'drupal' ? $this->t('Drupal core') : $project_data[$project_info->name]->info['name'],
          'version' => $project_info->version,
          'info' => $this->createInfoString($project_info),
        ];
      }
      elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
        $local = $project_info->files[LOCALE_TRANSLATION_LOCAL] ?? NULL;
        $remote = $project_info->files[LOCALE_TRANSLATION_REMOTE] ?? NULL;
        $recent = _locale_translation_source_compare($local, $remote) == LOCALE_TRANSLATION_SOURCE_COMPARE_LT ? $remote : $local;
        $updates[$langcode]['updates'][] = [
          'name' => $project_info->name == 'drupal' ? $this->t('Drupal core') : $project_data[$project_info->name]->info['name'],
          'version' => $project_info->version,
          'timestamp' => $recent->timestamp,
        ];
      }
    }
  }
  return $updates;
}

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