You are here

private function wf_crm_admin_form::addAjaxItem in Webform CiviCRM Integration 7.4

Same name and namespace in other branches
  1. 7.5 includes/wf_crm_admin_form.inc \wf_crm_admin_form::addAjaxItem()

Boilerplate-reducing helper function for FAPI ajax. Set an existing form element to control an ajax container. The container will be created if it doesn't already exist.

Parameters

string $path: A : separated string of nested array keys leading to the control element's parent

string $control_element: Array key of the existing element to add ajax behavior to

string $container: Path to the key of the container to be created (relative to $path) use '..' to go up a level

string $class: Css class to add to target container

7 calls to wf_crm_admin_form::addAjaxItem()
wf_crm_admin_form::buildActivityTab in includes/wf_crm_admin_form.inc
Activity settings
wf_crm_admin_form::buildCaseTab in includes/wf_crm_admin_form.inc
Case settings FIXME: This is exactly the same code as buildGrantTab. More utilities and less boilerplate needed.
wf_crm_admin_form::buildContactTab in includes/wf_crm_admin_form.inc
Build fields for a contact
wf_crm_admin_form::buildContributionTab in includes/wf_crm_admin_form.inc
Contribution settings
wf_crm_admin_form::buildGrantTab in includes/wf_crm_admin_form.inc
Grant settings FIXME: This is nearly the same code as buildCaseTab. More utilities and less boilerplate needed.

... See full list

File

includes/wf_crm_admin_form.inc, line 1399
Webform CiviCRM module's admin form.

Class

wf_crm_admin_form
@file Webform CiviCRM module's admin form.

Code

private function addAjaxItem($path, $control_element, $container, $class = 'civicrm-ajax-wrapper') {

  // Get a reference to the control container
  // For anyone who wants to call this evil - I challenge you to find a better way to accomplish this
  eval('$control_container = &$this->form[\'' . str_replace(':', "']['", $path) . "'];");

  // Now find the container element (may be outside the $path if .. is used)
  foreach (explode(':', $container) as $level) {
    if ($level == '..') {
      $path = substr($path, 0, strrpos($path, ':'));
    }
    else {
      $path .= ':' . $level;
    }
  }
  eval('$target_container = &$this->form[\'' . str_replace(':', "']['", substr($path, 0, strrpos($path, ':'))) . "'];");
  $id = 'civicrm-ajax-' . str_replace(array(
    ':',
    '_',
  ), '-', $path);
  $control_container[$control_element]['#ajax'] = array(
    'callback' => 'wf_crm_configure_form_ajax',
    'pathstr' => $path,
    'wrapper' => $id,
    'effect' => 'fade',
  );
  if (!isset($target_container[$level])) {
    $target_container[$level] = array();
  }
  $target_container[$level]['#prefix'] = '<div class="' . $class . '" id="' . $id . '">';
  $target_container[$level]['#suffix'] = '</div>';
}