3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * Helper class to build navigation links.
37 class CRM_Contribute_Form_ContributionPage_TabHeader
{
40 * @param CRM_Core_Form $form
44 public static function build(&$form) {
45 $tabs = $form->get('tabHeader');
46 if (!$tabs ||
empty($_GET['reset'])) {
47 $tabs = self
::process($form);
48 $form->set('tabHeader', $tabs);
50 $form->assign_by_ref('tabHeader', $tabs);
51 CRM_Core_Resources
::singleton()
52 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
55 'active' => self
::getCurrentTab($tabs),
62 * @param CRM_Core_Form $form
66 public static function process(&$form) {
67 if ($form->getVar('_id') <= 0) {
80 'title' => ts('Title'),
83 'title' => ts('Amounts'),
86 'title' => ts('Memberships'),
89 'title' => ts('Receipt'),
92 'title' => ts('Tell a Friend'),
95 'title' => ts('Profiles'),
98 'title' => ts('Premiums'),
101 'title' => ts('Widgets'),
104 'title' => ts('Personal Campaigns'),
108 $contribPageId = $form->getVar('_id');
109 // Call tabset hook to add/remove custom tabs
110 CRM_Utils_Hook
::tabset('civicrm/admin/contribute', $tabs, ['contribution_page_id' => $contribPageId]);
111 $fullName = $form->getVar('_name');
112 $className = CRM_Utils_String
::getClassName($fullName);
114 // Hack for special cases.
115 switch ($className) {
117 $attributes = $form->getVar('_attributes');
118 $class = CRM_Utils_Request
::retrieveComponent($attributes);
121 case 'MembershipBlock':
122 $class = 'membership';
126 $class = strtolower($className);
130 if (array_key_exists($class, $tabs)) {
131 $tabs[$class]['current'] = TRUE;
132 $qfKey = $form->get('qfKey');
134 $tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
138 if ($contribPageId) {
139 $reset = !empty($_GET['reset']) ?
'reset=1&' : '';
141 foreach ($tabs as $key => $value) {
142 if (!isset($tabs[$key]['qfKey'])) {
143 $tabs[$key]['qfKey'] = NULL;
146 $tabs[$key]['link'] = CRM_Utils_System
::url(
147 "civicrm/admin/contribute/{$key}",
148 "{$reset}action=update&id={$contribPageId}{$tabs[$key]['qfKey']}"
150 $tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
152 //get all section info.
153 $contriPageInfo = CRM_Contribute_BAO_ContributionPage
::getSectionInfo([$contribPageId]);
155 foreach ($contriPageInfo[$contribPageId] as $section => $info) {
157 $tabs[$section]['valid'] = FALSE;
167 public static function reset(&$form) {
168 $tabs = self
::process($form);
169 $form->set('tabHeader', $tabs);
177 public static function getCurrentTab($tabs) {
178 static $current = FALSE;
184 if (is_array($tabs)) {
185 foreach ($tabs as $subPage => $pageVal) {
186 if ($pageVal['current'] === TRUE) {
193 $current = $current ?
$current : 'settings';