You are here

private function WebformCivicrmPostProcess::isFieldHiddenByExistingContactSettings in Webform CiviCRM Integration 8.5

Test whether a field has been hidden due to existing contact settings

ame heckSubmitDisabledSetting Checks if 'Submit Disabled' setting should be considered

Parameters

$ent:

$c:

$table:

$n:

Return value

bool

2 calls to WebformCivicrmPostProcess::isFieldHiddenByExistingContactSettings()
WebformCivicrmPostProcess::fillDataFromSubmission in src/WebformCivicrmPostProcess.php
Fill data array with submitted form values
WebformCivicrmPostProcess::validate in src/WebformCivicrmPostProcess.php
Called after a webform is submitted Or, for a multipage form, called after each page

File

src/WebformCivicrmPostProcess.php, line 2587
Front-end form validation and post-processing.

Class

WebformCivicrmPostProcess

Namespace

Drupal\webform_civicrm

Code

private function isFieldHiddenByExistingContactSettings($ent, $c, $table, $n, $name, $checkSubmitDisabledSetting = FALSE) {
  if ($ent === 'contact' && isset($this->enabled["civicrm_{$c}_contact_1_contact_existing"])) {
    $component = $this->node
      ->getElement("civicrm_{$c}_contact_1_contact_existing");
    $existing_contact_val = $this
      ->submissionValue($component['#form_key']);

    // Fields are hidden if value is empty (no selection) or a numeric contact id
    if (!$existing_contact_val[0] || is_numeric($existing_contact_val[0])) {
      $type = $table == 'contact' && strpos($name, 'name') ? 'name' : $table;
      $component += [
        'hide_fields' => [],
      ];
      if (in_array($type, $component['hide_fields'])) {

        // Check to see if configured to Submit disabled field value(s)
        if ($checkSubmitDisabledSetting && $component['submit_disabled']) {
          return FALSE;
        }

        // With the no_hide_blank setting we must load the contact to determine if the field was hidden
        if (wf_crm_aval($component, 'no_hide_blank')) {

          // @todo this method doesn't exist?
          $value = wf_crm_aval($this
            ->loadContact($c), "{$table}:{$n}:{$name}");
          return !(!$value && !is_numeric($value));
        }
        return TRUE;
      }
    }
  }
  return FALSE;
}