media_ahah.inc 3.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?php
// $Id$

/**
 * @file
 * Media AHAH
 *
 * AHAH functions for the Media module.
 */

/**
 * This function builds the form elements for the file formater based
 * on the node type and field for settings and the file extension to get the
 * formatters.
 *
 * @param string $registration_id
 *   The id of the registration creating this formatter.
 * @param string $node_type
 *   The kind of node.
 * @param string $field
 *   The machine name of the field being operated on.
 * @param string $uri
 *   (optional) The uri to the item, or file://path if it is being uploaded.
 * @param string $file_extension
 *   (optional) The kind of file that will be operated on.
 */
function media_ahah_formatter_load() { //$registration_id, $node_type, $field, $uri = NULL, $file_extension = NULL) {
  // The form is generated in an include file which we need to include manually.
  include_once 'modules/node/node.pages.inc';
30
  
31
  // We're starting in step #3, preparing for #4.
32
  $form_state    = array('storage' => NULL, 'submitted' => FALSE);
33
  $form_build_id = $_POST['form_build_id'];
34
  
35 36 37 38
  // Step #4.
  $form = form_get_cache($form_build_id, $form_state);

  // Preparing for #5.
39 40 41
  $args                = $form['#parameters'];
  $form_id             = array_shift($args);
  $form_state['post']  = $form['#post'] = $_POST;
42 43 44 45
  $form['#programmed'] = $form['#redirect'] = FALSE;

  // Step #5.
  drupal_process_form($form_id, $form, $form_state);
46
  
47 48 49 50 51 52 53 54
  // Step #6 and #7 and #8.
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  // Do whatever we need here for Step #9.
  drupal_set_message('media_ahah_formatter_load can add anything here (if necessary).');

  // Step #10: Output any drupal messages and the new form.
  $media_tabs = $form[$field]['media']['media_tabs'];
55
  $output     = theme('status_messages') . drupal_render($media_tabs);
56 57 58 59 60 61

  // Ensure any changes to Drupal.settings js are preserved.
  $javascript = drupal_add_js(NULL, NULL, 'header');

  // Final rendering callback.
  drupal_json(array(
62 63
    'status'   => TRUE,
    'data'     => $output,
64 65 66 67 68 69 70 71 72 73
    'settings' => call_user_func_array('array_merge_recursive', $javascript['setting']),
  ));
}

/**
 * TODO: Document
 */
function media_ahah_metadata_ahah() {
  // The form is generated in an include file which we need to include manually.
  include_once 'modules/node/node.pages.inc';
74
  
75
  // We're starting in step #3, preparing for #4.
76
  $form_state    = array('storage' => NULL, 'submitted' => FALSE);
77
  $form_build_id = $_POST['form_build_id'];
78
  
79 80 81 82
  // Step #4.
  $form = form_get_cache($form_build_id, $form_state);

  // Preparing for #5.
83 84 85
  $args                = $form['#parameters'];
  $form_id             = array_shift($args);
  $form_state['post']  = $form['#post'] = $_POST;
86 87 88 89
  $form['#programmed'] = $form['#redirect'] = FALSE;

  // Step #5.
  drupal_process_form($form_id, $form, $form_state);
90
  
91 92 93 94 95 96 97 98
  // Step #6 and #7 and #8.
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  // Do whatever we need here for Step #9.
  drupal_set_message('final submission: media_ahah_metadata_ahah can do something here, maybe display a new add file form?');

  // Step #10: Output any drupal messages and the new form.
  $media_tabs = $form[$field]['media']['media_tabs'];
99
  $output     = theme('status_messages') . drupal_render($media_tabs);
100 101 102 103 104 105

  // Ensure any changes to Drupal.settings js are preserved.
  $javascript = drupal_add_js(NULL, NULL, 'header');

  // Final rendering callback.
  drupal_json(array(
106 107
    'status'   => TRUE,
    'data'     => $output,
108 109 110
    'settings' => call_user_func_array('array_merge_recursive', $javascript['setting']),
  ));
}