summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/ajax.inc51
-rw-r--r--includes/common.inc42
-rw-r--r--includes/theme.inc2
3 files changed, 81 insertions, 14 deletions
diff --git a/includes/ajax.inc b/includes/ajax.inc
index 0ec7859aa..2fd7f6941 100644
--- a/includes/ajax.inc
+++ b/includes/ajax.inc
@@ -515,7 +515,26 @@ function ajax_footer() {
}
/**
- * Add AJAX information about a form element to the page to communicate with JavaScript.
+ * Form element process callback to handle #ajax.
+ *
+ * @param $element
+ * An associative array containing the properties of the element.
+ *
+ * @return
+ * The processed element.
+ *
+ * @see ajax_pre_render_element()
+ */
+function ajax_process_form($element, &$form_state) {
+ $element = ajax_pre_render_element($element);
+ if (!empty($element['#ajax_processed'])) {
+ $form_state['cache'] = TRUE;
+ }
+ return $element;
+}
+
+/**
+ * Add AJAX information about an element to the page to communicate with JavaScript.
*
* If #ajax['path'] is set on an element, this additional JavaScript is added
* to the page header to attach the AJAX behaviors. See ajax.js for more
@@ -526,15 +545,22 @@ function ajax_footer() {
* Properties used:
* - #ajax['event']
* - #ajax['path']
+ * - #ajax['options']
* - #ajax['wrapper']
* - #ajax['parameters']
* - #ajax['effect']
*
* @return
- * None. Additional code is added to the header of the page using
- * drupal_add_js().
+ * The processed element with the necessary JavaScript attached to it.
*/
-function ajax_process_form($element, &$form_state) {
+function ajax_pre_render_element($element) {
+ // Skip already processed elements.
+ if (isset($element['#ajax_processed'])) {
+ return $element;
+ }
+ // Initialize #ajax_processed, so we do not process this element again.
+ $element['#ajax_processed'] = FALSE;
+
// Nothing to do if there is neither a callback nor a path.
if (!(isset($element['#ajax']['callback']) || isset($element['#ajax']['path']))) {
return $element;
@@ -567,6 +593,10 @@ function ajax_process_form($element, &$form_state) {
$element['#ajax']['event'] = 'change';
break;
+ case 'link':
+ $element['#ajax']['event'] = 'click';
+ break;
+
default:
return $element;
}
@@ -581,6 +611,8 @@ function ajax_process_form($element, &$form_state) {
// Assign default settings.
$settings += array(
+ 'path' => 'system/ajax',
+ 'options' => array(),
'selector' => '#' . $element['#id'],
'effect' => 'none',
'speed' => 'none',
@@ -593,9 +625,9 @@ function ajax_process_form($element, &$form_state) {
$settings['method'] = 'replaceWith';
}
- // Change path to url.
- $settings['url'] = isset($settings['path']) ? url($settings['path']) : url('system/ajax');
- unset($settings['path']);
+ // Change path to URL.
+ $settings['url'] = url($settings['path'], $settings['options']);
+ unset($settings['path'], $settings['options']);
// Add special data to $settings['submit'] so that when this element
// triggers an AJAX submission, Drupal's form processing can determine which
@@ -614,7 +646,7 @@ function ajax_process_form($element, &$form_state) {
}
unset($settings['trigger_as']);
}
- else {
+ elseif (isset($element['#name'])) {
// Most of the time, elements can submit as themselves, in which case the
// 'trigger_as' key isn't needed, and the element's name is used.
$settings['submit']['_triggering_element_name'] = $element['#name'];
@@ -645,7 +677,8 @@ function ajax_process_form($element, &$form_state) {
'data' => array('ajax' => array($element['#id'] => $settings)),
);
- $form_state['cache'] = TRUE;
+ // Indicate that AJAX processing was successful.
+ $element['#ajax_processed'] = TRUE;
}
return $element;
}
diff --git a/includes/common.inc b/includes/common.inc
index b15dccd2f..62c5d22eb 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -5206,10 +5206,44 @@ function drupal_pre_render_conditional_comments($elements) {
* @return
* The passed in elements containing a rendered link in '#markup'.
*/
-function drupal_pre_render_link($elements) {
- $options = isset($elements['#options']) ? $elements['#options'] : array();
- $elements['#markup'] = l($elements['#title'], $elements['#href'], $options);
- return $elements;
+function drupal_pre_render_link($element) {
+ // By default, link options to pass to l() are normally set in #options.
+ $element += array('#options' => array());
+ // However, within the scope of renderable elements, #attributes is a valid
+ // way to specify attributes, too. Take them into account, but do not override
+ // attributes from #options.
+ if (isset($element['#attributes'])) {
+ $element['#options'] += array('attributes' => array());
+ $element['#options']['attributes'] += $element['#attributes'];
+ }
+
+ // This #pre_render callback can be invoked from inside or outside of a Form
+ // API context, and depending on that, a HTML ID may be already set in
+ // different locations. #options should have precedence over Form API's #id.
+ // #attributes have been taken over into #options above already.
+ if (isset($element['#options']['attributes']['id'])) {
+ $element['#id'] = $element['#options']['attributes']['id'];
+ }
+ elseif (isset($element['#id'])) {
+ $element['#options']['attributes']['id'] = $element['#id'];
+ }
+
+ // Conditionally invoke ajax_pre_render_element(), if #ajax is set.
+ if (isset($element['#ajax']) && !isset($element['#ajax_processed'])) {
+ // If no HTML ID was found above, automatically create one.
+ if (!isset($element['#id'])) {
+ $element['#id'] = $element['#options']['attributes']['id'] = drupal_html_id('ajax-link');
+ }
+ // If #ajax['path] was not specified, use the href as AJAX request URL.
+ if (!isset($element['#ajax']['path'])) {
+ $element['#ajax']['path'] = $element['#href'];
+ $element['#ajax']['options'] = $element['#options'];
+ }
+ $element = ajax_pre_render_element($element);
+ }
+
+ $element['#markup'] = l($element['#title'], $element['#href'], $element['#options']);
+ return $element;
}
/**
diff --git a/includes/theme.inc b/includes/theme.inc
index 4bf80d855..6c7a779d9 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -108,7 +108,7 @@ function drupal_theme_initialize() {
// @see ajax_base_page_theme()
$setting['ajaxPageState'] = array(
'theme' => $theme_key,
- 'themeToken' => drupal_get_token($theme_key),
+ 'theme_token' => drupal_get_token($theme_key),
);
drupal_add_js($setting, 'setting');
}