Skip to content

Commit 7246ff6

Browse files
committed
refactor(hook): use new hook runtime and mark the old one as legacy
1 parent f107007 commit 7246ff6

3 files changed

Lines changed: 65 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- refactor(hook): use new hook runtime and mark the old one as legacy
810

911
## [1.3.1] - 2026-02-25
1012
### Removed

modules/entity_to_text_tika/entity_to_text_tika.install

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,26 @@
55
* Install, update and uninstall fn for the Entity to Text Tika sub-module.
66
*/
77

8+
use Drupal\Core\Hook\Attribute\LegacyRequirementsHook;
9+
use Drupal\entity_to_text_tika\Hook\EntityToTextTikaRequirementsHook;
10+
811
/**
912
* 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
1018
*/
19+
#[LegacyRequirementsHook]
1120
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-
2021
if ($phase !== 'runtime') {
21-
return $requirements;
22+
return [];
2223
}
2324

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);
4328

44-
return $requirements;
29+
return $hook->runtime();
4530
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Drupal\entity_to_text_tika\Hook;
4+
5+
use Drupal\Core\File\FileSystemInterface;
6+
use Drupal\Core\Hook\Attribute\Hook;
7+
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
8+
use Drupal\Core\StringTranslation\StringTranslationTrait;
9+
10+
/**
11+
* RuntimeRequirements for entity to text tika.
12+
*/
13+
final class EntityToTextTikaRequirementsHook {
14+
use StringTranslationTrait;
15+
16+
public function __construct(protected readonly StreamWrapperManagerInterface $streamWrapperManager, protected readonly FileSystemInterface $fileSystem) {
17+
}
18+
19+
/**
20+
* Implements hook_runtime_requirements().
21+
*/
22+
#[Hook('runtime_requirements')]
23+
public function runtime(): array {
24+
$requirements = [];
25+
26+
$requirements['entity_to_text_tika_private'] = [
27+
'title' => $this->t('Entity to Text (Tika): Local File Storage (OCR cache)'),
28+
'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.'),
29+
'value' => $this->t('Private file system is set and writtable.'),
30+
];
31+
32+
// Check if the private file stream wrapper is ready to use.
33+
if (!$this->streamWrapperManager->isValidScheme('private')) {
34+
$requirements['entity_to_text_tika_private']['value'] = 'Private file system is not set.';
35+
$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.');
36+
$requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_INFO;
37+
}
38+
39+
$private_path = $this->fileSystem->realpath('private://');
40+
// Check if the private file stream wrapper is ready to use.
41+
if (!is_dir($private_path) || !is_writable($private_path)) {
42+
$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]);
43+
$requirements['entity_to_text_tika_private']['severity'] = REQUIREMENT_ERROR;
44+
}
45+
46+
return $requirements;
47+
}
48+
49+
}

0 commit comments

Comments
 (0)