You are here

function asaf_handle_areas in Asaf (ajax submit for any form) 8

Same name and namespace in other branches
  1. 7 asaf.module \asaf_handle_areas()
1 call to asaf_handle_areas()
asaf_prepare_form in ./asaf.module
Attach ajax handlers to the specified buttons.

File

./asaf.module, line 254
Main module file.

Code

function asaf_handle_areas(&$element, $key, &$form_state) {
  if (!empty($element['#asaf_area'])) {
    $element['#asaf_area_id'] = asaf_get_area_wrapper_id($element['#asaf_area'], $form_state);

    /* When the form inserted directly in block, like user_login_block, or any other form which implemented in the
     * following way:
     *
     * function HOOK_block_view($delta = '') {
     *   return array(
     *     'subject' => t('Form title'),
     *     'content' => drupal_get_form('form_constructor'),
     *   );
     * }
     *
     * form area wrapper doesn't work correctly because block module use block.tpl.php as theme wrapper for block
     * content. In this case block wrapper HTML (block wrapper and block title) will be rendered inside form area
     * wrapper, and it will be loosed after first form update with asaf. To resolve this bug we have to wrap form
     * manually on the client-side using data-asaf-area-wrapper-id attribute */
    if ($element['#asaf_area'] == 'form') {
      $element['#attributes']['data-asaf-area-name'] = $element['#asaf_area'];
      $element['#attributes']['data-asaf-area-wrapper-id'] = $element['#asaf_area_id'];
    }
    else {
      $element['#prefix'] = '<div id="' . $element['#asaf_area_id'] . '" class="asaf-area-wrapper asaf-' . $element['#asaf_area'] . '-area-wrapper">' . (isset($element['#prefix']) ? $element['#prefix'] : '');
      $element['#suffix'] = (isset($element['#suffix']) ? $element['#suffix'] : '') . '</div>';
      $element['#attributes']['data-asaf-area-name'] = $element['#asaf_area'];
    }
  }
  foreach (element_children($element) as $child_key) {
    asaf_handle_areas($element[$child_key], $key ? $key . '][' . $child_key : $child_key, $form_state);
  }
}