Merge pull request #16108 from civicrm/5.21
[civicrm-core.git] / CRM / Utils / Wrapper.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 * 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
20 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 */
22 class CRM_Utils_Wrapper {
23
24 /**
25 * Simple Controller.
26 *
27 * The controller which will handle the display and processing of this page.
28 * @var \CRM_Core_Controller_Simple object
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 *
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)
44 *
45 * @return mixed
46 */
47 public function run($formName, $formLabel = NULL, $arguments = NULL) {
48 if (is_array($arguments)) {
49 $mode = CRM_Utils_Array::value('mode', $arguments);
50 $imageUpload = !empty($arguments['imageUpload']);
51 $addSequence = !empty($arguments['addSequence']);
52 $attachUpload = !empty($arguments['attachUpload']);
53 $ignoreKey = !empty($arguments['ignoreKey']);
54 }
55 else {
56 $arguments = [];
57 $mode = NULL;
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) {
74 $urlVar = CRM_Utils_Array::value('urlVar', $params);
75 $sessionVar = CRM_Utils_Array::value('sessionVar', $params);
76 $type = CRM_Utils_Array::value('type', $params);
77 $default = CRM_Utils_Array::value('default', $params);
78 $abort = CRM_Utils_Array::value('abort', $params, FALSE);
79
80 $value = NULL;
81 $value = CRM_Utils_Request::retrieve(
82 $urlVar,
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 }
100
101 }