diff --git a/core/includes/ajax.inc b/core/includes/ajax.inc index a53552b..0c4489e 100644 --- a/core/includes/ajax.inc +++ b/core/includes/ajax.inc @@ -1232,6 +1232,7 @@ function ajax_form_wrapper($form_id, &$form_state) { $commands = array(); $commands[] = ajax_command_dismiss_form(); $redirect = current_path(); + dsm($form_state); if (isset($form_state['redirect'])) { if (is_array($form_state['redirect'])) { $redirect = end($form_state['redirect']); diff --git a/core/includes/common.inc b/core/includes/common.inc index b9df851..4a279ac 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2313,7 +2313,6 @@ function l($text, $path, array $options = array()) { 'query' => array(), 'html' => FALSE, ); - if (!empty($options['modal'])) { $options['attributes']['class'][] = 'use-ajax'; drupal_add_library('system', 'drupal.ajax.modal'); diff --git a/core/modules/image/image.admin.inc b/core/modules/image/image.admin.inc index 933a4ad..643eed6 100644 --- a/core/modules/image/image.admin.inc +++ b/core/modules/image/image.admin.inc @@ -37,6 +37,12 @@ function image_style_form($form, &$form_state, $style) { $title = t('Edit style %name', array('%name' => $style->label())); drupal_set_title($title, PASS_THROUGH); + // Make sure modals are prepared. + drupal_add_library('system', 'drupal.ajax.modal'); + + // Explicitly set the action for ajax behavior. + $form['#action'] = url('admin/config/media/image-styles/edit/' . $style->id()); + $form_state['image_style'] = $style; $form['#tree'] = TRUE; $form['#attached']['css'][drupal_get_path('module', 'image') . '/image.admin.css'] = array(); @@ -88,11 +94,13 @@ function image_style_form($form, &$form_state, $style) { $links['edit'] = array( 'title' => t('edit'), 'href' => 'admin/config/media/image-styles/edit/' . $style->id() . '/effects/' . $key, + 'modal' => TRUE, ); } $links['delete'] = array( 'title' => t('delete'), 'href' => 'admin/config/media/image-styles/edit/' . $style->id() . '/effects/' . $key . '/delete', + 'modal' => TRUE, ); $form['effects'][$key]['operations'] = array( '#type' => 'operations', @@ -137,6 +145,9 @@ function image_style_form($form, &$form_state, $style) { $form['effects']['new']['add'] = array( '#type' => 'submit', '#value' => t('Add'), + '#ajax' => array( + 'callback' => 'image_style_form_add_submit_modal' + ), '#validate' => array('image_style_form_add_validate'), '#submit' => array('image_style_form_submit', 'image_style_form_add_submit'), ); @@ -181,11 +192,44 @@ function image_style_form_add_submit($form, &$form_state) { 'weight' => $form_state['values']['weight'], ); image_effect_save($style, $effect); + $form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style->id(); drupal_set_message(t('The image effect was successfully applied.')); } } /** + * Ajax modal handler for adding a new image effect to an image style. + */ +function image_style_form_add_submit_modal($form, &$form_state) { + $style = $form_state['image_style']; + // Check if this field has any configuration options. + $effect = image_effect_definition_load($form_state['values']['new']); + + // Load the configuration form for this option. + if (isset($effect['form callback'])) { + // Set sensible defaults if they don't already exist. + $form_state = array( + 'rerender' => FALSE, + 'ajax' => TRUE, + 'no_redirect' => TRUE, + 'build_info' => array( + 'args' => array( + $style, + $effect + ) + ) + ); + // Return a modal. + return array('#type' => 'ajax', '#commands' => ajax_form_wrapper('image_effect_form', $form_state)); + } + // If there's no form, immediately add the image effect. + else { + // Reload the page. + return array('#type' => 'ajax', '#commands' => array(ajax_command_redirect($form_state['redirect']))); + } +} + +/** * Submit handler for saving an image style. */ function image_style_form_submit($form, &$form_state) { @@ -343,6 +387,13 @@ function image_effect_form($form, &$form_state, $style, $effect) { } $form_state['image_style'] = $style; $form_state['image_effect'] = $effect; + // Explicitly set the action for ajax behavior. + if (empty($effect['ieid'])) { + $form['#action'] = url('admin/config/media/image-styles/edit/' . $style->id() . '/add/' . $effect['name']); + } + else { + $form['#action'] = url('admin/config/media/image-styles/edit/' . $style->id() . '/effects/' . $effect['ieid']); + } if (!empty($effect['ieid'])) { $title = t('Edit %label effect', array('%label' => $effect['label'])); @@ -414,6 +465,9 @@ function image_effect_delete_form($form, &$form_state, $style, $effect) { $form_state['image_style'] = $style; $form_state['image_effect'] = $effect; + // Explicitly set the action for ajax behavior. + $form['#action'] = url('admin/config/media/image-styles/edit/' . $style->id() . '/effects/' . $effect['ieid']) . '/delete'; + $question = t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $style->label(), '@effect' => $effect['label'])); return confirm_form($form, $question, 'admin/config/media/image-styles/edit/' . $style->id(), '', t('Delete')); } diff --git a/core/modules/image/image.module b/core/modules/image/image.module index c763dc6..0318c5c 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -146,7 +146,7 @@ function image_menu() { 'title' => 'Edit image effect', 'description' => 'Edit an existing effect within a style.', 'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE), - 'page callback' => 'drupal_get_form', + 'page callback' => 'ajax_modal_form', 'page arguments' => array('image_effect_form', 5, 7), 'access arguments' => array('administer image styles'), 'file' => 'image.admin.inc', @@ -155,7 +155,7 @@ function image_menu() { 'title' => 'Delete image effect', 'description' => 'Delete an existing effect from a style.', 'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE), - 'page callback' => 'drupal_get_form', + 'page callback' => 'ajax_modal_form', 'page arguments' => array('image_effect_delete_form', 5, 7), 'access arguments' => array('administer image styles'), 'file' => 'image.admin.inc', @@ -164,7 +164,7 @@ function image_menu() { 'title' => 'Add image effect', 'description' => 'Add a new effect to a style.', 'load arguments' => array(5), - 'page callback' => 'drupal_get_form', + 'page callback' => 'ajax_modal_form', 'page arguments' => array('image_effect_form', 5, 7), 'access arguments' => array('administer image styles'), 'file' => 'image.admin.inc',