You are here

function webform_civicrm_aval in Webform CiviCRM Integration 7.2

Same name and namespace in other branches
  1. 6.2 webform_civicrm.module \webform_civicrm_aval()

Return a value from nested arrays or objects.

@return: found value or default

Parameters

$haystack: the array to search:

$keys: pass a single key, or multiple keys separated by : to get a nested value:

$default: value to return if given array key does not exist:

$strict: should we use empty or isset to determine if array key exists?:

20 calls to webform_civicrm_aval()
webform_civicrm_add_remove in ./webform_civicrm_forms.inc
Handle adding/removing multivalued data for a contact/activity/etc. Currently used only for groups and tags, but written with expansion in mind.
webform_civicrm_configure_form_ajax in ./webform_civicrm.module
FAPI AJAX callback for the configure form.
webform_civicrm_configure_form_builder in ./webform_civicrm_admin.inc
Form to configure CiviCRM options for a Webform Called indirectly from hook_menu() for D7-D6 compatibility
webform_civicrm_configure_form_item in ./webform_civicrm_admin.inc
Build a field item for the configure form
webform_civicrm_configure_form_submit in ./webform_civicrm_admin.inc
Submission handler, saves CiviCRM options for a Webform node

... See full list

File

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

Code

function webform_civicrm_aval($haystack, $keys, $default = NULL, $strict = FALSE) {
  foreach (explode(':', $keys) as $key) {
    if (is_object($haystack)) {
      $haystack = (array) $haystack;
    }
    if (!is_array($haystack) || !isset($haystack[$key]) || empty($haystack[$key]) && $default !== NULL && !$strict) {
      return $default;
    }
    $haystack = $haystack[$key];
  }

  // $haystack has been reduced down to the item we want
  return $haystack;
}