CRM_Admin_Form_OptionValue - Set cancel behavior using cancelAction instead of JS
authorTim Otten <totten@civicrm.org>
Tue, 10 Dec 2013 03:02:53 +0000 (19:02 -0800)
committerTim Otten <totten@civicrm.org>
Tue, 10 Dec 2013 03:03:52 +0000 (19:03 -0800)
Coleman told me to do it.

CRM/Admin/Form/OptionValue.php

index 917ee385a22cd4887ceddae12a8905aee191ce26..e168c137031d2d0935c85dd67c96a710f78ad004 100644 (file)
@@ -189,9 +189,8 @@ class CRM_Admin_Form_OptionValue extends CRM_Admin_Form {
       $this->add('select', 'contactOptions', ts('Contact Type'), array('' => '-select-') + $values, TRUE);
     }
 
+    $this->add('hidden', 'gid', $this->_gid);
     $this->addFormRule(array('CRM_Admin_Form_OptionValue', 'formRule'), $this);
-    $cancelURL = CRM_Utils_System::url('civicrm/admin/optionValue', "gid={$this->_gid}&reset=1");
-    $cancelURL = str_replace('&amp;', '&', $cancelURL);
     $this->addButtons(
       array(
         array(
@@ -202,12 +201,21 @@ class CRM_Admin_Form_OptionValue extends CRM_Admin_Form {
         array(
           'type' => 'cancel',
           'name' => ts('Cancel'),
-          'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
         ),
       )
     );
   }
 
+  function cancelAction() {
+    parent::cancelAction();
+
+    $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0);
+    $cancelURL = CRM_Utils_System::url('civicrm/admin/optionValue', "gid={$gid}&reset=1");
+
+    $session = CRM_Core_Session::singleton();
+    $session->pushUserContext($cancelURL);
+  }
+
   /**
    * global form rule
    *