From 7246ff68807f2fd1e3cab7dd19575bfcaf03e15e Mon Sep 17 00:00:00 2001 From: Kevin Wenger Date: Fri, 15 May 2026 15:59:45 +0200 Subject: [PATCH] refactor(hook): use new hook runtime and mark the old one as legacy --- CHANGELOG.md | 2 + .../entity_to_text_tika.install | 43 ++++++---------- .../Hook/EntityToTextTikaRequirementsHook.php | 49 +++++++++++++++++++ 3 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 modules/entity_to_text_tika/src/Hook/EntityToTextTikaRequirementsHook.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 97bbe23..1a53400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- refactor(hook): use new hook runtime and mark the old one as legacy ## [1.3.1] - 2026-02-25 ### Removed diff --git a/modules/entity_to_text_tika/entity_to_text_tika.install b/modules/entity_to_text_tika/entity_to_text_tika.install index 7dd3c4d..f8ccea4 100644 --- a/modules/entity_to_text_tika/entity_to_text_tika.install +++ b/modules/entity_to_text_tika/entity_to_text_tika.install @@ -5,41 +5,26 @@ * Install, update and uninstall fn for the Entity to Text Tika sub-module. */ +use Drupal\Core\Hook\Attribute\LegacyRequirementsHook; +use Drupal\entity_to_text_tika\Hook\EntityToTextTikaRequirementsHook; + /** * Implements hook_requirements(). + * + * @deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use + * hook_runtime_requirements() for runtime checks instead. + * + * @see https://www.drupal.org/node/3490851 */ +#[LegacyRequirementsHook] function entity_to_text_tika_requirements($phase = 'runtime') { - $requirements = []; - $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager'); - $file_system = \Drupal::service('file_system'); - - /* ************************************************************************ */ - // Check private file directory. - /* ************************************************************************ */ - if ($phase !== 'runtime') { - return $requirements; + return []; } - $requirements['entity_to_text_tika_private'] = [ - 'title' => t('Entity to Text (Tika): Local File Storage (OCR cache)'), - 'description' => t('Entity to Text Tika expose a Local File Storage optimisation in order to store OCR of document in the private:// schema. The current private schema configuration can leverage it.'), - 'value' => t('Private file system is set and writtable.'), - ]; - - // Check if the private file stream wrapper is ready to use. - if (!$stream_wrapper_manager->isValidScheme('private')) { - $requirements['entity_to_text_tika_private']['value'] = 'Private file system is not set.'; - $requirements['entity_to_text_tika_private']['description'] = t('Entity to Text Tika expose a Local File Storage optimisation in order to store OCR of document in the private:// schema. The current private schema configuration cannot leverage it.'); - $requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_INFO; - } - - $private_path = $file_system->realpath('private://'); - // Check if the private file stream wrapper is ready to use. - if (!is_dir($private_path) || !is_writable($private_path)) { - $requirements['entity_to_text_tika_private']['value'] = t('Entity to Text Tika expose a Local File Storage optimisation in order to store OCR of document in the private:// schema. The current private schema configuration cannot leverage it. The resolved private directory %directory% seems not writable.', ['%directory%' => $private_path]); - $requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_ERROR; - } + $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager'); + $file_system = \Drupal::service('file_system'); + $hook = new EntityToTextTikaRequirementsHook($stream_wrapper_manager, $file_system); - return $requirements; + return $hook->runtime(); } diff --git a/modules/entity_to_text_tika/src/Hook/EntityToTextTikaRequirementsHook.php b/modules/entity_to_text_tika/src/Hook/EntityToTextTikaRequirementsHook.php new file mode 100644 index 0000000..e1e3f07 --- /dev/null +++ b/modules/entity_to_text_tika/src/Hook/EntityToTextTikaRequirementsHook.php @@ -0,0 +1,49 @@ + $this->t('Entity to Text (Tika): Local File Storage (OCR cache)'), + 'description' => $this->t('Entity to Text Tika expose a Local File Storage optimisation in order to store OCR of document in the private:// schema. The current private schema configuration can leverage it.'), + 'value' => $this->t('Private file system is set and writtable.'), + ]; + + // Check if the private file stream wrapper is ready to use. + if (!$this->streamWrapperManager->isValidScheme('private')) { + $requirements['entity_to_text_tika_private']['value'] = 'Private file system is not set.'; + $requirements['entity_to_text_tika_private']['description'] = $this->t('Entity to Text Tika expose a Local File Storage optimisation in order to store OCR of document in the private:// schema. The current private schema configuration cannot leverage it.'); + $requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_INFO; + } + + $private_path = $this->fileSystem->realpath('private://'); + // Check if the private file stream wrapper is ready to use. + if (!is_dir($private_path) || !is_writable($private_path)) { + $requirements['entity_to_text_tika_private']['value'] = $this->t('Entity to Text Tika expose a Local File Storage optimisation in order to store OCR of document in the private:// schema. The current private schema configuration cannot leverage it. The resolved private directory %directory% seems not writable.', ['%directory%' => $private_path]); + $requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_ERROR; + } + + return $requirements; + } + +}