Issue #1802072 by fubhy, Stalski: Ajax callbacks should be callbacks defined as function or class method.
parent
22ac2df4d9
commit
07ab1e8f61
|
@ -376,8 +376,8 @@ function ajax_form_callback() {
|
||||||
if (!empty($form_state['triggering_element'])) {
|
if (!empty($form_state['triggering_element'])) {
|
||||||
$callback = $form_state['triggering_element']['#ajax']['callback'];
|
$callback = $form_state['triggering_element']['#ajax']['callback'];
|
||||||
}
|
}
|
||||||
if (!empty($callback) && function_exists($callback)) {
|
if (!empty($callback) && is_callable($callback)) {
|
||||||
return $callback($form, $form_state);
|
return call_user_func_array($callback, array(&$form, &$form_state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
* Simpletest mock module for Ajax forms testing.
|
* Simpletest mock module for Ajax forms testing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Drupal\ajax_forms_test\Callbacks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_menu().
|
* Implements hook_menu().
|
||||||
*/
|
*/
|
||||||
|
@ -41,6 +43,8 @@ function ajax_forms_test_menu() {
|
||||||
* Tests form_state['values'] during callback.
|
* Tests form_state['values'] during callback.
|
||||||
*/
|
*/
|
||||||
function ajax_forms_test_simple_form($form, &$form_state) {
|
function ajax_forms_test_simple_form($form, &$form_state) {
|
||||||
|
$object = new Callbacks();
|
||||||
|
|
||||||
$form = array();
|
$form = array();
|
||||||
$form['select'] = array(
|
$form['select'] = array(
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
|
@ -49,7 +53,7 @@ function ajax_forms_test_simple_form($form, &$form_state) {
|
||||||
'green' => 'green',
|
'green' => 'green',
|
||||||
'blue' => 'blue'),
|
'blue' => 'blue'),
|
||||||
'#ajax' => array(
|
'#ajax' => array(
|
||||||
'callback' => 'ajax_forms_test_simple_form_select_callback',
|
'callback' => array($object, 'selectCallback'),
|
||||||
),
|
),
|
||||||
'#suffix' => '<div id="ajax_selected_color">No color yet selected</div>',
|
'#suffix' => '<div id="ajax_selected_color">No color yet selected</div>',
|
||||||
);
|
);
|
||||||
|
@ -58,7 +62,7 @@ function ajax_forms_test_simple_form($form, &$form_state) {
|
||||||
'#type' => 'checkbox',
|
'#type' => 'checkbox',
|
||||||
'#title' => t('Test checkbox'),
|
'#title' => t('Test checkbox'),
|
||||||
'#ajax' => array(
|
'#ajax' => array(
|
||||||
'callback' => 'ajax_forms_test_simple_form_checkbox_callback',
|
'callback' => array($object, 'checkboxCallback'),
|
||||||
),
|
),
|
||||||
'#suffix' => '<div id="ajax_checkbox_value">No action yet</div>',
|
'#suffix' => '<div id="ajax_checkbox_value">No action yet</div>',
|
||||||
);
|
);
|
||||||
|
@ -69,26 +73,6 @@ function ajax_forms_test_simple_form($form, &$form_state) {
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Ajax form callback: Selects color.
|
|
||||||
*/
|
|
||||||
function ajax_forms_test_simple_form_select_callback($form, $form_state) {
|
|
||||||
$commands = array();
|
|
||||||
$commands[] = ajax_command_html('#ajax_selected_color', $form_state['values']['select']);
|
|
||||||
$commands[] = ajax_command_data('#ajax_selected_color', 'form_state_value_select', $form_state['values']['select']);
|
|
||||||
return array('#type' => 'ajax', '#commands' => $commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ajax form callback: Selects checkbox value.
|
|
||||||
*/
|
|
||||||
function ajax_forms_test_simple_form_checkbox_callback($form, $form_state) {
|
|
||||||
$commands = array();
|
|
||||||
$commands[] = ajax_command_html('#ajax_checkbox_value', (int) $form_state['values']['checkbox']);
|
|
||||||
$commands[] = ajax_command_data('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state['values']['checkbox']);
|
|
||||||
return array('#type' => 'ajax', '#commands' => $commands);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form constructor for the Ajax Command display form.
|
* Form constructor for the Ajax Command display form.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Definition of Drupal\ajax_forms_test\Callbacks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Drupal\ajax_forms_test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple object for testing methods as Ajax callbacks.
|
||||||
|
*/
|
||||||
|
class Callbacks {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajax callback triggered by select.
|
||||||
|
*/
|
||||||
|
function selectCallback($form, $form_state) {
|
||||||
|
$commands = array();
|
||||||
|
$commands[] = ajax_command_html('#ajax_selected_color', $form_state['values']['select']);
|
||||||
|
$commands[] = ajax_command_data('#ajax_selected_color', 'form_state_value_select', $form_state['values']['select']);
|
||||||
|
return array('#type' => 'ajax', '#commands' => $commands);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajax callback triggered by checkbox.
|
||||||
|
*/
|
||||||
|
function checkboxCallback($form, $form_state) {
|
||||||
|
$commands = array();
|
||||||
|
$commands[] = ajax_command_html('#ajax_checkbox_value', (int) $form_state['values']['checkbox']);
|
||||||
|
$commands[] = ajax_command_data('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state['values']['checkbox']);
|
||||||
|
return array('#type' => 'ajax', '#commands' => $commands);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue