. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\FlashMessages; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Site; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function assert; use function e; use function redirect; use function route; /** * Set the default tree. */ class SelectDefaultTree implements RequestHandlerInterface, StatusCodeInterface { /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = $request->getAttribute('tree'); assert($tree instanceof Tree); Site::setPreference('DEFAULT_GEDCOM', $tree->name()); /* I18N: %s is the name of a family tree */ $message = I18N::translate('The family tree ā€œ%sā€ will be shown to visitors when they first arrive at this website.', e($tree->title())); FlashMessages::addMessage($message, 'success'); $url = route(ManageTrees::class, ['tree' => $tree->name()]); return redirect($url); } }