@@ -30,87 +30,87 @@ |
||
30 | 30 | */ |
31 | 31 | class SourceCertificateIconHook implements FactSourceTextExtenderInterface |
32 | 32 | { |
33 | - private CertificatesModule $module; |
|
34 | - private UrlObfuscatorService $url_obfuscator_service; |
|
33 | + private CertificatesModule $module; |
|
34 | + private UrlObfuscatorService $url_obfuscator_service; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for SourceCertificateIconHook |
|
38 | - * |
|
39 | - * @param CertificatesModule $module |
|
40 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
41 | - */ |
|
42 | - public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
43 | - { |
|
44 | - $this->module = $module; |
|
45 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
46 | - } |
|
36 | + /** |
|
37 | + * Constructor for SourceCertificateIconHook |
|
38 | + * |
|
39 | + * @param CertificatesModule $module |
|
40 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
41 | + */ |
|
42 | + public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
43 | + { |
|
44 | + $this->module = $module; |
|
45 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
51 | - */ |
|
52 | - public function module(): ModuleInterface |
|
53 | - { |
|
54 | - return $this->module; |
|
55 | - } |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
51 | + */ |
|
52 | + public function module(): ModuleInterface |
|
53 | + { |
|
54 | + return $this->module; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
60 | - */ |
|
61 | - public function factSourcePrepend(Tree $tree, $fact): string |
|
62 | - { |
|
63 | - $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
64 | - if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level) { |
|
65 | - $path = $this->extractPath($fact); |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
60 | + */ |
|
61 | + public function factSourcePrepend(Tree $tree, $fact): string |
|
62 | + { |
|
63 | + $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
64 | + if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level) { |
|
65 | + $path = $this->extractPath($fact); |
|
66 | 66 | |
67 | - if ($path !== '') { |
|
68 | - $certificate = new Certificate($tree, $path); |
|
69 | - return view($this->module->name() . '::components/certificate-icon', [ |
|
70 | - 'module_name' => $this->module->name(), |
|
71 | - 'certificate' => $certificate, |
|
72 | - 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
73 | - 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
74 | - ]); |
|
75 | - } |
|
76 | - } |
|
77 | - return ''; |
|
78 | - } |
|
67 | + if ($path !== '') { |
|
68 | + $certificate = new Certificate($tree, $path); |
|
69 | + return view($this->module->name() . '::components/certificate-icon', [ |
|
70 | + 'module_name' => $this->module->name(), |
|
71 | + 'certificate' => $certificate, |
|
72 | + 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
73 | + 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
74 | + ]); |
|
75 | + } |
|
76 | + } |
|
77 | + return ''; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Extract path from the provided fact objet. |
|
82 | - * |
|
83 | - * @param \Fisharebest\Webtrees\Fact|array<array<\Fisharebest\Webtrees\Contracts\ElementInterface|string>> $fact |
|
84 | - * @return string |
|
85 | - * @psalm-suppress RedundantConditionGivenDocblockType |
|
86 | - */ |
|
87 | - private function extractPath($fact): string |
|
88 | - { |
|
89 | - if ($fact instanceof Fact && $fact->target() instanceof Source) { |
|
90 | - return $fact->attribute('_ACT'); |
|
91 | - } elseif ( |
|
92 | - is_array($fact) && count($fact) === 2 |
|
93 | - && null !== ($source_elements = $fact[0]) && is_array($source_elements) // @phpstan-ignore-line |
|
94 | - && null !== ($source_values = $fact[1]) && is_array($source_values) // @phpstan-ignore-line |
|
95 | - ) { |
|
96 | - foreach ($source_elements as $key => $element) { |
|
97 | - if ( |
|
98 | - $element instanceof SourceCertificate |
|
99 | - && isset($source_values[$key]) && is_string($source_values[$key]) |
|
100 | - ) { |
|
101 | - return $element->canonical($source_values[$key]); |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - return ''; |
|
106 | - } |
|
80 | + /** |
|
81 | + * Extract path from the provided fact objet. |
|
82 | + * |
|
83 | + * @param \Fisharebest\Webtrees\Fact|array<array<\Fisharebest\Webtrees\Contracts\ElementInterface|string>> $fact |
|
84 | + * @return string |
|
85 | + * @psalm-suppress RedundantConditionGivenDocblockType |
|
86 | + */ |
|
87 | + private function extractPath($fact): string |
|
88 | + { |
|
89 | + if ($fact instanceof Fact && $fact->target() instanceof Source) { |
|
90 | + return $fact->attribute('_ACT'); |
|
91 | + } elseif ( |
|
92 | + is_array($fact) && count($fact) === 2 |
|
93 | + && null !== ($source_elements = $fact[0]) && is_array($source_elements) // @phpstan-ignore-line |
|
94 | + && null !== ($source_values = $fact[1]) && is_array($source_values) // @phpstan-ignore-line |
|
95 | + ) { |
|
96 | + foreach ($source_elements as $key => $element) { |
|
97 | + if ( |
|
98 | + $element instanceof SourceCertificate |
|
99 | + && isset($source_values[$key]) && is_string($source_values[$key]) |
|
100 | + ) { |
|
101 | + return $element->canonical($source_values[$key]); |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + return ''; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * {@inheritDoc} |
|
110 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
111 | - */ |
|
112 | - public function factSourceAppend(Tree $tree, $fact): string |
|
113 | - { |
|
114 | - return ''; |
|
115 | - } |
|
108 | + /** |
|
109 | + * {@inheritDoc} |
|
110 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
111 | + */ |
|
112 | + public function factSourceAppend(Tree $tree, $fact): string |
|
113 | + { |
|
114 | + return ''; |
|
115 | + } |
|
116 | 116 | } |
@@ -34,163 +34,163 @@ |
||
34 | 34 | */ |
35 | 35 | class WelcomeBlockModule extends AbstractModule implements ModuleMyArtJaubInterface, ModuleBlockInterface |
36 | 36 | { |
37 | - use ModuleMyArtJaubTrait; |
|
38 | - use ModuleBlockTrait; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritDoc} |
|
42 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
43 | - */ |
|
44 | - public function title(): string |
|
45 | - { |
|
46 | - return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * {@inheritDoc} |
|
51 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
52 | - */ |
|
53 | - public function description(): string |
|
54 | - { |
|
55 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
56 | - return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
62 | - */ |
|
63 | - public function loadRoutes(Map $router): void |
|
64 | - { |
|
65 | - $router->attach('', '', static function (Map $router): void { |
|
66 | - |
|
67 | - $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
68 | - $router->tokens(['block_id' => '\d+']); |
|
69 | - $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
70 | - }); |
|
71 | - }); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * {@inheritDoc} |
|
76 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
77 | - */ |
|
78 | - public function customModuleVersion(): string |
|
79 | - { |
|
80 | - return '2.1.1-v.1'; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * {@inheritDoc} |
|
85 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
86 | - * |
|
87 | - * @param mixed[] $config |
|
88 | - */ |
|
89 | - public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
90 | - { |
|
91 | - $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
92 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
93 | - |
|
94 | - $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
95 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
96 | - |
|
97 | - $content = view($this->name() . '::block-embed', [ |
|
98 | - 'block_id' => $block_id, |
|
99 | - 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
100 | - 'fab_login_block_view' => $fab_login_block_view, |
|
101 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
102 | - 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
103 | - ]); |
|
104 | - |
|
105 | - if ($context !== self::CONTEXT_EMBED) { |
|
106 | - return view('modules/block-template', [ |
|
107 | - 'block' => Str::kebab($this->name()), |
|
108 | - 'id' => $block_id, |
|
109 | - 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
110 | - 'title' => e($tree->title()), |
|
111 | - 'content' => $content, |
|
112 | - ]); |
|
113 | - } |
|
114 | - |
|
115 | - return $content; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * {@inheritDoc} |
|
120 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
121 | - */ |
|
122 | - public function isTreeBlock(): bool |
|
123 | - { |
|
124 | - return true; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * {@inheritDoc} |
|
129 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
130 | - */ |
|
131 | - public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
132 | - { |
|
133 | - return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * {@inheritDoc} |
|
138 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
139 | - */ |
|
140 | - public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
141 | - { |
|
142 | - $matomo_enabled = Validator::parsedBody($request)->string('matomo_enabled', '') === 'yes'; |
|
143 | - $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
144 | - if (!$matomo_enabled) { |
|
145 | - return; |
|
146 | - } |
|
147 | - |
|
148 | - $matomo_url = trim(Validator::parsedBody($request)->string('matomo_url', '')); |
|
149 | - if (filter_var($matomo_url, FILTER_VALIDATE_URL) === false) { |
|
150 | - FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
151 | - return; |
|
152 | - } |
|
153 | - |
|
154 | - $matomo_siteid = Validator::parsedBody($request)->integer('matomo_siteid', -1); |
|
155 | - if ($matomo_siteid === -1) { |
|
156 | - FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
157 | - return; |
|
158 | - } |
|
159 | - |
|
160 | - $matomo_token = trim(Validator::parsedBody($request)->string('matomo_token', '')); |
|
161 | - |
|
162 | - $this |
|
163 | - ->setBlockSetting($block_id, 'matomo_url', $matomo_url) |
|
164 | - ->setBlockSetting($block_id, 'matomo_token', $matomo_token) |
|
165 | - ->setBlockSetting($block_id, 'matomo_siteid', (string) $matomo_siteid); |
|
166 | - |
|
167 | - Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
172 | - * |
|
173 | - * @param int $block_id |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public function isMatomoEnabled(int $block_id): bool |
|
177 | - { |
|
178 | - return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
183 | - * |
|
184 | - * @param int $block_id |
|
185 | - * @return array<string, mixed> |
|
186 | - */ |
|
187 | - public function matomoSettings(int $block_id): array |
|
188 | - { |
|
189 | - return [ |
|
190 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
191 | - 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
192 | - 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
193 | - 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
194 | - ]; |
|
195 | - } |
|
37 | + use ModuleMyArtJaubTrait; |
|
38 | + use ModuleBlockTrait; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritDoc} |
|
42 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
43 | + */ |
|
44 | + public function title(): string |
|
45 | + { |
|
46 | + return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
52 | + */ |
|
53 | + public function description(): string |
|
54 | + { |
|
55 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
56 | + return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
62 | + */ |
|
63 | + public function loadRoutes(Map $router): void |
|
64 | + { |
|
65 | + $router->attach('', '', static function (Map $router): void { |
|
66 | + |
|
67 | + $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
68 | + $router->tokens(['block_id' => '\d+']); |
|
69 | + $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
70 | + }); |
|
71 | + }); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * {@inheritDoc} |
|
76 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
77 | + */ |
|
78 | + public function customModuleVersion(): string |
|
79 | + { |
|
80 | + return '2.1.1-v.1'; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * {@inheritDoc} |
|
85 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
86 | + * |
|
87 | + * @param mixed[] $config |
|
88 | + */ |
|
89 | + public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
90 | + { |
|
91 | + $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
92 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
93 | + |
|
94 | + $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
95 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
96 | + |
|
97 | + $content = view($this->name() . '::block-embed', [ |
|
98 | + 'block_id' => $block_id, |
|
99 | + 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
100 | + 'fab_login_block_view' => $fab_login_block_view, |
|
101 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
102 | + 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
103 | + ]); |
|
104 | + |
|
105 | + if ($context !== self::CONTEXT_EMBED) { |
|
106 | + return view('modules/block-template', [ |
|
107 | + 'block' => Str::kebab($this->name()), |
|
108 | + 'id' => $block_id, |
|
109 | + 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
110 | + 'title' => e($tree->title()), |
|
111 | + 'content' => $content, |
|
112 | + ]); |
|
113 | + } |
|
114 | + |
|
115 | + return $content; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * {@inheritDoc} |
|
120 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
121 | + */ |
|
122 | + public function isTreeBlock(): bool |
|
123 | + { |
|
124 | + return true; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * {@inheritDoc} |
|
129 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
130 | + */ |
|
131 | + public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
132 | + { |
|
133 | + return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * {@inheritDoc} |
|
138 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
139 | + */ |
|
140 | + public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
141 | + { |
|
142 | + $matomo_enabled = Validator::parsedBody($request)->string('matomo_enabled', '') === 'yes'; |
|
143 | + $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
144 | + if (!$matomo_enabled) { |
|
145 | + return; |
|
146 | + } |
|
147 | + |
|
148 | + $matomo_url = trim(Validator::parsedBody($request)->string('matomo_url', '')); |
|
149 | + if (filter_var($matomo_url, FILTER_VALIDATE_URL) === false) { |
|
150 | + FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
151 | + return; |
|
152 | + } |
|
153 | + |
|
154 | + $matomo_siteid = Validator::parsedBody($request)->integer('matomo_siteid', -1); |
|
155 | + if ($matomo_siteid === -1) { |
|
156 | + FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
157 | + return; |
|
158 | + } |
|
159 | + |
|
160 | + $matomo_token = trim(Validator::parsedBody($request)->string('matomo_token', '')); |
|
161 | + |
|
162 | + $this |
|
163 | + ->setBlockSetting($block_id, 'matomo_url', $matomo_url) |
|
164 | + ->setBlockSetting($block_id, 'matomo_token', $matomo_token) |
|
165 | + ->setBlockSetting($block_id, 'matomo_siteid', (string) $matomo_siteid); |
|
166 | + |
|
167 | + Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
172 | + * |
|
173 | + * @param int $block_id |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public function isMatomoEnabled(int $block_id): bool |
|
177 | + { |
|
178 | + return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
183 | + * |
|
184 | + * @param int $block_id |
|
185 | + * @return array<string, mixed> |
|
186 | + */ |
|
187 | + public function matomoSettings(int $block_id): array |
|
188 | + { |
|
189 | + return [ |
|
190 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
191 | + 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
192 | + 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
193 | + 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
194 | + ]; |
|
195 | + } |
|
196 | 196 | } |
@@ -29,50 +29,50 @@ |
||
29 | 29 | */ |
30 | 30 | class AdminConfigAction implements RequestHandlerInterface |
31 | 31 | { |
32 | - private ?MiscExtensionsModule $module; |
|
32 | + private ?MiscExtensionsModule $module; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructor for AdminConfigPage Request Handler |
|
36 | - * |
|
37 | - * @param ModuleService $module_service |
|
38 | - */ |
|
39 | - public function __construct(ModuleService $module_service) |
|
40 | - { |
|
41 | - $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first(); |
|
42 | - } |
|
34 | + /** |
|
35 | + * Constructor for AdminConfigPage Request Handler |
|
36 | + * |
|
37 | + * @param ModuleService $module_service |
|
38 | + */ |
|
39 | + public function __construct(ModuleService $module_service) |
|
40 | + { |
|
41 | + $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first(); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * {@inheritDoc} |
|
46 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
47 | - */ |
|
48 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
49 | - { |
|
50 | - if ($this->module === null) { |
|
51 | - FlashMessages::addMessage( |
|
52 | - I18N::translate('The attached module could not be found.'), |
|
53 | - 'danger' |
|
54 | - ); |
|
55 | - return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
56 | - } |
|
44 | + /** |
|
45 | + * {@inheritDoc} |
|
46 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
47 | + */ |
|
48 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
49 | + { |
|
50 | + if ($this->module === null) { |
|
51 | + FlashMessages::addMessage( |
|
52 | + I18N::translate('The attached module could not be found.'), |
|
53 | + 'danger' |
|
54 | + ); |
|
55 | + return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
56 | + } |
|
57 | 57 | |
58 | - $this->module->setPreference( |
|
59 | - 'MAJ_TITLE_PREFIX', |
|
60 | - Validator::parsedBody($request)->string('MAJ_TITLE_PREFIX', '') |
|
61 | - ); |
|
62 | - $this->module->setPreference( |
|
63 | - 'MAJ_DISPLAY_CNIL', |
|
64 | - Validator::parsedBody($request)->string('MAJ_DISPLAY_CNIL', '') |
|
65 | - ); |
|
66 | - $this->module->setPreference( |
|
67 | - 'MAJ_CNIL_REFERENCE', |
|
68 | - Validator::parsedBody($request)->string('MAJ_CNIL_REFERENCE', '') |
|
69 | - ); |
|
58 | + $this->module->setPreference( |
|
59 | + 'MAJ_TITLE_PREFIX', |
|
60 | + Validator::parsedBody($request)->string('MAJ_TITLE_PREFIX', '') |
|
61 | + ); |
|
62 | + $this->module->setPreference( |
|
63 | + 'MAJ_DISPLAY_CNIL', |
|
64 | + Validator::parsedBody($request)->string('MAJ_DISPLAY_CNIL', '') |
|
65 | + ); |
|
66 | + $this->module->setPreference( |
|
67 | + 'MAJ_CNIL_REFERENCE', |
|
68 | + Validator::parsedBody($request)->string('MAJ_CNIL_REFERENCE', '') |
|
69 | + ); |
|
70 | 70 | |
71 | - FlashMessages::addMessage( |
|
72 | - I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
73 | - 'success' |
|
74 | - ); |
|
71 | + FlashMessages::addMessage( |
|
72 | + I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
73 | + 'success' |
|
74 | + ); |
|
75 | 75 | |
76 | - return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
77 | - } |
|
76 | + return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
77 | + } |
|
78 | 78 | } |
@@ -31,58 +31,58 @@ |
||
31 | 31 | */ |
32 | 32 | class ModulesHooksAction extends AbstractModuleComponentAction |
33 | 33 | { |
34 | - protected HookService $hook_service; |
|
34 | + protected HookService $hook_service; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for ModulesHooksAction Request Handler |
|
38 | - * |
|
39 | - * @param ModuleService $module_service |
|
40 | - * @param TreeService $tree_service |
|
41 | - * @param HookService $hook_service |
|
42 | - */ |
|
43 | - public function __construct(ModuleService $module_service, TreeService $tree_service, HookService $hook_service) |
|
44 | - { |
|
45 | - parent::__construct($module_service, $tree_service); |
|
46 | - $this->hook_service = $hook_service; |
|
47 | - } |
|
36 | + /** |
|
37 | + * Constructor for ModulesHooksAction Request Handler |
|
38 | + * |
|
39 | + * @param ModuleService $module_service |
|
40 | + * @param TreeService $tree_service |
|
41 | + * @param HookService $hook_service |
|
42 | + */ |
|
43 | + public function __construct(ModuleService $module_service, TreeService $tree_service, HookService $hook_service) |
|
44 | + { |
|
45 | + parent::__construct($module_service, $tree_service); |
|
46 | + $this->hook_service = $hook_service; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritDoc} |
|
51 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | - */ |
|
53 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | - { |
|
55 | - $hook_name = Validator::attributes($request)->string('hook_name', ''); |
|
56 | - $hook_collector = $this->hook_service->find($hook_name, true); |
|
57 | - if ($hook_collector === null) { |
|
58 | - FlashMessages::addMessage(I18N::translate('The hook with name “%s” does not exist.', $hook_name), 'danger'); |
|
59 | - return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
60 | - } |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | + */ |
|
53 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | + { |
|
55 | + $hook_name = Validator::attributes($request)->string('hook_name', ''); |
|
56 | + $hook_collector = $this->hook_service->find($hook_name, true); |
|
57 | + if ($hook_collector === null) { |
|
58 | + FlashMessages::addMessage(I18N::translate('The hook with name “%s” does not exist.', $hook_name), 'danger'); |
|
59 | + return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
60 | + } |
|
61 | 61 | |
62 | - foreach ($hook_collector->hooks() as $hook) { |
|
63 | - $this->updateStatus(get_class($hook->module()), $request); |
|
64 | - } |
|
62 | + foreach ($hook_collector->hooks() as $hook) { |
|
63 | + $this->updateStatus(get_class($hook->module()), $request); |
|
64 | + } |
|
65 | 65 | |
66 | - $this->updateHookOrder($hook_collector, $request); |
|
66 | + $this->updateHookOrder($hook_collector, $request); |
|
67 | 67 | |
68 | - FlashMessages::addMessage(I18N::translate('The hook preferences have been updated.'), 'success'); |
|
68 | + FlashMessages::addMessage(I18N::translate('The hook preferences have been updated.'), 'success'); |
|
69 | 69 | |
70 | - return Registry::responseFactory()->redirect(ModulesHooksPage::class, ['hook_name' => $hook_name]); |
|
71 | - } |
|
70 | + return Registry::responseFactory()->redirect(ModulesHooksPage::class, ['hook_name' => $hook_name]); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Update the order of modules for a hook interface. |
|
75 | - * |
|
76 | - * @param HookCollectorInterface $hook_collector |
|
77 | - * @param ServerRequestInterface $request |
|
78 | - */ |
|
79 | - protected function updateHookOrder(HookCollectorInterface $hook_collector, ServerRequestInterface $request): void |
|
80 | - { |
|
81 | - $order = Validator::parsedBody($request)->array('order'); |
|
82 | - $order = array_flip($order); |
|
73 | + /** |
|
74 | + * Update the order of modules for a hook interface. |
|
75 | + * |
|
76 | + * @param HookCollectorInterface $hook_collector |
|
77 | + * @param ServerRequestInterface $request |
|
78 | + */ |
|
79 | + protected function updateHookOrder(HookCollectorInterface $hook_collector, ServerRequestInterface $request): void |
|
80 | + { |
|
81 | + $order = Validator::parsedBody($request)->array('order'); |
|
82 | + $order = array_flip($order); |
|
83 | 83 | |
84 | - foreach ($hook_collector->hooks() as $hook) { |
|
85 | - $this->hook_service->updateOrder($hook_collector, $hook->module(), $order[$hook->module()->name()] ?? 0); |
|
86 | - } |
|
87 | - } |
|
84 | + foreach ($hook_collector->hooks() as $hook) { |
|
85 | + $this->hook_service->updateOrder($hook_collector, $hook->module(), $order[$hook->module()->name()] ?? 0); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |