summaryrefslogtreecommitdiff
path: root/app/Http/RequestHandlers/PasteFact.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-10-28 20:17:46 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-10-28 21:11:32 +0000
commit3b3db8adf3fd54bb8a196a781da9123905e54adf (patch)
tree5bde4709c771ea00529f79f8f45652c49a3a7c10 /app/Http/RequestHandlers/PasteFact.php
parentfc1d5378722fa0e1e930dd6d4c5742e419121965 (diff)
downloadwebtrees-3b3db8adf3fd54bb8a196a781da9123905e54adf.tar.gz
webtrees-3b3db8adf3fd54bb8a196a781da9123905e54adf.tar.bz2
webtrees-3b3db8adf3fd54bb8a196a781da9123905e54adf.zip
Fix: #2705 - Break EditGedcomRecordController into request handlers
Diffstat (limited to 'app/Http/RequestHandlers/PasteFact.php')
-rw-r--r--app/Http/RequestHandlers/PasteFact.php73
1 files changed, 73 insertions, 0 deletions
diff --git a/app/Http/RequestHandlers/PasteFact.php b/app/Http/RequestHandlers/PasteFact.php
new file mode 100644
index 0000000000..b37a18645a
--- /dev/null
+++ b/app/Http/RequestHandlers/PasteFact.php
@@ -0,0 +1,73 @@
+<?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\Services\ClipboardService;
+use Fisharebest\Webtrees\Tree;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+
+use function assert;
+use function redirect;
+
+/**
+ * Paste a fact from the clipboard.
+ */
+class PasteFact implements RequestHandlerInterface
+{
+ /** @var ClipboardService */
+ private $clipboard_service;
+
+ /**
+ * EditGedcomRecordController constructor.
+ *
+ * @param ClipboardService $clipboard_service
+ */
+ public function __construct(ClipboardService $clipboard_service)
+ {
+ $this->clipboard_service = $clipboard_service;
+ }
+
+ /**
+ * Paste a fact from the clipboard into a record.
+ *
+ * @param ServerRequestInterface $request
+ *
+ * @return ResponseInterface
+ */
+ public function handle(ServerRequestInterface $request): ResponseInterface
+ {
+ $tree = $request->getAttribute('tree');
+ assert($tree instanceof Tree);
+
+ $xref = $request->getAttribute('xref');
+ $fact_id = $request->getParsedBody()['fact_id'];
+ $record = GedcomRecord::getInstance($xref, $tree);
+
+ Auth::checkRecordAccess($record, true);
+
+ $this->clipboard_service->pasteFact($fact_id, $record);
+
+ return redirect($record->url());
+ }
+}