diff --git a/README.txt b/README.txt index bc55f03..b077fbd 100644 --- a/README.txt +++ b/README.txt @@ -21,6 +21,8 @@ Supported forms: * Contact (modal_forms/nojs/contact) * Comment (modal_forms/nojs/comment/reply/%node) * Webform (modal_forms/nojs/webform/%node) +* User profile edit (modal_forms/nojs/user/%user/edit) + Function that rewrite normal links to modal forms links (except for webforms) can be activated on the modules configuration page. diff --git a/js/modal_forms_profile.js b/js/modal_forms_profile.js new file mode 100644 index 0000000..47d8a41 --- /dev/null +++ b/js/modal_forms_profile.js @@ -0,0 +1,11 @@ +(function ($) { + +Drupal.behaviors.initModalFormsProfile = { + attach: function (context, settings) { + $("a[href*='/user/'][href$='/edit'], a[href*='?q=user/'][href$='/edit']", context).once('init-modal-forms-profile', function () { + this.href = this.href.replace(/user\/([0-9]+)\/edit/,"modal_forms/nojs/user/$1/edit"); + }).addClass('ctools-use-modal ctools-modal-modal-popup-large'); + } +}; + +})(jQuery); \ No newline at end of file diff --git a/modal_forms.admin.inc b/modal_forms.admin.inc index 77dd7f1..18c444f 100644 --- a/modal_forms.admin.inc +++ b/modal_forms.admin.inc @@ -86,6 +86,18 @@ function modal_forms_admin_settings() { '#description' => t('Automatically activate Modal forms for links to contact.'), ); + // Profile settings. + $form['modal_forms_profile_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Profile links settings'), + ); + $form['modal_forms_profile_settings']['modal_forms_profile'] = array( + '#type' => 'checkbox', + '#title' => t('Enable for edit user profile links'), + '#default_value' => variable_get('modal_forms_profile', 0), + '#description' => t('Automatically activate Modal forms for links to user/[uid]/edit.'), + ); + // Styles and options settings. $form['modal_forms_custom_settings'] = array( '#type' => 'fieldset', diff --git a/modal_forms.module b/modal_forms.module index 8c4645d..5e98264 100644 --- a/modal_forms.module +++ b/modal_forms.module @@ -85,6 +85,14 @@ function modal_forms_menu() { 'file' => 'modal_forms.pages.inc', 'type' => MENU_CALLBACK, ); + $items['modal_forms/%ctools_js/user/%user/edit'] = array( + 'title' => 'Profile', + 'page callback' => 'modal_forms_profile', + 'page arguments' => array(1, 3), + 'access callback' => 'user_is_logged_in', + 'file' => 'modal_forms.pages.inc', + 'type' => MENU_CALLBACK, + ); $items['modal_forms/%ctools_js/dismiss'] = array( 'title' => 'Dismiss', 'page callback' => 'modal_forms_dismiss', @@ -139,6 +147,12 @@ function modal_forms_form_alter(&$form, &$form_state, $form_id) { $form['name']['#size'] = 30; } break; + case 'user_profile_form': + if (arg(0) == 'modal_forms') { + $form['account']['name']['#size'] = 30; + $form['account']['mail']['#size'] = 30; + } + break; } } @@ -274,6 +288,9 @@ function _modal_forms_doheader() { if (user_access('post comments') && variable_get('modal_forms_comment', 0)) { drupal_add_js($path . '/js/modal_forms_comment.js', array('weight' => -20)); } + if (user_is_logged_in() && variable_get('modal_forms_profile', 0)) { + drupal_add_js($path . '/js/modal_forms_profile.js', array('weight' => -20)); + } $already_added = TRUE; } diff --git a/modal_forms.pages.inc b/modal_forms.pages.inc index 250f9a6..98267d1 100644 --- a/modal_forms.pages.inc +++ b/modal_forms.pages.inc @@ -313,6 +313,41 @@ function modal_forms_view_webform($node, $js = NULL) { } /** + * A modal user profile callback. + */ +function modal_forms_profile($js = NULL, $user) { + + // Fall back if $js is not set. + if (!$js) { + return drupal_get_form('user_profile_form', $user); + } + + ctools_include('user.pages', 'user', ''); + ctools_include('modal'); + ctools_include('ajax'); + $form_state = array( + // 'title' => t('Edit user'), + 'ajax' => TRUE, + 'build_info' => array( + 'args' => array($user), + ), + ); + $output = ctools_modal_form_wrapper('user_profile_form', $form_state); + if (!empty($form_state['executed'])) { + // We'll just overwrite the form output if it was successful. + $output = array(); + ctools_add_js('ajax-responder'); + if (isset($_GET['destination'])) { + $output[] = ctools_ajax_command_redirect($_GET['destination']); + } + else { + $output[] = ctools_ajax_command_reload(); + } + } + print ajax_render($output); +} + +/** * Closes modal windows. */ function modal_forms_dismiss($js = NULL) {