Skip to content

Commit 2c7378f

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

3 files changed

Lines changed: 54 additions & 0 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
* Install, update and uninstall fn for the Entity to Text Tika sub-module.
66
*/
77

8+
use Drupal\Core\Hook\Attribute\LegacyRequirementsHook;
9+
810
/**
911
* Implements hook_requirements().
1012
*/
13+
#[LegacyRequirementsHook]
1114
function entity_to_text_tika_requirements($phase = 'runtime') {
1215
$requirements = [];
1316
$stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');
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)