1<?php 2 3use Fisharebest\Webtrees\Elements\AbstractXrefElement; 4use Fisharebest\Webtrees\Elements\EmptyElement; 5use Fisharebest\Webtrees\Registry; 6use Fisharebest\Webtrees\Tree; 7use Ramsey\Uuid\Uuid; 8 9/** 10 * @var string $gedcom 11 * @var array<string> $hierarchy 12 * @var string $prefix 13 * @var Tree $tree 14 */ 15 16preg_match_all('/^(\d+) (\w+) ?(.*)/m', $gedcom, $matches); 17[, $levels, $tags, $values] = $matches; 18$levels = array_map(static fn(string $x): int => (int) $x, $levels); 19$keys = array_keys($levels); 20$elements = []; 21$ids = []; 22 23foreach ($keys as $key) { 24 $hierarchy[$levels[$key]] = $tags[$key]; 25 $full_tag = implode(':', array_slice($hierarchy, 0, 1 + $levels[$key])); 26 $elements[$key] = Registry::elementFactory()->make($full_tag); 27 $ids[$key] = Uuid::uuid4()->toString() . '-' . $full_tag; 28} 29 30?> 31<?php foreach ($keys as $key) : ?> 32 <?php if ($key > 0 && $levels[$key] > $levels[$key - 1] && $elements[$key] instanceof AbstractXrefElement) : ?> 33 <div class="row"> 34 <div class="col-sm-1"></div> 35 <div class="col-sm-11">XXX</div> 36 </div> 37 <?php endif ?> 38 39 <?php if ($elements[$key] instanceof EmptyElement && $values[$key] === '') : ?> 40 <input type="hidden" name="<?= e($prefix) ?>levels[]" value="<?= $levels[$key] ?>"> 41 <input type="hidden" name="<?= e($prefix) ?>tags[]" value="<?= e($tags[$key]) ?>"> 42 <input type="hidden" name="<?= e($prefix) ?>values[]" value=""> 43 <?php else : ?> 44 <div class="row form-group mb-3"> 45 <label class="col-sm-3 col-form-label" for="<?= e($ids[$key]) ?>"> 46 <?= $elements[$key]->label() ?> 47 </label> 48 49 <div class="col-sm-9"> 50 <input type="hidden" name="<?= e($prefix) ?>levels[]" value="<?= $levels[$key] ?>"> 51 <input type="hidden" name="<?= e($prefix) ?>tags[]" value="<?= e($tags[$key]) ?>"> 52 <?= $elements[$key]->edit($ids[$key], $prefix . 'values[]', strtr($values[$key], ["\r" => "\n"]), $tree) ?> 53 </div> 54 </div> 55 <?php endif ?> 56<?php endforeach ?> 57