diff --git a/includes/ajax.inc b/includes/ajax.inc index 6e8e277..feb0747 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -390,8 +390,13 @@ function ajax_form_callback() { if (!empty($form_state['triggering_element'])) { $callback = $form_state['triggering_element']['#ajax']['callback']; } - if (!empty($callback) && function_exists($callback)) { - $result = $callback($form, $form_state); + if (!empty($callback) && is_callable($callback)) { + if (strpos($callback, '::')) { + // Handle static class method. + $result = call_user_func_array($callback, array($form, $form_state)); + } else { + $result = $callback($form, $form_state); + } if (!(is_array($result) && isset($result['#type']) && $result['#type'] == 'ajax')) { // Turn the response into a #type=ajax array if it isn't one already. diff --git a/includes/form.inc b/includes/form.inc index 0d358c2..3b28164 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -788,7 +788,20 @@ function drupal_retrieve_form($form_id, &$form_state) { // We first check to see if there's a function named after the $form_id. // If there is, we simply pass the arguments on to it to get the form. - if (!function_exists($form_id)) { + // Extended to handle static class methods as form ids. + $sep = '::'; + $is_static_method = strpos($form_id,$sep); + $function_exists = false; + if ($is_static_method) { + $explode = explode($sep,$form_id); + $class = $explode[0]; + $method = $explode[1]; + $function_exists = method_exists($class,$method); + } + else { + $function_exists = function_exists($form_id); + } + if (!$function_exists) { // In cases where many form_ids need to share a central constructor function, // such as the node editing form, modules can implement hook_forms(). It // maps one or more form_ids to the correct constructor functions. @@ -1510,7 +1523,12 @@ function form_execute_handlers($type, &$form, &$form_state) { $batch['has_form_submits'] = TRUE; } else { - $function($form, $form_state); + if (strpos($function, '::')) { + // Handle static class method. + call_user_func_array($function, array($form, &$form_state)); + } else { + $function($form, $form_state); + } } $return = TRUE; }