From f0cd665f4f208d1006247a5b316d61aec536b3cf Mon Sep 17 00:00:00 2001 From: Lee Rowlands <lee.rowlands@previousnext.com.au> Date: Fri, 3 Jan 2025 14:04:34 +1000 Subject: [PATCH] Issue #3495509 by nicxvan: Mark Locale module procedural hooks as converted --- core/modules/locale/locale.batch.inc | 2 + core/modules/locale/locale.bulk.inc | 2 + core/modules/locale/locale.compare.inc | 2 + core/modules/locale/locale.fetch.inc | 2 + core/modules/locale/locale.install | 130 +++++++++++---------- core/modules/locale/locale.module | 2 + core/modules/locale/locale.pages.inc | 2 + core/modules/locale/locale.translation.inc | 2 + 8 files changed, 80 insertions(+), 64 deletions(-) diff --git a/core/modules/locale/locale.batch.inc b/core/modules/locale/locale.batch.inc index 408ba383fa8c..66c44e465bc2 100644 --- a/core/modules/locale/locale.batch.inc +++ b/core/modules/locale/locale.batch.inc @@ -7,6 +7,7 @@ use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\Exception\InvalidStreamWrapperException; use Drupal\Core\File\FileExists; +use Drupal\Core\Hook\Attribute\StopProceduralHookScan; use Drupal\Core\Url; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; @@ -36,6 +37,7 @@ * @param array|\ArrayAccess $context * The batch context. */ +#[StopProceduralHookScan] function locale_translation_batch_version_check(string $project, string $langcode, array|\ArrayAccess &$context) { $locale_project = \Drupal::service('locale.project')->get($project); diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 56ca32b57ee7..e63ee7a45aa4 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -6,6 +6,7 @@ use Drupal\Core\Batch\BatchBuilder; use Drupal\Core\File\Exception\FileException; +use Drupal\Core\Hook\Attribute\StopProceduralHookScan; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Url; use Drupal\file\FileInterface; @@ -36,6 +37,7 @@ * l10n_update functionality to feed in translation files alike. * https://www.drupal.org/node/1191488 */ +#[StopProceduralHookScan] function locale_translate_batch_import_files(array $options, $force = FALSE) { $options += [ 'overwrite_options' => [], diff --git a/core/modules/locale/locale.compare.inc b/core/modules/locale/locale.compare.inc index 8c46c245a9f8..89155a39cdc4 100644 --- a/core/modules/locale/locale.compare.inc +++ b/core/modules/locale/locale.compare.inc @@ -5,6 +5,7 @@ */ use Drupal\Core\Batch\BatchBuilder; +use Drupal\Core\Hook\Attribute\StopProceduralHookScan; use Drupal\Core\Utility\ProjectInfo; /** @@ -17,6 +18,7 @@ /** * Clear the project data table. */ +#[StopProceduralHookScan] function locale_translation_flush_projects() { \Drupal::service('locale.project')->deleteAll(); } diff --git a/core/modules/locale/locale.fetch.inc b/core/modules/locale/locale.fetch.inc index d47a9f1f59da..25b657f8abac 100644 --- a/core/modules/locale/locale.fetch.inc +++ b/core/modules/locale/locale.fetch.inc @@ -5,6 +5,7 @@ */ use Drupal\Core\Batch\BatchBuilder; +use Drupal\Core\Hook\Attribute\StopProceduralHookScan; /** * Load the common translation API. @@ -27,6 +28,7 @@ * @return array * Batch definition array. */ +#[StopProceduralHookScan] function locale_translation_batch_update_build($projects = [], $langcodes = [], $options = []) { \Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.compare'); $projects = $projects ? $projects : array_keys(locale_translation_get_projects()); diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index cf034cc6f36f..774465e195b8 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -7,12 +7,78 @@ use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\Hook\Attribute\StopProceduralHookScan; use Drupal\Core\Link; use Drupal\Core\Url; +/** + * Implements hook_requirements(). + */ +function locale_requirements($phase) { + $requirements = []; + if ($phase == 'runtime') { + $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' => t('Translation update status'), + 'value' => Link::fromTextAndUrl(t('Updates available'), Url::fromRoute('locale.translate_status'))->toString(), + 'severity' => REQUIREMENT_WARNING, + 'description' => 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' => t('Translation update status'), + 'value' => t('Missing translations'), + 'severity' => REQUIREMENT_INFO, + 'description' => 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' => t('Translation update status'), + 'value' => t('Up to date'), + 'severity' => REQUIREMENT_OK, + ]; + } + } + else { + $requirements['locale_translation'] = [ + 'title' => t('Translation update status'), + 'value' => Link::fromTextAndUrl(t('Can not determine status'), Url::fromRoute('locale.translate_status'))->toString(), + 'severity' => REQUIREMENT_WARNING, + 'description' => 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; +} + /** * Implements hook_install(). */ +#[StopProceduralHookScan] function locale_install(): void { // Create the interface translations directory and ensure it's writable. if (!$directory = \Drupal::config('locale.settings')->get('translation.path')) { @@ -252,70 +318,6 @@ function locale_schema(): array { return $schema; } -/** - * Implements hook_requirements(). - */ -function locale_requirements($phase) { - $requirements = []; - if ($phase == 'runtime') { - $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' => t('Translation update status'), - 'value' => Link::fromTextAndUrl(t('Updates available'), Url::fromRoute('locale.translate_status'))->toString(), - 'severity' => REQUIREMENT_WARNING, - 'description' => 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' => t('Translation update status'), - 'value' => t('Missing translations'), - 'severity' => REQUIREMENT_INFO, - 'description' => 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' => t('Translation update status'), - 'value' => t('Up to date'), - 'severity' => REQUIREMENT_OK, - ]; - } - } - else { - $requirements['locale_translation'] = [ - 'title' => t('Translation update status'), - 'value' => Link::fromTextAndUrl(t('Can not determine status'), Url::fromRoute('locale.translate_status'))->toString(), - 'severity' => REQUIREMENT_WARNING, - 'description' => 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; -} - /** * Implements hook_update_last_removed(). */ diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 56083f16dc57..dc5d753fa69f 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -11,6 +11,7 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\Hook\Attribute\StopProceduralHookScan; use Drupal\Core\Installer\InstallerKernel; use Drupal\Core\Site\Settings; use Drupal\Core\Form\FormStateInterface; @@ -141,6 +142,7 @@ * Array of installed languages keyed by language name. English is omitted * unless it is marked as translatable. */ +#[StopProceduralHookScan] function locale_translatable_language_list() { $languages = \Drupal::languageManager()->getLanguages(); if (!locale_is_translatable('en')) { diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index ca6fc45836c0..e016a1a99a3f 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -4,6 +4,7 @@ * @file */ +use Drupal\Core\Hook\Attribute\StopProceduralHookScan; use Drupal\Core\Link; use Drupal\Core\Url; @@ -21,6 +22,7 @@ * * @see \Drupal\locale\Form\TranslationStatusForm */ +#[StopProceduralHookScan] function template_preprocess_locale_translation_update_info(array &$variables): void { foreach ($variables['updates'] as $update) { $variables['modules'][] = $update['name']; diff --git a/core/modules/locale/locale.translation.inc b/core/modules/locale/locale.translation.inc index b0c577c14850..7bb8502c53f3 100644 --- a/core/modules/locale/locale.translation.inc +++ b/core/modules/locale/locale.translation.inc @@ -4,6 +4,7 @@ * @file */ +use Drupal\Core\Hook\Attribute\StopProceduralHookScan; use Drupal\Core\StreamWrapper\StreamWrapperManager; /** @@ -53,6 +54,7 @@ * * @see locale_translation_build_projects() */ +#[StopProceduralHookScan] function locale_translation_get_projects(array $project_names = []) { $projects = &drupal_static(__FUNCTION__, []); -- GitLab