xref(); $cancel_url = $individual->url(); } elseif ($family !== null) { $xref = $family->xref(); $cancel_url = $family->url(); } else { $cancel_url = route('manage-trees', ['tree' => $tree->name()]); $xref = 'new'; } // Different cultures do surnames differently $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION')); if ($name_fact instanceof Fact) { // 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'), ]; } 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->husband(); if ($father instanceof Individual && $father->facts(['NAME'])->isNotEmpty()) { $father_name = $father->facts(['NAME'])->first()->value(); } else { $father_name = ''; } $mother = $family->wife(); if ($mother instanceof Individual && $mother->facts(['NAME'])->isNotEmpty()) { $mother_name = $mother->facts(['NAME'])->first()->value(); } else { $mother_name = ''; } } else { $father = null; $mother = null; $father_name = ''; $mother_name = ''; } if ($individual && $individual->facts(['NAME'])->isNotEmpty()) { $indi_name = $individual->facts(['NAME'])->first()->value(); } else { $indi_name = ''; } switch ($next_action) { case AddChildToFamilyAction::class: $name_fields = array_merge($name_fields, $surname_tradition->newChildNames($father_name, $mother_name, $gender)); break; case AddChildToIndividualAction::class: if ($individual->sex() === '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 AddParentToIndividualAction::class: $name_fields = array_merge($name_fields, $surname_tradition->newParentNames($indi_name, $gender)); break; case AddSpouseToFamilyAction::class: 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 AddSpouseToIndividualAction::class: $name_fields = array_merge($name_fields, $surname_tradition->newSpouseNames($indi_name, $gender)); break; case AddUnlinkedAction::class: case EditFactAction::class: if ($surname_tradition->hasSurnames()) { $name_fields['NAME'] = '//'; } break; } } $bdm = ''; // used to copy '1 SOUR' to '2 SOUR' for BIRT DEAT MARR ?>