Skip to content

Commit fc89ca3

Browse files
committed
feat: add fullName class method to UserModel
1 parent 21d2448 commit fc89ca3

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/PrefillGravityForms/Models/UserModel.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public function age(): int
6262
return (int) ($this->data['leeftijd'] ?? 0);
6363
}
6464

65+
public function initials(): string
66+
{
67+
return (string) ($this->data['naam']['voorletters'] ?? '');
68+
}
69+
6570
public function firstNames(): string
6671
{
6772
return (string) ($this->data['naam']['voornamen'] ?? '');
@@ -76,4 +81,15 @@ public function lastNamePrefix(): string
7681
{
7782
return (string) ($this->data['naam']['voorvoegsel'] ?? '');
7883
}
84+
85+
public function fullName(bool $withInitials = false): string
86+
{
87+
$nameParts = [
88+
$withInitials ? $this->initials() : $this->firstNames(),
89+
$this->lastNamePrefix(),
90+
$this->lastName(),
91+
];
92+
93+
return implode(' ', array_filter($nameParts));
94+
}
7995
}

0 commit comments

Comments
 (0)