You are here

function wf_crm_aval in Webform CiviCRM Integration 8.5

Same name and namespace in other branches
  1. 7.5 webform_civicrm.module \wf_crm_aval()
  2. 7.3 webform_civicrm.module \wf_crm_aval()
  3. 7.4 webform_civicrm.module \wf_crm_aval()

Return a value from nested arrays or objects.

Parameters

array|object $haystack: The array to search

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

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

bool $strict: Should we use empty or isset to determine if array key exists? If TRUE, use isset

Return value

mixed found value or default

83 calls to wf_crm_aval()
AdminForm::addConditionalRule in src/AdminForm.php
Create a conditional rule if the source and target fields both exist. TODO: This is fairly minimal. It doesn't check if the rule already exists, and doesn't work if both fields haven't been created yet.
AdminForm::addDynamicCustomSetting in src/AdminForm.php
AdminForm::addItem in src/AdminForm.php
Build a field item for the admin form
AdminForm::buildActivityTab in src/AdminForm.php
Activity settings
AdminForm::buildCaseTab in src/AdminForm.php
Case settings FIXME: This is exactly the same code as buildGrantTab. More utilities and less boilerplate needed.

... See full list

File

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

Code

function wf_crm_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;
}