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 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
07f8d162 | 19 | * Helper class to build navigation links. |
6a488035 TO |
20 | */ |
21 | class CRM_Contribute_Form_ContributionPage_TabHeader { | |
1330f57a | 22 | |
186c9c17 | 23 | /** |
c490a46a | 24 | * @param CRM_Core_Form $form |
186c9c17 EM |
25 | * |
26 | * @return array | |
27 | */ | |
00be9182 | 28 | public static function build(&$form) { |
6a488035 | 29 | $tabs = $form->get('tabHeader'); |
8cc574cf | 30 | if (!$tabs || empty($_GET['reset'])) { |
6a488035 TO |
31 | $tabs = self::process($form); |
32 | $form->set('tabHeader', $tabs); | |
33 | } | |
34 | $form->assign_by_ref('tabHeader', $tabs); | |
4165b7e5 | 35 | CRM_Core_Resources::singleton() |
96ed17aa | 36 | ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header') |
be2fb01f CW |
37 | ->addSetting([ |
38 | 'tabSettings' => [ | |
353ffa53 | 39 | 'active' => self::getCurrentTab($tabs), |
be2fb01f CW |
40 | ], |
41 | ]); | |
6a488035 TO |
42 | return $tabs; |
43 | } | |
44 | ||
186c9c17 | 45 | /** |
c490a46a | 46 | * @param CRM_Core_Form $form |
186c9c17 | 47 | * |
3fd42bb5 | 48 | * @return array|null |
186c9c17 | 49 | */ |
00be9182 | 50 | public static function process(&$form) { |
6a488035 TO |
51 | if ($form->getVar('_id') <= 0) { |
52 | return NULL; | |
53 | } | |
54 | ||
a8b477f6 MWMC |
55 | $default = [ |
56 | 'link' => NULL, | |
57 | 'valid' => FALSE, | |
58 | 'active' => FALSE, | |
59 | 'current' => FALSE, | |
cb60aa31 EM |
60 | 'class' => FALSE, |
61 | 'extra' => FALSE, | |
62 | 'template' => FALSE, | |
63 | 'count' => FALSE, | |
64 | 'icon' => FALSE, | |
a8b477f6 MWMC |
65 | ]; |
66 | ||
be2fb01f CW |
67 | $tabs = [ |
68 | 'settings' => [ | |
353ffa53 | 69 | 'title' => ts('Title'), |
a8b477f6 | 70 | ] + $default, |
be2fb01f | 71 | 'amount' => [ |
353ffa53 | 72 | 'title' => ts('Amounts'), |
a8b477f6 | 73 | ] + $default, |
be2fb01f | 74 | 'membership' => [ |
353ffa53 | 75 | 'title' => ts('Memberships'), |
a8b477f6 | 76 | ] + $default, |
be2fb01f | 77 | 'thankyou' => [ |
353ffa53 | 78 | 'title' => ts('Receipt'), |
a8b477f6 | 79 | ] + $default, |
be2fb01f | 80 | 'friend' => [ |
353ffa53 | 81 | 'title' => ts('Tell a Friend'), |
a8b477f6 | 82 | ] + $default, |
be2fb01f | 83 | 'custom' => [ |
353ffa53 | 84 | 'title' => ts('Profiles'), |
a8b477f6 | 85 | ] + $default, |
be2fb01f | 86 | 'premium' => [ |
353ffa53 | 87 | 'title' => ts('Premiums'), |
a8b477f6 | 88 | ] + $default, |
be2fb01f | 89 | 'widget' => [ |
353ffa53 | 90 | 'title' => ts('Widgets'), |
a8b477f6 | 91 | ] + $default, |
be2fb01f | 92 | 'pcp' => [ |
353ffa53 | 93 | 'title' => ts('Personal Campaigns'), |
a8b477f6 | 94 | ] + $default, |
be2fb01f | 95 | ]; |
6a488035 TO |
96 | |
97 | $contribPageId = $form->getVar('_id'); | |
a8b477f6 | 98 | // Call tabset hook to add/remove custom tabs |
be2fb01f | 99 | CRM_Utils_Hook::tabset('civicrm/admin/contribute', $tabs, ['contribution_page_id' => $contribPageId]); |
353ffa53 TO |
100 | $fullName = $form->getVar('_name'); |
101 | $className = CRM_Utils_String::getClassName($fullName); | |
6a488035 TO |
102 | |
103 | // Hack for special cases. | |
104 | switch ($className) { | |
105 | case 'Contribute': | |
106 | $attributes = $form->getVar('_attributes'); | |
b90552b7 | 107 | $class = CRM_Utils_Request::retrieveComponent($attributes); |
6a488035 TO |
108 | break; |
109 | ||
110 | case 'MembershipBlock': | |
111 | $class = 'membership'; | |
112 | break; | |
113 | ||
114 | default: | |
115 | $class = strtolower($className); | |
116 | break; | |
117 | } | |
118 | ||
119 | if (array_key_exists($class, $tabs)) { | |
120 | $tabs[$class]['current'] = TRUE; | |
121 | $qfKey = $form->get('qfKey'); | |
122 | if ($qfKey) { | |
123 | $tabs[$class]['qfKey'] = "&qfKey={$qfKey}"; | |
124 | } | |
125 | } | |
126 | ||
127 | if ($contribPageId) { | |
0d8afee2 | 128 | $reset = !empty($_GET['reset']) ? 'reset=1&' : ''; |
6a488035 TO |
129 | |
130 | foreach ($tabs as $key => $value) { | |
131 | if (!isset($tabs[$key]['qfKey'])) { | |
132 | $tabs[$key]['qfKey'] = NULL; | |
133 | } | |
134 | ||
389bcebf | 135 | $tabs[$key]['link'] = CRM_Utils_System::url( |
6a488035 | 136 | "civicrm/admin/contribute/{$key}", |
353ffa53 TO |
137 | "{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}" |
138 | ); | |
6a488035 TO |
139 | $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE; |
140 | } | |
141 | //get all section info. | |
be2fb01f | 142 | $contriPageInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo([$contribPageId]); |
6a488035 TO |
143 | |
144 | foreach ($contriPageInfo[$contribPageId] as $section => $info) { | |
145 | if (!$info) { | |
146 | $tabs[$section]['valid'] = FALSE; | |
147 | } | |
148 | } | |
149 | } | |
150 | return $tabs; | |
151 | } | |
152 | ||
186c9c17 EM |
153 | /** |
154 | * @param $form | |
155 | */ | |
00be9182 | 156 | public static function reset(&$form) { |
6a488035 TO |
157 | $tabs = self::process($form); |
158 | $form->set('tabHeader', $tabs); | |
159 | } | |
160 | ||
186c9c17 EM |
161 | /** |
162 | * @param $tabs | |
163 | * | |
164 | * @return int|string | |
165 | */ | |
00be9182 | 166 | public static function getCurrentTab($tabs) { |
6a488035 TO |
167 | static $current = FALSE; |
168 | ||
169 | if ($current) { | |
170 | return $current; | |
171 | } | |
172 | ||
173 | if (is_array($tabs)) { | |
174 | foreach ($tabs as $subPage => $pageVal) { | |
175 | if ($pageVal['current'] === TRUE) { | |
176 | $current = $subPage; | |
177 | break; | |
178 | } | |
179 | } | |
180 | } | |
181 | ||
182 | $current = $current ? $current : 'settings'; | |
183 | return $current; | |
184 | } | |
96025800 | 185 | |
6a488035 | 186 | } |