You are here

function activeedit_render in Javascript Tools 5

1 string reference to 'activeedit_render'
activeedit_form_alter in activeedit/activeedit.module
Implementation of hook_form_alter().

File

activeedit/activeedit.module, line 70

Code

function activeedit_render($form_id, $form) {
  $key = $_REQUEST['activeedit_id'];
  $type = $_REQUEST['activeedit_type'];
  $submit = isset($_POST) && $_POST['activeedit_submit'];
  $settings = activeedit_types($type);
  activeedit_node_form_id($form_id, $key);
  $object = NULL;

  // We only need to set the object if we are returning data after a submit.
  if ($submit) {
    switch ($form_id) {
      case 'node_form':

        // Third argument forces a refresh to reflect changed data.
        if (arg(0) == 'node' && is_numeric(arg(1))) {
          $object = node_load(arg(1), NULL, TRUE);
        }
        break;
      case 'comment_form':
        if (arg(0) == 'comment' && arg(1) == 'edit' && is_numeric(arg(2))) {
          $object = _comment_load(arg(2), NULL, TRUE);
        }
        break;
    }
  }
  $error = form_get_errors() ? TRUE : FALSE;
  $targets = activeedit_get_targets($type, FALSE, TRUE, $object);
  if ($submit && !$error) {
    $data = array(
      'error' => $error,
      'message' => theme('status_messages'),
      'content' => $targets[$key]['#content'],
      'placement' => $settings['#placement'],
    );
  }
  else {

    // Filter the form.
    // Only filter if there are filters registered.
    // Otherwise we present the full form.
    if (count($targets[$key]['#form'][$form_id])) {
      formfilter_filter_form($form, $targets[$key]['#form'][$form_id], TRUE);
    }
    unset($form['#prefix']);
    unset($form['#suffix']);
    activeedit_convert_submits($form, $targets[$key]['#submit_text']);
    $data = array(
      'error' => $error,
      'message' => theme('status_messages'),
      'content' => drupal_render($form),
    );
  }
  print drupal_to_js(array(
    'status' => TRUE,
    'data' => $data,
  ));
  exit;
}