summaryrefslogtreecommitdiff
path: root/app/Http/RequestHandlers/AddNewFact.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-10-28 21:58:21 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-10-28 23:09:11 +0000
commit2917771c25c65897723561cdcefe19f90d29a925 (patch)
treeae96a7a13bf3514cfc6f05a198175fbbb56db435 /app/Http/RequestHandlers/AddNewFact.php
parent3b3db8adf3fd54bb8a196a781da9123905e54adf (diff)
downloadwebtrees-2917771c25c65897723561cdcefe19f90d29a925.tar.gz
webtrees-2917771c25c65897723561cdcefe19f90d29a925.tar.bz2
webtrees-2917771c25c65897723561cdcefe19f90d29a925.zip
Fix: #2706 - Break EditGedcomRecordController into request handlers
Diffstat (limited to 'app/Http/RequestHandlers/AddNewFact.php')
-rw-r--r--app/Http/RequestHandlers/AddNewFact.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/app/Http/RequestHandlers/AddNewFact.php b/app/Http/RequestHandlers/AddNewFact.php
new file mode 100644
index 0000000000..8785c97047
--- /dev/null
+++ b/app/Http/RequestHandlers/AddNewFact.php
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2019 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace Fisharebest\Webtrees\Http\RequestHandlers;
+
+use Fisharebest\Webtrees\Auth;
+use Fisharebest\Webtrees\GedcomRecord;
+use Fisharebest\Webtrees\GedcomTag;
+use Fisharebest\Webtrees\Http\ViewResponseTrait;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+use function assert;
+
+/**
+ * Add a new fact.
+ */
+class AddNewFact implements RequestHandlerInterface
+{
+ use ViewResponseTrait;
+
+ /**
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $tree = $request->getAttribute('tree');
+ assert($tree instanceof Tree);
+
+ $xref = $request->getAttribute('xref');
+ $fact = $request->getAttribute('fact');
+
+ $record = GedcomRecord::getInstance($xref, $tree);
+ Auth::checkRecordAccess($record, true);
+
+ $title = $record->fullName() . ' - ' . GedcomTag::getLabel($fact, $record);
+
+ return $this->viewResponse('edit/add-fact', [
+ 'fact' => $fact,
+ 'record' => $record,
+ 'title' => $title,
+ 'tree' => $tree,
+ ]);
+ }
+}