0

In the link given below , https://drupal.org/node/224333
So as given in below statement you do not have to declare the callback path* what does this mean? I have hook_menu() in d6 which is as follows :

$items['ort/add/ion'] = array(
    'type' => MENU_CALLBACK,
    'page callback' => 'ort_add_ion',
    'access arguments' => array('access content'),
    'file' => 'ort.tion.inc',
  );

Does the link say that for d7 you do not need page callback or something different?


In Drupal 7, you do not have to declare the callback path in hook_menu(), and the callback function is far simpler.

Drupal 6:

<?php
// This function must be pointed to in hook_menu() in D6.
function my_callback_function() {
  // ... Much work to build the form ....

  drupal_process_form($form_id, $form, $form_state);
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  $output = drupal_render($form);

  // Final rendering callback.
  print drupal_json(array('status' => TRUE, 'data' => $output));
  exit();
}
?>

Drupal 7:

<?php
// No path needs be set up to point to the function, and $form and $form_state are provided.
function my_callback_function($form, &$form_state) {
  // Often you would select a portion of the form to match #ajax['wrapper']
  // rather than processing the whole form.
  return $form;  // Either HTML or a render array may be returned.
}
?>
1

The simple answer is it is for ajax items. In drupal 6 you had to declare a path and direct your ahah to it with ['#ahah']['path']. In drupal 7 it is handled automatically and you now use ['#ajax']['callback'] to call the function without having to declare a path.

  • what is the difference between hook_menu in d6 and d7 for ajax callback functions ? – harshal Aug 13 '13 at 8:11
  • In drupal 6 you had to register a path so the javascript knew where to look for results. In drupal 7 this is done automatically for you making ajax much easier in drupal 7 – 2pha Aug 13 '13 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.