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