. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Tree; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function assert; /** * Process a form to create a new submission. */ class CreateSubmissionAction implements RequestHandlerInterface { /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = $request->getAttribute('tree'); assert($tree instanceof Tree); $params = (array) $request->getParsedBody(); $submitter = $params['submitter']; $gedcom = "0 @@ SUBN\n1 SUBM @" . $submitter . '@'; $record = $tree->createRecord($gedcom); $record = Registry::submissionFactory()->new($record->xref(), $record->gedcom(), null, $tree); // id and text are for select2 / autocomplete // html is for interactive modals return response([ 'id' => '@' . $record->xref() . '@', 'text' => view('selects/submission', [ 'submission' => $record, ]), 'html' => view('modals/record-created', [ 'title' => I18N::translate('The submission has been created'), 'name' => $record->fullName(), 'url' => $record->url(), ]), ]); } }