function LocaleRequirements::runtime

Implements hook_runtime_requirements().

Attributes

#[Hook('runtime_requirements')]

File

core/modules/locale/src/Hook/LocaleRequirements.php, line 23

Class

LocaleRequirements
Requirements for the Locale module.

Namespace

Drupal\locale\Hook

Code

public function runtime() : array {
    $requirements = [];
    $available_updates = [];
    $untranslated = [];
    $languages = locale_translatable_language_list();
    if ($languages) {
        // Determine the status of the translation updates per language.
        $status = locale_translation_get_status();
        if ($status) {
            foreach ($status as $project) {
                foreach ($project as $langcode => $project_info) {
                    if (empty($project_info->type)) {
                        $untranslated[$langcode] = $languages[$langcode]->getName();
                    }
                    elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
                        $available_updates[$langcode] = $languages[$langcode]->getName();
                    }
                }
            }
            if ($available_updates || $untranslated) {
                if ($available_updates) {
                    $requirements['locale_translation'] = [
                        'title' => $this->t('Translation update status'),
                        'value' => Link::fromTextAndUrl($this->t('Updates available'), Url::fromRoute('locale.translate_status'))
                            ->toString(),
                        'severity' => RequirementSeverity::Warning,
                        'description' => $this->t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', [
                            '@languages' => implode(', ', $available_updates),
                            ':updates' => Url::fromRoute('locale.translate_status')->toString(),
                        ]),
                    ];
                }
                else {
                    $requirements['locale_translation'] = [
                        'title' => $this->t('Translation update status'),
                        'value' => $this->t('Missing translations'),
                        'severity' => RequirementSeverity::Info,
                        'description' => $this->t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', [
                            '@languages' => implode(', ', $untranslated),
                            ':updates' => Url::fromRoute('locale.translate_status')->toString(),
                        ]),
                    ];
                }
            }
            else {
                $requirements['locale_translation'] = [
                    'title' => $this->t('Translation update status'),
                    'value' => $this->t('Up to date'),
                    'severity' => RequirementSeverity::OK,
                ];
            }
        }
        else {
            $requirements['locale_translation'] = [
                'title' => $this->t('Translation update status'),
                'value' => Link::fromTextAndUrl($this->t('Can not determine status'), Url::fromRoute('locale.translate_status'))
                    ->toString(),
                'severity' => RequirementSeverity::Warning,
                'description' => $this->t('No translation status is available. See the <a href=":updates">Available translation updates</a> page for more information.', [
                    ':updates' => Url::fromRoute('locale.translate_status')->toString(),
                ]),
            ];
        }
    }
    return $requirements;
}

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