class AjaxController in Webform CiviCRM Integration 8.5
Hierarchy
- class \Drupal\webform_civicrm\Controller\AjaxController implements ContainerInjectionInterface
Expanded class hierarchy of AjaxController
File
- src/
Controller/ AjaxController.php, line 11
Namespace
Drupal\webform_civicrm\ControllerView source
class AjaxController implements ContainerInjectionInterface {
protected $requestStack;
/**
* The CiviCRM service.
*
* @var \Drupal\civicrm\Civicrm
*/
protected $civicrm;
public function __construct(Civicrm $civicrm, RequestStack $requestStack) {
$this->civicrm = $civicrm;
$this->requestStack = $requestStack;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('civicrm'), $container
->get('request_stack'));
}
/**
* Handles the ajax request.
*
* @param string $operation
* The operation to perform: stateProvince or county
*/
public function handle($key, $input = '', $isBilling = FALSE) {
$this->civicrm
->initialize();
if ($key === 'stateProvince') {
$isBilling = $isBilling === 'false' ? FALSE : $isBilling;
return $this
->stateProvince($input, $isBilling);
}
elseif ($key === 'county') {
return $this
->county($input);
}
else {
$processor = \Drupal::service('webform_civicrm.webform_ajax');
return new JsonResponse($processor
->contactAjax($key, $input));
}
}
protected function stateProvince($input, $isBilling = FALSE) {
if (!$input || (int) $input != $input && $input != 'default') {
$data = [
'' => t('- first choose a country'),
];
}
else {
$data = \Drupal::service('webform_civicrm.utils')
->wf_crm_get_states($input, $isBilling);
}
// @todo use Drupal's cacheable response?
return new JsonResponse($data);
}
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxController:: |
protected | property | The CiviCRM service. | |
AjaxController:: |
protected | property | ||
AjaxController:: |
protected | function | ||
AjaxController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
AjaxController:: |
public | function | Handles the ajax request. | |
AjaxController:: |
protected | function | ||
AjaxController:: |
public | function |