You are here

protected function AjaxController::county in Webform CiviCRM Integration 8.5

1 call to AjaxController::county()
AjaxController::handle in src/Controller/AjaxController.php
Handles the ajax request.

File

src/Controller/AjaxController.php, line 70

Class

AjaxController

Namespace

Drupal\webform_civicrm\Controller

Code

protected function county($input) {
  $data = [];
  $utils = \Drupal::service('webform_civicrm.utils');
  if (strpos($input, '-') !== FALSE) {
    list($state, $country) = explode('-', $input);
    $params = [
      'field' => 'county_id',
      'state_province_id' => $utils
        ->wf_crm_state_abbr($state, 'id', $country),
    ];
    $data = $utils
      ->wf_crm_apivalues('address', 'getoptions', $params);
  }

  // @todo use Drupal's cacheable response?
  return new JsonResponse($data);
}