3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Helper class to build navigation links.
21 class CRM_Contribute_Form_ContributionPage_TabHeader
{
24 * @param CRM_Core_Form $form
28 public static function build(&$form) {
29 $tabs = $form->get('tabHeader');
30 if (!$tabs ||
empty($_GET['reset'])) {
31 $tabs = self
::process($form);
32 $form->set('tabHeader', $tabs);
34 $form->assign_by_ref('tabHeader', $tabs);
35 CRM_Core_Resources
::singleton()
36 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
39 'active' => self
::getCurrentTab($tabs),
46 * @param CRM_Core_Form $form
50 public static function process(&$form) {
51 if ($form->getVar('_id') <= 0) {
69 'title' => ts('Title'),
72 'title' => ts('Amounts'),
75 'title' => ts('Memberships'),
78 'title' => ts('Receipt'),
81 'title' => ts('Tell a Friend'),
84 'title' => ts('Profiles'),
87 'title' => ts('Premiums'),
90 'title' => ts('Widgets'),
93 'title' => ts('Personal Campaigns'),
97 $contribPageId = $form->getVar('_id');
98 // Call tabset hook to add/remove custom tabs
99 CRM_Utils_Hook
::tabset('civicrm/admin/contribute', $tabs, ['contribution_page_id' => $contribPageId]);
100 $fullName = $form->getVar('_name');
101 $className = CRM_Utils_String
::getClassName($fullName);
103 // Hack for special cases.
104 switch ($className) {
106 $attributes = $form->getVar('_attributes');
107 $class = CRM_Utils_Request
::retrieveComponent($attributes);
110 case 'MembershipBlock':
111 $class = 'membership';
115 $class = strtolower($className);
119 if (array_key_exists($class, $tabs)) {
120 $tabs[$class]['current'] = TRUE;
121 $qfKey = $form->get('qfKey');
123 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
127 if ($contribPageId) {
128 $reset = !empty($_GET['reset']) ?
'reset=1&' : '';
130 foreach ($tabs as $key => $value) {
131 if (!isset($tabs[$key]['qfKey'])) {
132 $tabs[$key]['qfKey'] = NULL;
135 $tabs[$key]['link'] = CRM_Utils_System
::url(
136 "civicrm/admin/contribute/{$key}",
137 "{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}"
139 $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
141 //get all section info.
142 $contriPageInfo = CRM_Contribute_BAO_ContributionPage
::getSectionInfo([$contribPageId]);
144 foreach ($contriPageInfo[$contribPageId] as $section => $info) {
146 $tabs[$section]['valid'] = FALSE;
156 public static function reset(&$form) {
157 $tabs = self
::process($form);
158 $form->set('tabHeader', $tabs);
166 public static function getCurrentTab($tabs) {
167 static $current = FALSE;
173 if (is_array($tabs)) {
174 foreach ($tabs as $subPage => $pageVal) {
175 if ($pageVal['current'] === TRUE) {
182 $current = $current ?
$current : 'settings';