Merge in 5.20
[civicrm-core.git] / CRM / Core / QuickForm / Action / Jump.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 * Redefine the jump action.
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20 class CRM_Core_QuickForm_Action_Jump extends CRM_Core_QuickForm_Action {
21
22 /**
23 * Class constructor.
24 *
25 * @param object $stateMachine
26 * Reference to state machine object.
27 *
28 * @return \CRM_Core_QuickForm_Action_Jump
29 */
30 public function __construct(&$stateMachine) {
31 parent::__construct($stateMachine);
32 }
33
34 /**
35 * Processes the request.
36 *
37 * @param CRM_Core_Form $page
38 * CRM_Core_Form the current form-page.
39 * @param string $actionName
40 * Current action name, as one Action object can serve multiple actions.
41 *
42 * @return void
43 */
44 public function perform(&$page, $actionName) {
45 // check whether the page is valid before trying to go to it
46 if ($page->controller->isModal()) {
47 // we check whether *all* pages up to current are valid
48 // if there is an invalid page we go to it, instead of the
49 // requested one
50 $pageName = $page->getAttribute('id');
51 if (!$page->controller->isValid($pageName)) {
52 $pageName = $page->controller->findInvalid();
53 }
54 $current = &$page->controller->getPage($pageName);
55 }
56 else {
57 $current = &$page;
58 }
59 // generate the URL for the page 'display' event and redirect to it
60 $action = $current->getAttribute('action');
61 // prevent URLs that end in ? from causing redirects
62 $action = rtrim($action, '?');
63 // FIXME: this should be passed through CRM_Utils_System::url()
64 $url = $action . (FALSE === strpos($action, '?') ? '?' : '&') . $current->getButtonName('display') . '=true' . '&qfKey=' . $page->get('qfKey');
65
66 CRM_Utils_System::redirect($url);
67 }
68
69 }