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