Skip to content

Commit

Permalink
Fix state display on preview
Browse files Browse the repository at this point in the history
  • Loading branch information
jitendrapurohit committed Feb 10, 2024
1 parent d07b2b7 commit 95b7581
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Plugin/WebformElement/CivicrmOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,33 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
}
}

/**
* @inheritDoc
*/
protected function format($type, array &$element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = parent::format($type, $element, $webform_submission, $options);
$format = $this->getItemFormat($element);
if (!str_ends_with($element['#form_key'], '_address_state_province_id')) {
return $value;
}
if ($type === 'Text') {
$state_id = $value;
}
else {
$state_id = $value['#plain_text'] ?? NULL;
}
if ($format === 'raw' || empty($state_id) || !is_numeric($state_id)) {
return $value;
}
$utils = \Drupal::service('webform_civicrm.utils');
$state = $utils->wf_crm_apivalues('state_province', 'get', ['id' => $state_id], 'name');
if (!empty($state[$state_id])) {
if ($type === 'Text') {
return $state[$state_id];
}
$value['#plain_text'] = $state[$state_id];
}
return $value;
}

}

0 comments on commit 95b7581

Please sign in to comment.