Merge pull request #15649 from JMAConsulting/core-1346
[civicrm-core.git] / CRM / Core / QuickForm / Action / Done.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 back action.
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18 class CRM_Core_QuickForm_Action_Done extends CRM_Core_QuickForm_Action {
19
20 /**
21 * Class constructor.
22 *
23 * @param object $stateMachine
24 * Reference to state machine object.
25 *
26 * @return \CRM_Core_QuickForm_Action_Done
27 */
28 public function __construct(&$stateMachine) {
29 parent::__construct($stateMachine);
30 }
31
32 /**
33 * Processes the request.
34 * this is basically a self submit, so validate the page
35 * and if success, call post process
36 * when done processing pop to user context
37 *
38 * @param CRM_Core_Form $page
39 * The current form-page.
40 * @param string $actionName
41 * Current action name, as one Action object can serve multiple actions.
42 *
43 * @return object|void
44 */
45 public function perform(&$page, $actionName) {
46 $page->isFormBuilt() or $page->buildForm();
47
48 $pageName = $page->getAttribute('name');
49 $data = &$page->controller->container();
50 $data['values'][$pageName] = $page->exportValues();
51 $data['valid'][$pageName] = $page->validate();
52
53 // Modal form and page is invalid: don't go further
54 if ($page->controller->isModal() && !$data['valid'][$pageName]) {
55 return $page->handle('display');
56 }
57
58 // the page is valid, process it before we jump to the next state
59 $page->mainProcess();
60
61 // ok so we are done now, pop stack and jump back to where we came from
62 // we do not reset the context because u can achieve that affect using next
63 // use Done when u want to pop back to the same context without a reset
64 $this->popUserContext();
65 }
66
67 }