. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\FlashMessages; use Fisharebest\Webtrees\I18N; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; /** * 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. * * @return Response */ public function getAdminAction(): Response { $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 Request $request * * @return RedirectResponse */ public function postAdminAction(Request $request): RedirectResponse { $this->setPreference('body', $request->get('body', '')); $this->setPreference('head', $request->get('head', '')); $message = I18N::translate('The preferences for the module “%s” have been updated.', $this->title()); FlashMessages::addMessage($message, 'success'); return new RedirectResponse($this->getConfigLink()); } /** * Raw content, to be added at the end of the element. * Typically, this will be