You are here

function multiform_sharedfields_hide_elements in Multiple forms 7.2

Hide dependent sharedfields.

1 call to multiform_sharedfields_hide_elements()
multiform_sharedfields_process in ./multiform.module
Process sharedfields. Hide dependent sharedfields at form rendering and set their values in _POST after form submission.

File

./multiform.sharedfields.inc, line 61

Code

function multiform_sharedfields_hide_elements($multiform, $sharedfields_info, &$form, $form_state) {
  if (isset($form_state['#subform_index'])) {
    $multiform_id = $multiform['#multiform_id'];
    $subform_index = $form_state['#subform_index'];
    if (isset($sharedfields_info[$multiform_id])) {
      foreach ($sharedfields_info[$multiform_id] as $item) {
        if ($item['#dependent']['#index'] == $subform_index) {
          $array_parents_dependent = $item['#dependent']['#array_parents'];
          if (drupal_array_nested_key_exists($form, $array_parents_dependent)) {
            array_push($array_parents_dependent, '#pre_render');
            $pre_render = drupal_array_get_nested_value($form, $array_parents_dependent);
            if (is_array($pre_render)) {
              $pre_render[] = 'multiform_sharedfields_pre_render';
            }
            else {
              $pre_render = array(
                'multiform_sharedfields_pre_render',
              );
            }
            drupal_array_set_nested_value($form, $array_parents_dependent, $pre_render, TRUE);
          }
        }
      }
    }
  }
}