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
8efbe513
Commit
8efbe513
authored
17 years ago
by
Gábor Hojtsy
Browse files
Options
Downloads
Patches
Plain Diff
#173656
by qucksketch: fix upload form ordering and delete buttons on preview, among smaller issues
parent
bef39dc0
Branches
Branches containing commit
Tags
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
modules/upload/upload.module
+53
-18
53 additions, 18 deletions
modules/upload/upload.module
with
53 additions
and
18 deletions
modules/upload/upload.module
+
53
−
18
View file @
8efbe513
...
...
@@ -191,11 +191,25 @@ function upload_node_form_submit($form, &$form_state) {
$_SESSION
[
'upload_files'
][
$file
->
fid
]
=
$file
;
}
//
a
ttach session files to node.
//
A
ttach session files to node.
if
(
!
empty
(
$_SESSION
[
'upload_files'
]))
{
foreach
(
$_SESSION
[
'upload_files'
]
as
$fid
=>
$file
)
{
$form_state
[
'values'
][
'files'
][
$fid
]
=
$file
;
if
(
!
isset
(
$form_state
[
'values'
][
'files'
][
$fid
][
'filepath'
]))
{
$form_state
[
'values'
][
'files'
][
$fid
]
=
(
array
)
$file
;
}
}
}
// Order the form according to the set file weight values.
if
(
!
empty
(
$form_state
[
'values'
][
'files'
]))
{
$microweight
=
0.001
;
foreach
(
$form_state
[
'values'
][
'files'
]
as
$fid
=>
$file
)
{
if
(
is_numeric
(
$fid
))
{
$form_state
[
'values'
][
'files'
][
$fid
][
'#weight'
]
=
$file
[
'weight'
]
+
$microweight
;
$microweight
+=
0.001
;
}
}
uasort
(
$form_state
[
'values'
][
'files'
],
'element_sort'
);
}
}
...
...
@@ -463,7 +477,10 @@ function upload_delete_revision($node) {
function
_upload_form
(
$node
)
{
global
$user
;
$form
[
'#theme'
]
=
'upload_form_new'
;
$form
=
array
(
'#theme'
=>
'upload_form_new'
,
'#cache'
=>
TRUE
,
);
if
(
!
empty
(
$node
->
files
)
&&
is_array
(
$node
->
files
))
{
$form
[
'files'
][
'#theme'
]
=
'upload_form_current'
;
...
...
@@ -493,6 +510,7 @@ function _upload_form($node) {
if
(
user_access
(
'upload files'
))
{
$limits
=
_upload_file_limits
(
$user
);
$form
[
'new'
][
'#weight'
]
=
10
;
$form
[
'new'
][
'upload'
]
=
array
(
'#type'
=>
'file'
,
'#title'
=>
t
(
'Attach new file'
),
...
...
@@ -550,6 +568,7 @@ function theme_upload_form_current(&$form) {
* @ingroup themeable
*/
function
theme_upload_form_new
(
$form
)
{
drupal_add_tabledrag
(
'upload-attachments'
,
'order'
,
'sibling'
,
'upload-weight'
);
$output
=
drupal_render
(
$form
);
return
$output
;
}
...
...
@@ -571,20 +590,46 @@ function upload_load($node) {
* Menu-callback for JavaScript-based uploads.
*/
function
upload_js
()
{
// Load the form from the Form API cache.
$cache
=
cache_get
(
'form_'
.
$_POST
[
'form_build_id'
],
'cache_form'
);
// We only do the upload.module part of the node validation process.
$node
=
(
object
)
$_POST
;
$form_state
=
array
();
unset
(
$node
->
files
[
'upload'
]);
$form
=
$cache
->
data
;
$form_state
=
array
(
'values'
=>
$_POST
);
// Handle new uploads, and merge tmp files into node-files.
upload_node_form_submit
(
array
()
,
$form_state
);
$node
->
files
=
upload_load
(
$node
);
upload_node_form_submit
(
$form
,
$form_state
);
$node
_
files
=
upload_load
(
$node
);
if
(
!
empty
(
$form_state
[
'values'
][
'files'
]))
{
foreach
(
$form_state
[
'values'
][
'files'
]
as
$fid
=>
$file
)
{
$node
->
files
[
$fid
]
=
$file
;
if
(
is_numeric
(
$fid
))
{
$node
->
files
[
$fid
]
=
$file
;
if
(
!
isset
(
$file
[
'filepath'
]))
{
$node
->
files
[
$fid
]
=
$node_files
[
$fid
];
}
}
}
}
$form
=
_upload_form
(
$node
);
// Update the default values changed in the $_POST array.
$files
=
isset
(
$_POST
[
'files'
])
?
$_POST
[
'files'
]
:
array
();
foreach
(
$files
as
$fid
=>
$file
)
{
if
(
is_numeric
(
$fid
))
{
$form
[
'files'
][
$fid
][
'description'
][
'#default_value'
]
=
$file
[
'description'
];
$form
[
'files'
][
$fid
][
'list'
][
'#default_value'
]
=
isset
(
$file
[
'list'
])
?
1
:
0
;
$form
[
'files'
][
$fid
][
'remove'
][
'#default_value'
]
=
isset
(
$file
[
'remove'
])
?
1
:
0
;
$form
[
'files'
][
$fid
][
'weight'
][
'#default_value'
]
=
$file
[
'weight'
];
}
}
// Add the new element to the stored form state and resave.
$cache
->
data
[
'attachments'
][
'wrapper'
]
=
array_merge
(
$cache
->
data
[
'attachments'
][
'wrapper'
],
$form
);
cache_set
(
'form_'
.
$_POST
[
'form_build_id'
],
$cache
->
data
,
'cache_form'
,
$cache
->
expire
);
// Render the form for output.
$form
+=
array
(
'#post'
=>
$_POST
,
'#programmed'
=>
FALSE
,
...
...
@@ -594,16 +639,6 @@ function upload_js() {
drupal_alter
(
'form'
,
$form
,
array
(),
'upload_js'
);
$form_state
=
array
(
'submitted'
=>
FALSE
);
$form
=
form_builder
(
'upload_js'
,
$form
,
$form_state
);
// Maintain the list and delete checkboxes values.
$files
=
isset
(
$_POST
[
'files'
])
?
$_POST
[
'files'
]
:
array
();
foreach
(
$files
as
$fid
=>
$file
)
{
if
(
is_numeric
(
$fid
))
{
$form
[
'files'
][
$fid
][
'list'
][
'#value'
]
=
isset
(
$file
[
'list'
])
?
1
:
0
;
$form
[
'files'
][
$fid
][
'remove'
][
'#value'
]
=
isset
(
$file
[
'remove'
])
?
1
:
0
;
}
}
$output
=
theme
(
'status_messages'
)
.
drupal_render
(
$form
);
// We send the updated file attachments form.
...
...
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