Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
0e3fda75
Commit
0e3fda75
authored
15 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
#645822
by sun: Fixed #ajax is not extensible (and partially buggy).
parent
fdd39823
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
includes/ajax.inc
+35
-23
35 additions, 23 deletions
includes/ajax.inc
with
35 additions
and
23 deletions
includes/ajax.inc
+
35
−
23
View file @
0e3fda75
...
...
@@ -369,6 +369,11 @@ function ajax_deliver($page_callback_result) {
function
ajax_process_form
(
$element
,
&
$form_state
)
{
$js_added
=
&
drupal_static
(
__FUNCTION__
,
array
());
// Nothing to do if there is neither a callback nor a path.
if
(
!
(
isset
(
$element
[
'#ajax'
][
'callback'
])
||
isset
(
$element
[
'#ajax'
][
'path'
])))
{
return
$element
;
}
// Add a reasonable default event handler if none was specified.
if
(
isset
(
$element
[
'#ajax'
])
&&
!
isset
(
$element
[
'#ajax'
][
'event'
]))
{
switch
(
$element
[
'#type'
])
{
...
...
@@ -403,38 +408,45 @@ function ajax_process_form($element, &$form_state) {
// Adding the same JavaScript settings twice will cause a recursion error,
// we avoid the problem by checking if the JavaScript has already been added.
if
(
!
isset
(
$js_added
[
$element
[
'#id'
]])
&&
(
isset
(
$element
[
'#ajax'
][
'callback'
])
||
isset
(
$element
[
'#ajax'
][
'path'
]))
&&
isset
(
$element
[
'#ajax'
][
'event'
]))
{
drupal_add_library
(
'system'
,
'form'
);
$element
[
'#attached'
][
'js'
][]
=
'misc/ajax.js'
;
$ajax_binding
=
array
(
'url'
=>
isset
(
$element
[
'#ajax'
][
'callback'
])
?
url
(
'system/ajax'
)
:
url
(
$element
[
'#ajax'
][
'path'
]),
'event'
=>
$element
[
'#ajax'
][
'event'
],
'keypress'
=>
empty
(
$element
[
'#ajax'
][
'keypress'
])
?
NULL
:
$element
[
'#ajax'
][
'keypress'
],
'wrapper'
=>
empty
(
$element
[
'#ajax'
][
'wrapper'
])
?
NULL
:
$element
[
'#ajax'
][
'wrapper'
],
'selector'
=>
empty
(
$element
[
'#ajax'
][
'selector'
])
?
'#'
.
$element
[
'#id'
]
:
$element
[
'#ajax'
][
'selector'
],
'effect'
=>
empty
(
$element
[
'#ajax'
][
'effect'
])
?
'none'
:
$element
[
'#ajax'
][
'effect'
],
'speed'
=>
empty
(
$element
[
'#ajax'
][
'effect'
])
?
'none'
:
$element
[
'#ajax'
][
'effect'
],
'method'
=>
empty
(
$element
[
'#ajax'
][
'method'
])
?
'replace'
:
$element
[
'#ajax'
][
'method'
],
'progress'
=>
empty
(
$element
[
'#ajax'
][
'progress'
])
?
array
(
'type'
=>
'throbber'
)
:
$element
[
'#ajax'
][
'progress'
],
'button'
=>
isset
(
$element
[
'#executes_submit_callback'
])
?
array
(
$element
[
'#name'
]
=>
$element
[
'#value'
])
:
FALSE
,
if
(
!
isset
(
$js_added
[
$element
[
'#id'
]])
&&
isset
(
$element
[
'#ajax'
][
'event'
]))
{
$element
[
'#attached'
][
'library'
][]
=
array
(
'system'
,
'form'
);
$element
[
'#attached'
][
'js'
][
'misc/ajax.js'
]
=
array
(
'weight'
=>
JS_LIBRARY
+
2
);
$settings
=
$element
[
'#ajax'
];
// Assign default settings.
$settings
+=
array
(
'selector'
=>
'#'
.
$element
[
'#id'
],
'effect'
=>
'none'
,
'speed'
=>
'none'
,
'method'
=>
'replace'
,
'progress'
=>
array
(
'type'
=>
'throbber'
),
'formPath'
=>
implode
(
'/'
,
$element
[
'#array_parents'
]),
);
// Convert a simple #ajax['progress'] type string into an array.
if
(
is_string
(
$ajax_binding
[
'progress'
]))
{
$ajax_binding
[
'progress'
]
=
array
(
'type'
=>
$ajax_binding
[
'progress'
]);
// Process special settings.
$settings
[
'url'
]
=
isset
(
$settings
[
'path'
])
?
url
(
$settings
[
'path'
])
:
url
(
'system/ajax'
);
unset
(
$settings
[
'path'
]);
$settings
[
'button'
]
=
isset
(
$element
[
'#executes_submit_callback'
])
?
array
(
$element
[
'#name'
]
=>
$element
[
'#value'
])
:
FALSE
;
// Convert a simple #ajax['progress'] string into an array.
if
(
is_string
(
$settings
[
'progress'
]))
{
$settings
[
'progress'
]
=
array
(
'type'
=>
$settings
[
'progress'
]);
}
// Change progress path to a full URL.
if
(
isset
(
$ajax_binding
[
'progress'
][
'path'
]))
{
$ajax_binding
[
'progress'
][
'url'
]
=
url
(
$ajax_binding
[
'progress'
][
'path'
]);
if
(
isset
(
$settings
[
'progress'
][
'path'
]))
{
$settings
[
'progress'
][
'url'
]
=
url
(
$settings
[
'progress'
][
'path'
]);
unset
(
$settings
[
'progress'
][
'path'
]);
}
// Add progress.js if we're doing a bar display.
if
(
$
ajax_bind
ing
[
'progress'
][
'type'
]
==
'bar'
)
{
drupal_add_js
(
'misc/progress.js'
,
array
(
'cache'
=>
FALSE
)
)
;
if
(
$
sett
ing
s
[
'progress'
][
'type'
]
==
'bar'
)
{
$element
[
'#attached'
][
'js'
][
'misc/progress.js'
]
=
array
(
'cache'
=>
FALSE
);
}
drupal_add_js
(
array
(
'ajax'
=>
array
(
$element
[
'#id'
]
=>
$ajax_binding
)),
'setting'
);
// @todo This is incompatible with drupal_render() caching, but cannot be
// assigned to #attached, because AJAX callbacks render the form in a way
// so that #attached settings are not taken over.
drupal_add_js
(
array
(
'ajax'
=>
array
(
$element
[
'#id'
]
=>
$settings
)),
'setting'
);
$js_added
[
$element
[
'#id'
]]
=
TRUE
;
$form_state
[
'cache'
]
=
TRUE
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment