From 36cf948480cdddaf696ef3e8b2ab0cb0f1ca6794 Mon Sep 17 00:00:00 2001 From: Maxim Podorov Date: Mon, 24 Dec 2012 14:36:24 +0400 Subject: [PATCH] Rules module support. --- modal_forms.info | 1 + modal_forms.rules.inc | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 0 deletions(-) create mode 100644 modal_forms.rules.inc diff --git a/modal_forms.info b/modal_forms.info index 7bdba57..abdde9e 100644 --- a/modal_forms.info +++ b/modal_forms.info @@ -2,4 +2,5 @@ name = Modal forms description = This module use ctools modal feature to open some common forms in a modal window. dependencies[] = ctools core = 7.x +files[] = modal_forms.rules.inc configure = admin/config/development/modal_forms diff --git a/modal_forms.rules.inc b/modal_forms.rules.inc new file mode 100644 index 0000000..d0d16a2 --- /dev/null +++ b/modal_forms.rules.inc @@ -0,0 +1,58 @@ + array( + 'label' => t('Page redirect (modal forms aware)'), + 'group' => t('System'), + 'parameter' => array( + 'url' => array( + 'type' => 'uri', + 'label' => t('URL'), + 'description' => t('A Drupal path, path alias, or external URL to redirect to. Enter (optional) queries after "?" and (optional) anchor after "#".'), + ), + 'force' => array( + 'type' => 'boolean', + 'label' => t('Force redirect'), + 'restriction' => 'input', + 'description' => t("Force the redirect even if another destination parameter is present. Per default Drupal would redirect to the path given as destination parameter, in case it is set. Usually the destination parameter is set by appending it to the URL, e.g. !example_url", array('!example_url' => 'http://example.com/user/login?destination=node/2')), + 'optional' => TRUE, + 'default value' => TRUE, + ), + 'destination' => array( + 'type' => 'boolean', + 'label' => t('Append destination parameter'), + 'restriction' => 'input', + 'description' => t('Whether to append a destination parameter to the URL, so another redirect issued later on would lead back to the origin page.'), + 'optional' => TRUE, + 'default value' => FALSE, + ), + ), + 'access callback' => 'rules_system_integration_access', + ), + ); +} + +/** + * Action: Modal forms aware page redirect. + * + */ +function modal_forms_aware_redirect($url, $force = FALSE, $destination = FALSE) { + if ((arg(0) === 'modal_forms') && (arg(1) === 'ajax')) { + // Keep the current destination parameter if there is one set. + if (($destination) && (isset($_GET['destination']))) { + $url .= '&'; + $url .= drupal_http_build_query(drupal_get_destination()); + } + $_GET['destination'] = $url; + return; + } + rules_action_drupal_goto($url, $force, $destination); +} -- 1.7.0.4