You are here

protected function TranslationStatusForm::prepareUpdateData in Drupal 9

Same name and namespace in other branches
  1. 8 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.

1 call to TranslationStatusForm::prepareUpdateData()
TranslationStatusForm::buildForm in core/modules/locale/src/Form/TranslationStatusForm.php
Form builder for displaying the current translation 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_id => $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 = isset($project_info->files[LOCALE_TRANSLATION_LOCAL]) ? $project_info->files[LOCALE_TRANSLATION_LOCAL] : NULL;
        $remote = isset($project_info->files[LOCALE_TRANSLATION_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;
}