You are here

protected function Fields::getSets in Webform CiviCRM Integration 8.5

1 call to Fields::getSets()
Fields::wf_crm_get_fields in src/Fields.php

File

src/Fields.php, line 50

Class

Fields

Namespace

Drupal\webform_civicrm

Code

protected function getSets(array $components) : array {
  if (empty($this->sets)) {
    $sets = [
      'contact' => [
        'entity_type' => 'contact',
        'label' => t('Contact Fields'),
      ],
      'other' => [
        'entity_type' => 'contact',
        'label' => t('Tags and Groups'),
        'max_instances' => 1,
      ],
      'address' => [
        'entity_type' => 'contact',
        'label' => t('Address'),
        'max_instances' => 9,
        'custom_fields' => 'combined',
      ],
      'phone' => [
        'entity_type' => 'contact',
        'label' => t('Phone'),
        'max_instances' => 9,
        'custom_fields' => 'combined',
      ],
      'email' => [
        'entity_type' => 'contact',
        'label' => t('Email'),
        'max_instances' => 9,
        'custom_fields' => 'combined',
      ],
      'website' => [
        'entity_type' => 'contact',
        'label' => t('Website'),
        'max_instances' => 9,
        'custom_fields' => 'combined',
      ],
      'im' => [
        'entity_type' => 'contact',
        'label' => t('Instant Message'),
        'max_instances' => 9,
        'custom_fields' => 'combined',
      ],
      'activity' => [
        'entity_type' => 'activity',
        'label' => t('Activity'),
        'max_instances' => 99,
        'attachments' => TRUE,
      ],
      'relationship' => [
        'entity_type' => 'contact',
        'label' => t('Relationship'),
        'help_text' => TRUE,
        'custom_fields' => 'combined',
      ],
    ];
    $conditional_sets = [
      'CiviCase' => [
        'entity_type' => 'case',
        'label' => t('Case'),
        'max_instances' => 30,
      ],
      'CiviEvent' => [
        'entity_type' => 'participant',
        'label' => t('Participant'),
        'max_instances' => 9,
      ],
      'CiviContribute' => [
        'entity_type' => 'contribution',
        'label' => t('Contribution'),
      ],
      'CiviMember' => [
        'entity_type' => 'membership',
        'label' => t('Membership'),
        'custom_fields' => 'combined',
      ],
      'CiviGrant' => [
        'entity_type' => 'grant',
        'label' => t('Grant'),
        'max_instances' => 30,
        'attachments' => TRUE,
      ],
    ];
    foreach ($conditional_sets as $component => $set) {
      if (in_array($component, $components, TRUE)) {
        $sets[$set['entity_type']] = $set;
      }
    }

    // Contribution line items
    if (in_array('CiviContribute', $components, TRUE)) {
      $sets['line_items'] = [
        'entity_type' => 'line_item',
        'label' => t('Line Items'),
      ];
    }
    $extra_sets = \Drupal::service('webform_civicrm.utils')
      ->wf_crm_get_empty_sets();
    $sets += $extra_sets;
    $this->sets = $sets;
  }
  return $this->sets;
}