Skip to content

Commit

Permalink
Merge pull request #490 from City-of-Helsinki/develop
Browse files Browse the repository at this point in the history
Applicant fixes to production
  • Loading branch information
tvalimaa authored Nov 16, 2023
2 parents f47fb44 + 0c1db68 commit b21974a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function toArray(): array {
'application_type' => $this->application->bundle(),
'ssn_suffix' => $this->application->main_applicant[0]->personal_id,
'has_children' => $this->application->getHasChildren(),
'additional_applicant' => $this->getApplicant(),
'additional_applicant' => $this->getAdditionalApplicant(),
'right_of_residence' => NULL,
'project_id' => $this->projectUuid,
'apartments' => $this->getApartments(),
Expand Down Expand Up @@ -105,11 +105,11 @@ protected function getApartments(): array {
* @return object
* Applicant information.
*/
protected function getApplicant(): ?object {
protected function getAdditionalApplicant(): ?object {
if (!$this->application->hasAdditionalApplicant()) {
return NULL;
}
$applicant = $this->application->getApplicant()[0];
$applicant = $this->application->getAdditionalApplicants()[0];
return (object) [
'first_name' => $applicant['first_name'],
'last_name' => $applicant['last_name'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function toArray(): array {
'application_type' => $this->application->bundle(),
'ssn_suffix' => $this->application->main_applicant[0]->personal_id,
'has_children' => $this->application->getHasChildren(),
'additional_applicant' => $this->getApplicant(),
'additional_applicant' => $this->getAdditionalApplicant(),
'right_of_residence' => NULL,
'is_new_permit_number' => NULL,
'project_id' => $this->projectUuid,
Expand Down Expand Up @@ -115,11 +115,11 @@ private function getApartments() {
* @return array
* Applicant information.
*/
private function getApplicant() {
private function getAdditionalApplicant() {
if (!$this->application->hasAdditionalApplicant()) {
return NULL;
}
$applicant = $this->application->getApplicants()[0];
$applicant = $this->application->getAdditionalApplicants()[0];
return [
'first_name' => $applicant['first_name'],
'last_name' => $applicant['last_name'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function getMainApplicant(): ?array {
* @return array
* Array of applicants.
*/
public function getApplicant(): array {
public function getAdditionalApplicants(): array {
return $this->applicant->getValue() ?? [];
}

Expand Down
20 changes: 20 additions & 0 deletions public/modules/custom/asu_application/src/Form/ApplicationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
}
}

$has_additional_applicant = (!empty($formValues['applicant'][0]['has_additional_applicant'])) ? (bool) $formValues['applicant'][0]['has_additional_applicant'] : FALSE;

if ($has_additional_applicant) {
foreach ($formValues['applicant'][0] as $applicant_field => $applicant_value) {
if ($applicant_field == 'has_additional_applicant') {
continue;
}

if ($applicant_field == 'personal_id' && strlen($applicant_value) != 4) {
$fieldTitle = (string) $form["applicant"]['widget'][0][$applicant_field]['#title'];
$form_state->setErrorByName($field, t('Check @field', ['@field' => $fieldTitle]));
}

if (empty($applicant_value) || $applicant_value == '-' || strlen($applicant_value) < 2) {
$fieldTitle = (string) $form["applicant"]['widget'][0][$applicant_field]['#title'];
$form_state->setErrorByName($applicant_field, t('Field @field cannot be empty', ['@field' => $fieldTitle]));
}
}
}

$triggerName = $form_state->getTriggeringElement()['#name'];
if ($triggerName == 'submit-application') {
parent::validateForm($form, $form_state);
Expand Down

0 comments on commit b21974a

Please sign in to comment.