summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--filefield.module22
-rw-r--r--filefield_widget.inc12
2 files changed, 26 insertions, 8 deletions
diff --git a/filefield.module b/filefield.module
index 6658cb3..f405489 100644
--- a/filefield.module
+++ b/filefield.module
@@ -508,16 +508,34 @@ function filefield_js($type_name, $field_name, $delta) {
$field_form[$delta]['#prefix'] = '<div class="ahah-new-content">';
$field_form[$delta]['#suffix'] = '</div>';
- $output = theme('status_messages') . drupal_render($field_form[$delta]);
+ $output = drupal_render($field_form[$delta]);
// AHAH is not being nice to us and doesn't know the "other" button (that is,
// either "Upload" or "Delete") yet. Which in turn causes it not to attach
// AHAH behaviours after replacing the element. So we need to tell it first.
+
+ // Loop through the JS settings and find the settings needed for our buttons.
$javascript = drupal_add_js(NULL, NULL);
+ $filefield_ahah_settings = array();
if (isset($javascript['setting'])) {
- $output .= '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>';
+ foreach ($javascript['setting'] as $settings) {
+ if (isset($settings['ahah'])) {
+ foreach ($settings['ahah'] as $id => $ahah_settings) {
+ if (strpos($id, 'filefield-upload') || strpos($id, 'filefield-remove')) {
+ $filefield_ahah_settings[$id] = $ahah_settings;
+ }
+ }
+ }
+ }
}
+ // Add the AHAH settings needed for our new buttons.
+ if (!empty($filefield_ahah_settings)) {
+ $output .= '<script type="text/javascript">jQuery.extend(Drupal.settings.ahah, '. drupal_to_js($filefield_ahah_settings) .');</script>';
+ }
+
+ $output = theme('status_messages') . $output;
+
// For some reason, file uploads don't like drupal_json() with its manual
// setting of the text/javascript HTTP header. So use this one instead.
$GLOBALS['devel_shutdown'] = false;
diff --git a/filefield_widget.inc b/filefield_widget.inc
index b1f2289..f37ee43 100644
--- a/filefield_widget.inc
+++ b/filefield_widget.inc
@@ -193,7 +193,7 @@ function filefield_widget_process($element, $edit, &$form_state, $form) {
}
// Check if a remove button was clicked.
- $remove_name = $element['#field_name'] .'_'. $element['#delta'] .'_remove_btn';
+ $remove_name = $element['#field_name'] .'_'. $element['#delta'] .'_filefield_remove';
if (isset($form_state['clicked_button']) && $form_state['clicked_button']['#name'] == $remove_name) {
$item = array('fid' => 0, 'list' => $field['list_default'], 'data' => array('description' => ''));
}
@@ -254,7 +254,7 @@ function filefield_widget_process($element, $edit, &$form_state, $form) {
$element['#attributes']['id'] = $element['#id'] .'-ahah-wrapper';
$element['#prefix'] = '<div '. drupal_attributes($element['#attributes']) .'>';
$element['#suffix'] = '</div>';
- $element['upload_btn'] = array(
+ $element['filefield_upload'] = array(
'#type' => 'submit',
'#value' => t('Upload'),
'#process' => array('form_expand_ahah'),
@@ -272,11 +272,11 @@ function filefield_widget_process($element, $edit, &$form_state, $form) {
'#access' => empty($item['fid']),
);
- $element['remove_btn'] = array(
- '#name' => $element['#field_name'] .'_'. $element['#delta'] .'_remove_btn',
+ $element['filefield_remove'] = array(
+ '#name' => $element['#field_name'] .'_'. $element['#delta'] .'_filefield_remove',
'#type' => 'submit',
'#value' => t('Remove'),
- '#process' => array('filefield_widget_process_remove_btn', 'form_expand_ahah'),
+ '#process' => array('form_expand_ahah'),
'#submit' => array('node_form_submit_build_node'),
'#ahah' => array( // with JavaScript
'path' => 'filefield/ahah/'. $element['#type_name'] .'/'. $element['#field_name'] .'/'. $element['#delta'],
@@ -315,7 +315,7 @@ function theme_filefield_widget_preview($item) {
function theme_filefield_widget_item($element) {
// Put the upload button directly after the upload field.
- $element['upload']['#field_suffix'] = drupal_render($element['upload_btn']);
+ $element['upload']['#field_suffix'] = drupal_render($element['filefield_upload']);
$element['upload']['#theme'] = 'filefield_widget_file';
$output = '';