|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
|
5
|
|
|
* |
|
6
|
|
|
* @package MyArtJaub\Webtrees |
|
7
|
|
|
* @subpackage MiscExtensions |
|
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2009-2022, Jonathan Jaubart |
|
10
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace MyArtJaub\Webtrees\Module\MiscExtensions\Http\RequestHandlers; |
|
16
|
|
|
|
|
17
|
|
|
use Fisharebest\Webtrees\FlashMessages; |
|
18
|
|
|
use Fisharebest\Webtrees\I18N; |
|
19
|
|
|
use Fisharebest\Webtrees\Registry; |
|
20
|
|
|
use Fisharebest\Webtrees\Validator; |
|
21
|
|
|
use Fisharebest\Webtrees\Services\ModuleService; |
|
22
|
|
|
use MyArtJaub\Webtrees\Module\MiscExtensions\MiscExtensionsModule; |
|
23
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
24
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
25
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Request handler for saving the configuration of the module |
|
29
|
|
|
*/ |
|
30
|
|
|
class AdminConfigAction implements RequestHandlerInterface |
|
31
|
|
|
{ |
|
32
|
|
|
private ?MiscExtensionsModule $module; |
|
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
|
|
|
} |
|
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
|
|
|
} |
|
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
|
|
|
(string) Validator::parsedBody($request)->integer('MAJ_DISPLAY_CNIL', 0) |
|
65
|
|
|
); |
|
66
|
|
|
$this->module->setPreference( |
|
67
|
|
|
'MAJ_CNIL_REFERENCE', |
|
68
|
|
|
Validator::parsedBody($request)->string('MAJ_CNIL_REFERENCE', '') |
|
69
|
|
|
); |
|
70
|
|
|
$this->module->setPreference( |
|
71
|
|
|
'MAJ_USE_LEGACY_XREF', |
|
72
|
|
|
(string) Validator::parsedBody($request)->integer('MAJ_USE_LEGACY_XREF', 0) |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
FlashMessages::addMessage( |
|
76
|
|
|
I18N::translate('The preferences for the module ā%sā have been updated.', $this->module->title()), |
|
77
|
|
|
'success' |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
return Registry::responseFactory()->redirect(AdminConfigPage::class); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|