Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * The Contact Wrapper is a wrapper class which is called by | |
14 | * contact.module after it parses the menu path. | |
15 | * | |
16 | * The key elements of the wrapper are the controller and the | |
17 | * run method as explained below. | |
18 | * | |
19 | * @package CRM | |
ca5cec67 | 20 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
21 | */ |
22 | class CRM_Utils_Wrapper { | |
23 | ||
24 | /** | |
fe482240 | 25 | * Simple Controller. |
6a488035 TO |
26 | * |
27 | * The controller which will handle the display and processing of this page. | |
51dda21e | 28 | * @var \CRM_Core_Controller_Simple |
6a488035 TO |
29 | */ |
30 | protected $_controller; | |
31 | ||
32 | /** | |
33 | * Run. | |
34 | * | |
35 | * The heart of the callback processing is done by this method. | |
36 | * forms are of different type and have different operations. | |
37 | * | |
6c552737 TO |
38 | * @param string $formName name of the form processing this action |
39 | * @param string $formLabel label for the above form | |
40 | * @param array $arguments | |
41 | * - int mode: mode of operation. | |
42 | * - bool addSequence: should we add a unique sequence number to the end of the key | |
43 | * - bool ignoreKey: should we not set a qfKey for this controller (for standalone forms) | |
6a488035 | 44 | * |
b8c71ffa | 45 | * @return mixed |
6001af1f | 46 | */ |
00be9182 | 47 | public function run($formName, $formLabel = NULL, $arguments = NULL) { |
6a488035 | 48 | if (is_array($arguments)) { |
9c1bc317 | 49 | $mode = $arguments['mode'] ?? NULL; |
52f3b44b CW |
50 | $imageUpload = !empty($arguments['imageUpload']); |
51 | $addSequence = !empty($arguments['addSequence']); | |
52 | $attachUpload = !empty($arguments['attachUpload']); | |
53 | $ignoreKey = !empty($arguments['ignoreKey']); | |
6a488035 TO |
54 | } |
55 | else { | |
be2fb01f | 56 | $arguments = []; |
353ffa53 | 57 | $mode = NULL; |
6a488035 TO |
58 | $addSequence = $ignoreKey = $imageUpload = $attachUpload = FALSE; |
59 | } | |
60 | ||
61 | $this->_controller = new CRM_Core_Controller_Simple( | |
62 | $formName, | |
63 | $formLabel, | |
64 | $mode, | |
65 | $imageUpload, | |
66 | $addSequence, | |
67 | $ignoreKey, | |
68 | $attachUpload | |
69 | ); | |
70 | ||
71 | if (array_key_exists('urlToSession', $arguments)) { | |
72 | if (is_array($arguments['urlToSession'])) { | |
73 | foreach ($arguments['urlToSession'] as $params) { | |
9c1bc317 CW |
74 | $urlVar = $params['urlVar'] ?? NULL; |
75 | $sessionVar = $params['sessionVar'] ?? NULL; | |
76 | $type = $params['type'] ?? NULL; | |
77 | $default = $params['default'] ?? NULL; | |
353ffa53 | 78 | $abort = CRM_Utils_Array::value('abort', $params, FALSE); |
6a488035 TO |
79 | |
80 | $value = NULL; | |
884605ca DL |
81 | $value = CRM_Utils_Request::retrieve( |
82 | $urlVar, | |
6a488035 TO |
83 | $type, |
84 | $this->_controller, | |
85 | $abort, | |
86 | $default | |
87 | ); | |
88 | $this->_controller->set($sessionVar, $value); | |
89 | } | |
90 | } | |
91 | } | |
92 | ||
93 | if (array_key_exists('setEmbedded', $arguments)) { | |
94 | $this->_controller->setEmbedded(TRUE); | |
95 | } | |
96 | ||
97 | $this->_controller->process(); | |
98 | return $this->_controller->run(); | |
99 | } | |
96025800 | 100 | |
6a488035 | 101 | } |