. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Validator; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; /** * Link a media object to a record. */ class LinkMediaToRecordAction implements RequestHandlerInterface { /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = Validator::attributes($request)->tree(); $xref = Validator::attributes($request)->isXref()->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()); } }