xref: /webtrees/resources/views/individual-page-name.phtml (revision b9a4a6c608ac9f9f3bf6c12fbe1fbe871f30fedb)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Fact;
6use Fisharebest\Webtrees\Registry;
7use Fisharebest\Webtrees\Http\RequestHandlers\CopyFact;
8use Fisharebest\Webtrees\Http\RequestHandlers\DeleteFact;
9use Fisharebest\Webtrees\Http\RequestHandlers\EditFactPage;
10use Fisharebest\Webtrees\I18N;
11
12/**
13 * @var Fact $fact
14 */
15
16$individual = $fact->record();
17$tree       = $individual->tree();
18
19// Create a fake record, so we can extract the formatted NAME value from it.
20$fake_individual = Registry::individualFactory()->new(
21    'xref',
22    "0 @xref@ INDI\n1 DEAT Y\n" . $fact->gedcom(),
23    null,
24    $tree
25);
26$fake_individual->setPrimaryName(0); // Make sure we use the name from "1 NAME"
27
28$container_class = '';
29
30if ($fact->isPendingDeletion()) {
31    $container_class = 'wt-old';
32} elseif ($fact->isPendingAddition()) {
33    $container_class = 'wt-new';
34}
35
36?>
37<div class="accordion-item <?= $container_class ?>">
38    <div class="accordion-header" id="name-header-<?= $fact->id() ?>">
39        <button class="accordion-button collapsed gap-1" type="button" data-bs-toggle="collapse" data-bs-target="#name-content-<?= $fact->id() ?>" aria-expanded="false" aria-controls="name-content-<?= $fact->id() ?>">
40            <?= view('icons/expand') ?>
41            <?= view('icons/collapse') ?>
42            <span class="label"><?= I18N::translate('Name') ?></span>
43            <div>
44                <?= $fake_individual->fullName() ?>
45                <?php if ($fact->attribute('TYPE') !== '') : ?>
4647                    <?= Registry::elementFactory()->make($fact->tag() . ':TYPE')->value($fact->attribute('TYPE'), $tree) ?>
48                <?php endif ?>
49            </div>
50        </button>
51    </div>
52
53    <div id="name-content-<?= $fact->id() ?>" class="accordion-collapse collapse" data-bs-parent="#individual-names" aria-labelledby="name-header-<?= $fact->id() ?>">
54        <div class="accordion-body">
55            <dl class="row mb-0">
56                <dt class="col-md-4 col-lg-3"><?= I18N::translate('Name') ?></dt>
57                <dd class="col-md-8 col-lg-9"><bdi><?= e($fact->value()) ?></bdi></dd>
58
59                <?php preg_match_all('/\n2 (\w+) (.+)/', $fact->gedcom(), $matches, PREG_SET_ORDER) ?>
60                <?php foreach ($matches as $match) : ?>
61                    <?php [, $tag, $value] = $match ?>
62                    <?php $element = Registry::elementFactory()->make($fact->tag() . ':' . $tag) ?>
63                    <?php if ($tag !== 'SOUR' && $tag !== 'NOTE') : ?>
64                        <dt class="col-md-4 col-lg-3">
65                            <?= $element->label() ?>
66                        </dt>
67                        <dd class="col-md-8 col-lg-9">
68                            <?= $element->value($value, $fact->record()->tree()) ?>
69                        </dd>
70                    <?php endif ?>
71                <?php endforeach ?>
72            </dl>
73
74            <?= view('fact-sources', ['fact' => $fact]) ?>
75            <?= view('fact-notes', ['fact' => $fact]) ?>
76
77            <?php if ($fact->canEdit()) : ?>
78                <div class="d-flex">
79                    <a class="btn btn-link ms-auto" href="<?= e(route(EditFactPage::class, ['xref' => $individual->xref(), 'fact_id' => $fact->id(), 'tree' => $individual->tree()->name()])) ?>" title="<?= I18N::translate('Edit the name') ?>">
80                        <?= view('icons/edit') ?>
81                        <span class="visually-hidden"><?= I18N::translate('Edit the name') ?></span>
82                    </a>
83
84                <a class="btn btn-link" href="#" data-wt-post-url="<?= e(route(CopyFact::class, ['tree' => $fact->record()->tree()->name(), 'xref' => $fact->record()->xref(), 'fact_id' => $fact->id()])) ?>" title="<?= I18N::translate('Copy') ?>">
85                        <?= view('icons/copy') ?>
86                        <span class="visually-hidden"><?= I18N::translate('Copy') ?></span>
87                    </a>
88
89                    <a class="btn btn-link" href="#"
90                   data-wt-confirm="<?= I18N::translate('Are you sure you want to delete this fact?') ?>"
91                   data-wt-post-url="<?= e(route(DeleteFact::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'fact_id' => $fact->id()])) ?>"
92                       title="<?= I18N::translate('Delete this name') ?>">
93                        <?= view('icons/delete') ?>
94                        <span class="visually-hidden"><?= I18N::translate('Delete this name') ?></span>
95                    </a>
96                </div>
97            <?php endif ?>
98        </div>
99    </div>
100</div>
101