You are here

function webform_civicrm_civicrm_postSave_civicrm_custom_group in Webform CiviCRM Integration 7.5

Same name and namespace in other branches
  1. 8.5 webform_civicrm.module \webform_civicrm_civicrm_postSave_civicrm_custom_group()
  2. 7.4 webform_civicrm.module \webform_civicrm_civicrm_postSave_civicrm_custom_group()

Implements hook_civicrm_postSave_tableName().

Handles adding/editing a custom group.

Parameters

CRM_Core_DAO_CustomGroup $dao:

File

./webform_civicrm.module, line 456
Webform CiviCRM Integration Module: Links webform submissions to contacts in a CiviCRM database. @author Coleman Watts

Code

function webform_civicrm_civicrm_postSave_civicrm_custom_group($dao) {
  module_load_include('inc', 'webform', 'includes/webform.components');

  // get all fieldsets with custom group ID
  $customGroupId = $dao->id;
  $dbResource = db_query("SELECT * FROM {webform_component} WHERE type ='fieldset' " . "AND form_key LIKE '%cg{$customGroupId}_fieldset'");
  $fieldsets = $dbResource
    ->fetchAll(PDO::FETCH_ASSOC);

  // check if dao fields have been fetched
  if (!$dao->title) {
    $dao
      ->find(TRUE);
  }

  // run only if the title of the custom group has changed in civicrm
  if (!empty($fieldsets[0]) && $fieldsets[0]['name'] != $dao->title) {
    foreach ($fieldsets as $field_info) {
      $component = [];
      $component['name'] = $dao->title;
      $component['type'] = $field_info['type'];
      $component['form_key'] = $field_info['form_key'];
      $component['weight'] = $field_info['weight'];
      $component['nid'] = $field_info['nid'];
      $component['cid'] = $field_info['cid'];
      $component['pid'] = $field_info['pid'];
      webform_component_update($component);
    }
  }
}