Skip to content

Commit b0376fc

Browse files
committed
NameProcessor: add getMarriedSurnames() for birth+married rendering
When a chart consumer wants to display birth name with married surname appended (e.g., "Schmidt (Müller)"), the existing useMarriedName constructor flag does not help — it switches the primary name out entirely. Add a small additive method that returns just the married-surname parts from a matching _MARNM record. When a spouse is given, only _MARNM records whose surn matches the spouse's surn are returned. Empty array when no _MARNM matches. Composition (parens, separator, etc.) is left to the consumer so chart modules can pick their own visual format.
1 parent ef795db commit b0376fc

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

src/Processor/NameProcessor.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,50 @@ public function getLastNames(): array
251251
return $this->getNamesByIdentifier(self::XPATH_LAST_NAMES);
252252
}
253253

254+
/**
255+
* Returns the married surname parts (from a `_MARNM` GEDCOM record), or an empty
256+
* array when no married-name record matches. When $spouse is given, only `_MARNM`
257+
* records whose `surn` matches the spouse's `surn` are considered; otherwise any
258+
* `_MARNM` is returned.
259+
*
260+
* Use this in a chart consumer that already shows the birth name and wants to
261+
* append the married surname (e.g. "Schmidt (Müller)") — separate from the
262+
* `useMarriedName` constructor flag, which switches the primary name out
263+
* entirely.
264+
*
265+
* @param Individual|null $spouse Optional spouse to scope the surname match
266+
*
267+
* @return string[]
268+
*/
269+
public function getMarriedSurnames(?Individual $spouse = null): array
270+
{
271+
foreach ($this->individual->getAllNames() as $individualName) {
272+
if ($individualName['type'] !== '_MARNM') {
273+
continue;
274+
}
275+
276+
if ($spouse instanceof Individual) {
277+
$spouseHasMatch = false;
278+
279+
foreach ($spouse->getAllNames() as $spouseName) {
280+
if ($individualName['surn'] === $spouseName['surn']) {
281+
$spouseHasMatch = true;
282+
283+
break;
284+
}
285+
}
286+
287+
if (!$spouseHasMatch) {
288+
continue;
289+
}
290+
}
291+
292+
return $this->splitAndCleanName([$individualName['surn']]);
293+
}
294+
295+
return [];
296+
}
297+
254298
/**
255299
* Returns the preferred name of the individual.
256300
*

0 commit comments

Comments
 (0)