xref: /webtrees/resources/views/edit/edit-gedcom-fields.phtml (revision 0d047a8c74753c7558a60f4789c838996d6fae8b)
1<?php
2
3use Fisharebest\Webtrees\Registry;
4use Fisharebest\Webtrees\Tree;
5use Ramsey\Uuid\Uuid;
6
7/**
8 * @var string        $gedcom
9 * @var array<string> $hierarchy
10 * @var string        $prefix
11 * @var Tree          $tree
12 */
13
14$gedcom = preg_replace('/\n\d CONT ?/', "\r", $gedcom);
15?>
16
17<?php foreach (explode("\n", $gedcom) as $line) : ?>
18    <?php
19    preg_match('/^(\d+) (\w+) ?(.*)/', $line, $match);
20    [, $level, $tag, $value] = $match;
21    $hierarchy[$level] = $tag;
22    $full_tag          = implode(':', array_slice($hierarchy, 0, 1 + (int) $level));
23    $element           = Registry::elementFactory()->make($full_tag);
24    $id                = Uuid::uuid4()->toString() . '-' . $full_tag;
25    ?>
26
27    <div class="form-group row">
28        <label class="col-sm-3 col-form-label" for="<?= e($id) ?>">
29            <?= $element->label() ?>
30        </label>
31
32        <div class="col-sm-9">
33            <input type="hidden" name="<?= e($prefix) ?>levels[]" value="<?= e($level) ?>">
34            <input type="hidden" name="<?= e($prefix) ?>tags[]" value="<?= e($tag) ?>">
35            <?= $element->edit($id, $prefix . 'values[]', strtr($value, ["\r" => "\n"]), $tree) ?>
36        </div>
37    </div>
38<?php endforeach ?>
39