You are here

function webform_civicrm_civicrm_buildForm in Webform CiviCRM Integration 7.4

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

Implements hook_civicrm_buildForm().

Parameters

string $formName:

CRM_Core_Form $form:

File

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

Code

function webform_civicrm_civicrm_buildForm($formName, $form) {

  // Warn user when deleting custom fields used by webforms
  if ($formName == 'CRM_Custom_Form_DeleteField') {
    $nodes = array();
    $fid = $form
      ->getVar('_id');
    if ($fid) {
      $webforms = db_query("SELECT nid FROM {webform_component} WHERE form_key LIKE 'civicrm_%_custom_{$fid}' GROUP BY nid");
      foreach ($webforms as $webform) {
        $node = node_load($webform->nid);
        $nodes[] = l($node->title, 'node/' . $webform->nid);
      }
    }
    if ($nodes) {
      $list = '<ul><li>' . implode('</li><li>', $nodes) . '</li></ul>';
      CRM_Core_Region::instance('page-body')
        ->add(array(
        'markup' => '<strong>' . t('This field is used in the following webforms:') . '</strong>' . $list,
      ));
    }
  }
}