. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Elements; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Tree; use function e; use function in_array; use function view; /** * NAME_PERSONAL := {Size=1:120} * [ * | // | * // | // | * // ] * The surname of an individual, if known, is enclosed between two slash (/) * characters. The order of the name parts should be the order that the person * would, by custom of their culture, have used when giving it to a recorder. * Early versions of Personal Ancestral File ® and other products did not use * the trailing slash when the surname was the last element of the name. If * part of name is illegible, that part is indicated by an ellipsis (...). * Capitalize the name of a person or place in the conventional manner— * capitalize the first letter of each part and lowercase the other letters, * unless conventional usage is otherwise. For example: McMurray. * Examples: * William Lee (given name only or surname not known) * /Parry/ (surname only) * William Lee /Parry/ * William Lee /Mac Parry/ (both parts (Mac and Parry) are surname parts * William /Lee/ Parry (surname imbedded in the name string) * William Lee /Pa.../ */ class NamePersonal extends AbstractElement { protected const MAXIMUM_LENGTH = 120; protected const SUBTAGS = [ 'TYPE' => '0:1', 'NPFX' => '0:1', 'GIVN' => '0:1', 'SPFX' => '0:1', 'SURN' => '0:1', 'NSFX' => '0:1', 'NICK' => '0:1', 'NOTE' => '0:M', 'SOUR' => '0:M', 'FONE' => '0:M', 'ROMN' => '0:M', ]; // For some languages, we want to show the surname field first. protected const SURNAME_FIRST_LANGUAGES = ['hu', 'jp', 'ko', 'zh-Hans', 'zh-Hant']; protected const SUBTAGS_SURNAME_FIRST = [ 'TYPE' => '0:1', 'NPFX' => '0:1', 'SPFX' => '0:1', 'SURN' => '0:1', 'GIVN' => '0:1', 'NSFX' => '0:1', 'NICK' => '0:1', 'NOTE' => '0:M', 'SOUR' => '0:M', 'FONE' => '0:M', 'ROMN' => '0:M', ]; /** * Create a default value for this element. * * @param Tree $tree * * @return string */ public function default(Tree $tree): string { return Registry::surnameTraditionFactory() ->make($tree->getPreference('SURNAME_TRADITION')) ->defaultName(); } /** * An edit control for this data. * * @param string $id * @param string $name * @param string $value * @param Tree $tree * * @return string */ public function edit(string $id, string $name, string $value, Tree $tree): string { return '
' . view('edit/input-addon-edit-name', ['id' => $id]) . '' . view('edit/input-addon-keyboard', ['id' => $id]) . view('edit/input-addon-help', ['topic' => 'NAME']) . '
'; } /** * @return array */ public function subtags(): array { if (in_array(I18N::languageTag(), static::SURNAME_FIRST_LANGUAGES, true)) { return static::SUBTAGS_SURNAME_FIRST; } return static::SUBTAGS; } }