xref(); $cancel_url = $individual->url(); } elseif ($family !== null) { $xref = $family->xref(); $cancel_url = $family->url(); } else { $cancel_url = route('admin-trees'); $xref = 'new'; } // Different cultures do surnames differently $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION')); if ($name_fact !== null) { // Editing an existing name $name_fact_id = $name_fact->id(); $namerec = $name_fact->gedcom(); $name_fields = [ 'NAME' => $name_fact->value(), 'TYPE' => $name_fact->attribute('TYPE'), 'NPFX' => $name_fact->attribute('NPFX'), 'GIVN' => $name_fact->attribute('GIVN'), 'NICK' => $name_fact->attribute('NICK'), 'SPFX' => $name_fact->attribute('SPFX'), 'SURN' => $name_fact->attribute('SURN'), 'NSFX' => $name_fact->attribute('NSFX'), ]; // Populate any missing subfields from the NAME field $npfx_accept = implode('|', Config::namePrefixes()); if (preg_match('/(((' . $npfx_accept . ')\.? +)*)([^\n\/"]*)("(.*)")? *\/(([a-z]{2,3} +)*)(.*)\/ *(.*)/i', $name_fields['NAME'], $name_bits)) { $name_fields['NPFX'] = $name_fields['NPFX'] ?: $name_bits[1]; $name_fields['GIVN'] = $name_fields['GIVN'] ?: $name_bits[4]; $name_fields['NICK'] = $name_fields['NICK'] ?: $name_bits[6]; $name_fields['SPFX'] = $name_fields['SPFX'] ?: trim($name_bits[7]); $name_fields['SURN'] = $name_fields['SURN'] ?: preg_replace('~/[^/]*/~', ',', $name_bits[9]); $name_fields['NSFX'] = $name_fields['NSFX'] ?: $name_bits[10]; } } else { // Creating a new name $name_fact_id = ''; $namerec = ''; $name_fields = [ 'NAME' => '', 'TYPE' => '', 'NPFX' => '', 'GIVN' => '', 'NICK' => '', 'SPFX' => '', 'SURN' => '', 'NSFX' => '', ]; // Inherit surname from parents, spouse or child if ($family) { $father = $family->getHusband(); if ($father && $father->getFirstFact('NAME')) { $father_name = $father->getFirstFact('NAME')->value(); } else { $father_name = ''; } $mother = $family->getWife(); if ($mother && $mother->getFirstFact('NAME')) { $mother_name = $mother->getFirstFact('NAME')->value(); } else { $mother_name = ''; } } else { $father = null; $mother = null; $father_name = ''; $mother_name = ''; } if ($individual && $individual->getFirstFact('NAME')) { $indi_name = $individual->getFirstFact('NAME')->value(); } else { $indi_name = ''; } switch ($nextaction) { case 'add_child_to_family_action': $name_fields = array_merge($name_fields, $surname_tradition->newChildNames($father_name, $mother_name, $gender)); break; case 'add_child_to_individual_action': if ($individual->getSex() === 'F') { $name_fields = array_merge($name_fields, $surname_tradition->newChildNames('', $indi_name, $gender)); } else { $name_fields = array_merge($name_fields, $surname_tradition->newChildNames($indi_name, '', $gender)); } break; case 'add_parent_to_individual_action': $name_fields = array_merge($name_fields, $surname_tradition->newParentNames($indi_name, $gender)); break; case 'add_spouse_to_family_action': if ($father) { $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($father_name, $gender)); } else { $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($mother_name, $gender)); } break; case 'add_spouse_to_individual_action': $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($indi_name, $gender)); break; case 'add_unlinked_indi_action': case 'update': if ($surname_tradition->hasSurnames()) { $name_fields['NAME'] = '//'; } break; } } $bdm = ''; // used to copy '1 SOUR' to '2 SOUR' for BIRT DEAT MARR ?>