You are here

function Utils::wf_crm_get_contact_types in Webform CiviCRM Integration 8.5

Get contact types and sub-types Unlike pretty much every other option list CiviCRM wants "name" instead of "id"

Return value

array

Overrides UtilsInterface::wf_crm_get_contact_types

File

src/Utils.php, line 317
Webform CiviCRM module's common utility functions.

Class

Utils

Namespace

Drupal\webform_civicrm

Code

function wf_crm_get_contact_types() {
  static $contact_types = [];
  static $sub_types = [];
  if (!$contact_types) {
    $data = $this
      ->wf_crm_apivalues('contact_type', 'get', [
      'is_active' => 1,
    ]);
    foreach ($data as $type) {
      if (empty($type['parent_id'])) {
        $contact_types[strtolower($type['name'])] = $type['label'];
        continue;
      }
      $sub_types[strtolower($data[$type['parent_id']]['name'])][strtolower($type['name'])] = $type['label'];
    }
  }
  return [
    $contact_types,
    $sub_types,
  ];
}