. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\FlashMessages; use Fisharebest\Webtrees\I18N; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; /** * Class CustomCssJsModule - add CSS and JS to every page */ class CustomCssJsModule extends AbstractModule implements ModuleConfigInterface, ModuleGlobalInterface { use ModuleConfigTrait; use ModuleGlobalTrait; /** * A sentence describing what this module does. * * @return string */ public function description(): string { /* I18N: Description of the “CSS and JS” module. */ return I18N::translate('Add styling and scripts to every page.'); } /** * Should this module be enabled when it is first installed? * * @return bool */ public function isEnabledByDefault(): bool { return false; } /** * Show a form to edit the user CSS and JS. * * @param ServerRequestInterface $request * * @return ResponseInterface */ public function getAdminAction(/** @scrutinizer ignore-unused */ ServerRequestInterface $request): ResponseInterface { $this->layout = 'layouts/administration'; return $this->viewResponse('modules/custom-css-js/edit', [ 'title' => $this->title(), 'head' => $this->getPreference('head'), 'body' => $this->getPreference('body'), ]); } /** * How should this module be identified in the control panel, etc.? * * @return string */ public function title(): string { /* I18N: Name of a module. */ return I18N::translate('CSS and JS'); } /** * Save the user CSS and JS. * * @param ServerRequestInterface $request * * @return ResponseInterface */ public function postAdminAction(ServerRequestInterface $request): ResponseInterface { $params = (array) $request->getParsedBody(); $this->setPreference('body', $params['body']); $this->setPreference('head', $params['head']); $message = I18N::translate('The preferences for the module “%s” have been updated.', $this->title()); FlashMessages::addMessage($message, 'success'); return redirect($this->getConfigLink()); } /** * Raw content, to be added at the end of the
element. * Typically, this will be