app/Module/MiscExtensions/Http/RequestHandlers/AdminConfigPage.php
<?php
/**
* webtrees-lib: MyArtJaub library for webtrees
*
* @package MyArtJaub\Webtrees
* @subpackage MiscExtensions
* @author Jonathan Jaubart <dev@jaubart.com>
* @copyright Copyright (c) 2009-2022, Jonathan Jaubart
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
*/
declare(strict_types=1);
namespace MyArtJaub\Webtrees\Module\MiscExtensions\Http\RequestHandlers;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException;
use Fisharebest\Webtrees\Http\ViewResponseTrait;
use Fisharebest\Webtrees\Services\ModuleService;
use MyArtJaub\Webtrees\Module\MiscExtensions\MiscExtensionsModule;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
/**
* Request handler for displaying configuration of the module
*/
class AdminConfigPage implements RequestHandlerInterface
{
use ViewResponseTrait;
private ?MiscExtensionsModule $module;
/**
* Constructor for AdminConfigPage Request Handler
*
* @param ModuleService $module_service
*/
public function __construct(ModuleService $module_service)
{
$this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first();
}
/**
* {@inheritDoc}
* @see \Psr\Http\Server\RequestHandlerInterface::handle()
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->layout = 'layouts/administration';
if ($this->module === null) {
throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
}
return $this->viewResponse($this->module->name() . '::admin/config', [
'module' => $this->module,
'title' => $this->module->title()
]);
}
}