xref: /webtrees/app/Elements/XrefSharedNote.php (revision 701f5d180b85b9d3e0747b6ddc9e9d64dd73d0d6)
1*701f5d18SGreg Roach<?php
2*701f5d18SGreg Roach
3*701f5d18SGreg Roach/**
4*701f5d18SGreg Roach * webtrees: online genealogy
5*701f5d18SGreg Roach * Copyright (C) 2022 webtrees development team
6*701f5d18SGreg Roach * This program is free software: you can redistribute it and/or modify
7*701f5d18SGreg Roach * it under the terms of the GNU General Public License as published by
8*701f5d18SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9*701f5d18SGreg Roach * (at your option) any later version.
10*701f5d18SGreg Roach * This program is distributed in the hope that it will be useful,
11*701f5d18SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*701f5d18SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*701f5d18SGreg Roach * GNU General Public License for more details.
14*701f5d18SGreg Roach * You should have received a copy of the GNU General Public License
15*701f5d18SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16*701f5d18SGreg Roach */
17*701f5d18SGreg Roach
18*701f5d18SGreg Roachdeclare(strict_types=1);
19*701f5d18SGreg Roach
20*701f5d18SGreg Roachnamespace Fisharebest\Webtrees\Elements;
21*701f5d18SGreg Roach
22*701f5d18SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\CreateNoteModal;
23*701f5d18SGreg Roachuse Fisharebest\Webtrees\I18N;
24*701f5d18SGreg Roachuse Fisharebest\Webtrees\Registry;
25*701f5d18SGreg Roachuse Fisharebest\Webtrees\Tree;
26*701f5d18SGreg Roach
27*701f5d18SGreg Roachuse function e;
28*701f5d18SGreg Roachuse function route;
29*701f5d18SGreg Roachuse function trim;
30*701f5d18SGreg Roachuse function view;
31*701f5d18SGreg Roach
32*701f5d18SGreg Roach/**
33*701f5d18SGreg Roach * XREF:SNOTE := {Size=1:22}
34*701f5d18SGreg Roach * A pointer to, or a cross-reference identifier of, a shared note record.
35*701f5d18SGreg Roach */
36*701f5d18SGreg Roachclass XrefSharedNote extends AbstractXrefElement
37*701f5d18SGreg Roach{
38*701f5d18SGreg Roach    /**
39*701f5d18SGreg Roach     * An edit control for this data.
40*701f5d18SGreg Roach     *
41*701f5d18SGreg Roach     * @param string $id
42*701f5d18SGreg Roach     * @param string $name
43*701f5d18SGreg Roach     * @param string $value
44*701f5d18SGreg Roach     * @param Tree   $tree
45*701f5d18SGreg Roach     *
46*701f5d18SGreg Roach     * @return string
47*701f5d18SGreg Roach     */
48*701f5d18SGreg Roach    public function edit(string $id, string $name, string $value, Tree $tree): string
49*701f5d18SGreg Roach    {
50*701f5d18SGreg Roach        $select = view('components/select-shared-note', [
51*701f5d18SGreg Roach            'id'          => $id,
52*701f5d18SGreg Roach            'name'        => $name,
53*701f5d18SGreg Roach            'shared_note' => Registry::sharedNoteFactory()->make(trim($value, '@'), $tree),
54*701f5d18SGreg Roach            'tree'        => $tree,
55*701f5d18SGreg Roach            'at'          => '@',
56*701f5d18SGreg Roach        ]);
57*701f5d18SGreg Roach
58*701f5d18SGreg Roach        return
59*701f5d18SGreg Roach            '<div class="input-group">' .
60*701f5d18SGreg Roach            '<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . e(route(CreateNoteModal::class, ['tree' => $tree->name()])) . '" data-wt-select-id="' . $id . '" title="' . I18N::translate('Create a shared note') . '">' .
61*701f5d18SGreg Roach            view('icons/add') .
62*701f5d18SGreg Roach            '</button>' .
63*701f5d18SGreg Roach            $select .
64*701f5d18SGreg Roach            '</div>';
65*701f5d18SGreg Roach    }
66*701f5d18SGreg Roach
67*701f5d18SGreg Roach    /**
68*701f5d18SGreg Roach     * Display the value of this type of element.
69*701f5d18SGreg Roach     *
70*701f5d18SGreg Roach     * @param string $value
71*701f5d18SGreg Roach     * @param Tree   $tree
72*701f5d18SGreg Roach     *
73*701f5d18SGreg Roach     * @return string
74*701f5d18SGreg Roach     */
75*701f5d18SGreg Roach    public function value(string $value, Tree $tree): string
76*701f5d18SGreg Roach    {
77*701f5d18SGreg Roach        return $this->valueXrefLink($value, $tree, Registry::sharedNoteFactory());
78*701f5d18SGreg Roach    }
79*701f5d18SGreg Roach}
80