You are here

function multiform_cache_prepare in Multiple forms 7.2

Cache mapped submits info and hide them.

Cache only if submits map is not empty.

1 call to multiform_cache_prepare()
multiform_get_form in ./multiform.module
Returns a form containing a number of other forms.

File

./multiform.inc, line 157

Code

function multiform_cache_prepare($build_id_hash, $settings, &$multiform_form) {
  $cache = array();

  // Actually we don't need to cache settings itself.
  $cache['settings'] = array(
    $settings,
  );

  // @todo: Prepare cache only in case submits map is set.
  $form_keys = array();

  // @todo: Skip submits_map subform
  foreach ($multiform_form['multiform'] as $k => $subform) {
    $form_id = $subform['#form_id'];
    if ($form_id != 'multiform_submits_form') {
      $form_keys[$form_id] = $k;
    }
  }
  foreach ($settings['#subforms'] as $k => $subform) {
    if (!empty($subform['#map']) && isset($form_keys[$subform['form_id']])) {
      $form_key = $form_keys[$subform['form_id']];
      foreach ($subform['#map'] as $m => $map) {
        $key_exists = FALSE;
        $form_key = $form_keys[$subform['form_id']];
        $element = drupal_array_get_nested_value($multiform_form['multiform'][$form_key], $map['#parents'], $key_exists);
        if ($key_exists) {
          $element['#name'] = 'op';
          $settings['#subforms'][$k]['#map'][$m]['#element'] = $element;

          // Hide mapped submit.
          drupal_array_set_nested_value($multiform_form['multiform'][$form_key], array_merge($map['#parents'], array(
            '#printed',
          )), TRUE, TRUE);
        }
      }
    }
  }

  // Set cache.
  cache_set('multiform_settings-' . $build_id_hash, $settings, 'cache', CACHE_TEMPORARY);
}