Merge pull request #15978 from civicrm/5.20
[civicrm-core.git] / CRM / Core / QuickForm / Action.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * This is the base Action class for all actions which we redefine. This is
14 * integrated with the StateMachine, Controller and State objects
15 *
16 * @package CRM
17 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 */
19 require_once 'HTML/QuickForm/Action.php';
20
21 /**
22 * Class CRM_Core_QuickForm_Action
23 */
24 class CRM_Core_QuickForm_Action extends HTML_QuickForm_Action {
25
26 /**
27 * Reference to the state machine i belong to.
28 * @var object
29 */
30 protected $_stateMachine;
31
32 /**
33 * Constructor.
34 *
35 * @param object $stateMachine
36 * Reference to state machine object.
37 *
38 * @return \CRM_Core_QuickForm_Action
39 */
40 public function __construct(&$stateMachine) {
41 $this->_stateMachine = &$stateMachine;
42 }
43
44 /**
45 * Returns the user to the top of the user context stack.
46 */
47 public function popUserContext() {
48 $session = CRM_Core_Session::singleton();
49 $config = CRM_Core_Config::singleton();
50
51 // check if destination is set, if so goto destination
52 $destination = $this->_stateMachine->getDestination();
53 if ($destination) {
54 $destination = urldecode($destination);
55 }
56 else {
57 $destination = $session->popUserContext();
58
59 if (empty($destination)) {
60 $destination = $config->userFrameworkBaseURL;
61 }
62 }
63
64 //CRM-5839 -do not redirect control.
65 if (!$this->_stateMachine->getSkipRedirection()) {
66 CRM_Utils_System::redirect($destination);
67 }
68 }
69
70 }