You are here

private function CivicrmInlineEntityFormController::fillEntityValues in CiviCRM Entity 7.2

Utility function to fill entity with form values

Parameters

$values:

$entity:

$civicrm_entity_fields:

string $entity_type:

1 call to CivicrmInlineEntityFormController::fillEntityValues()
CivicrmInlineEntityFormController::entityFormSubmit in modules/civicrm_entity_inline/includes/civicrm.civicrm_entity_inline.inc
Handles the submission of an entity form.

File

modules/civicrm_entity_inline/includes/civicrm.civicrm_entity_inline.inc, line 508

Class

CivicrmInlineEntityFormController

Code

private function fillEntityValues(&$values, $entity, $civicrm_entity_fields, $entity_type = '') {
  foreach ($values as $key => $value) {
    if (substr($key, 0, 7) == 'custom_') {
      if (!empty($civicrm_entity_fields['values'][$key]['html_type']) && $civicrm_entity_fields['values'][$key]['html_type'] == 'CheckBox') {
        if (is_array($value)) {
          $stored_value = array();
          foreach ($value as $option => $checkbox_value) {
            if ($checkbox_value) {
              $stored_value[] = $option;
            }
          }
          $entity->{$key} = !empty($stored_value) ? $stored_value : array(
            '',
          );
        }
      }
      else {
        if (is_array($value) && isset($value['value'])) {
          $value = $value['value'];

          //$form_state['values'][$field_name]['und']['form'][$key] = $value;
          $values[$key] = $value;
        }
        $entity->{$key} = $value;
      }
      if (!empty($civicrm_entity_fields['values'][$key]['is_view'])) {
        unset($entity->{$key});
      }
    }
    else {
      if (is_array($value) && isset($value['value'])) {
        $value = $value['value'];

        //$form_state['values'][$field_name]['und']['form'][$key] = $value;
        $values[$key] = $value;
      }
      $entity->{$key} = $value;
    }
  }
}