|
5 | 5 | * Install, update and uninstall fn for the Entity to Text Tika sub-module. |
6 | 6 | */ |
7 | 7 |
|
| 8 | +use Drupal\Core\Hook\Attribute\LegacyRequirementsHook; |
| 9 | +use Drupal\entity_to_text_tika\Hook\EntityToTextTikaRequirementsHook; |
| 10 | + |
8 | 11 | /** |
9 | 12 | * Implements hook_requirements(). |
| 13 | + * |
| 14 | + * @deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use |
| 15 | + * hook_runtime_requirements() for runtime checks instead. |
| 16 | + * |
| 17 | + * @see https://www.drupal.org/node/3490851 |
10 | 18 | */ |
| 19 | +#[LegacyRequirementsHook] |
11 | 20 | function entity_to_text_tika_requirements($phase = 'runtime') { |
12 | | - $requirements = []; |
13 | | - $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager'); |
14 | | - $file_system = \Drupal::service('file_system'); |
15 | | - |
16 | | - /* ************************************************************************ */ |
17 | | - // Check private file directory. |
18 | | - /* ************************************************************************ */ |
19 | | - |
20 | 21 | if ($phase !== 'runtime') { |
21 | | - return $requirements; |
| 22 | + return []; |
22 | 23 | } |
23 | 24 |
|
24 | | - $requirements['entity_to_text_tika_private'] = [ |
25 | | - 'title' => t('Entity to Text (Tika): Local File Storage (OCR cache)'), |
26 | | - '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.'), |
27 | | - 'value' => t('Private file system is set and writtable.'), |
28 | | - ]; |
29 | | - |
30 | | - // Check if the private file stream wrapper is ready to use. |
31 | | - if (!$stream_wrapper_manager->isValidScheme('private')) { |
32 | | - $requirements['entity_to_text_tika_private']['value'] = 'Private file system is not set.'; |
33 | | - $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.'); |
34 | | - $requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_INFO; |
35 | | - } |
36 | | - |
37 | | - $private_path = $file_system->realpath('private://'); |
38 | | - // Check if the private file stream wrapper is ready to use. |
39 | | - if (!is_dir($private_path) || !is_writable($private_path)) { |
40 | | - $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]); |
41 | | - $requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_ERROR; |
42 | | - } |
| 25 | + $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager'); |
| 26 | + $file_system = \Drupal::service('file_system'); |
| 27 | + $hook = new EntityToTextTikaRequirementsHook($stream_wrapper_manager, $file_system); |
43 | 28 |
|
44 | | - return $requirements; |
| 29 | + return $hook->runtime(); |
45 | 30 | } |
0 commit comments