. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Auth; 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; use function is_string; /** * Link a media object to a record. */ class LinkMediaToRecordAction implements RequestHandlerInterface { /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = $request->getAttribute('tree'); assert($tree instanceof Tree); $xref = $request->getAttribute('xref'); assert(is_string($xref)); $params = (array) $request->getParsedBody(); $link = $params['link'] ?? ''; $media = Registry::mediaFactory()->make($xref, $tree); $media = Auth::checkMediaAccess($media); $record = Registry::gedcomRecordFactory()->make($link, $tree); $record = Auth::checkRecordAccess($record, true); $record->createFact('1 OBJE @' . $xref . '@', true); return redirect($media->url()); } }