From c1bd837577c475c5476d60cdc272920649a5f117 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Thu, 16 Aug 2018 17:41:54 +0100 Subject: [PATCH] Extract selectedChild tabheader functionality and enable for Manage Events --- CRM/Admin/Page/MessageTemplates.php | 15 +++------------ CRM/Contact/Page/View/Summary.php | 2 +- CRM/Core/Page/Basic.php | 3 +++ CRM/Event/Form/ManageEvent/Repeat.php | 2 +- CRM/Event/Form/ManageEvent/TabHeader.php | 5 ++++- CRM/UF/Page/Group.php | 6 +----- templates/CRM/Admin/Page/Extensions.tpl | 15 +-------------- templates/CRM/Admin/Page/MessageTemplates.tpl | 11 +---------- templates/CRM/Contribute/Page/Tab.tpl | 12 +----------- templates/CRM/Event/Form/ManageEvent/Tab.tpl | 1 + templates/CRM/UF/Page/Group.tpl | 13 ++----------- templates/CRM/common/TabSelected.tpl | 12 ++++++++++++ 12 files changed, 31 insertions(+), 66 deletions(-) create mode 100644 templates/CRM/common/TabSelected.tpl diff --git a/CRM/Admin/Page/MessageTemplates.php b/CRM/Admin/Page/MessageTemplates.php index 1fdc8dc65a50..be658e66bedf 100644 --- a/CRM/Admin/Page/MessageTemplates.php +++ b/CRM/Admin/Page/MessageTemplates.php @@ -187,22 +187,13 @@ public function action(&$object, $action, &$values, &$links, $permission, $force * @throws Exception */ public function run($args = NULL, $pageArgs = NULL, $sort = NULL) { + $id = $this->getIdAndAction(); // handle the revert action and offload the rest to parent - if (CRM_Utils_Request::retrieve('action', 'String', $this) & CRM_Core_Action::REVERT) { - - $id = CRM_Utils_Request::retrieve('id', 'Positive', $this); - if (!$this->checkPermission($id, NULL)) { - CRM_Core_Error::fatal(ts('You do not have permission to revert this template.')); - } - + if ($this->_action & CRM_Core_Action::REVERT) { $this->_revertedId = $id; - CRM_Core_BAO_MessageTemplate::revert($id); } - $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this); - if (in_array($selectedChild, array('user', 'workflow'))) { - $this->assign('selectedChild', $selectedChild); - } + return parent::run($args, $pageArgs, $sort); } diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index d41da69d8f86..9f1611285f0c 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -122,7 +122,7 @@ public function view() { ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header') ->addSetting(array( 'summaryPrint' => array('mode' => $this->_print), - 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary')), + 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, 'summary')), )); $this->assign('summaryPrint', $this->_print); $session = CRM_Core_Session::singleton(); diff --git a/CRM/Core/Page/Basic.php b/CRM/Core/Page/Basic.php index fe3f1652cb98..48af5ebf531b 100644 --- a/CRM/Core/Page/Basic.php +++ b/CRM/Core/Page/Basic.php @@ -171,11 +171,14 @@ public function run() { * * @return int * The ID if present, or 0. + * @throws \CRM_Core_Exception */ public function getIdAndAction() { $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); $this->assign('action', $this->_action); + $this->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this)); + // get 'id' if present $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); diff --git a/CRM/Event/Form/ManageEvent/Repeat.php b/CRM/Event/Form/ManageEvent/Repeat.php index 495522b2a2aa..abd824acf89a 100644 --- a/CRM/Event/Form/ManageEvent/Repeat.php +++ b/CRM/Event/Form/ManageEvent/Repeat.php @@ -110,7 +110,7 @@ public function postProcess() { unset($params['id']); $url = 'civicrm/event/manage/repeat'; - $urlParams = "action=update&reset=1&id={$this->_id}"; + $urlParams = "action=update&reset=1&id={$this->_id}&selectedChild=repeat"; $linkedEntities = array( array( diff --git a/CRM/Event/Form/ManageEvent/TabHeader.php b/CRM/Event/Form/ManageEvent/TabHeader.php index b2d3b03649a3..e4a19a77e458 100644 --- a/CRM/Event/Form/ManageEvent/TabHeader.php +++ b/CRM/Event/Form/ManageEvent/TabHeader.php @@ -42,8 +42,11 @@ class CRM_Event_Form_ManageEvent_TabHeader { * @param CRM_Event_Form_ManageEvent $form * * @return array + * @throws \CRM_Core_Exception */ public static function build(&$form) { + $form->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $form)); + $tabs = $form->get('tabHeader'); if (!$tabs || empty($_GET['reset'])) { $tabs = self::process($form); @@ -235,7 +238,7 @@ public static function getCurrentTab($tabs) { if (is_array($tabs)) { foreach ($tabs as $subPage => $pageVal) { - if ($pageVal['current'] === TRUE) { + if (CRM_Utils_Array::value('current', $pageVal) === TRUE) { $current = $subPage; break; } diff --git a/CRM/UF/Page/Group.php b/CRM/UF/Page/Group.php index c87feb2e6da3..0d372bcad74a 100644 --- a/CRM/UF/Page/Group.php +++ b/CRM/UF/Page/Group.php @@ -145,10 +145,6 @@ public static function &actionLinks() { * This method is called after the page is created. It checks for the * type of action and executes that action. * Finally it calls the parent's run method. - * - * @param - * - * @return void */ public function run() { // get the requested action @@ -160,7 +156,7 @@ public function run() { // assign vars to templates $this->assign('action', $action); - $this->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'String', $this)); + $this->assign('selectedChild', CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this)); $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0 ); diff --git a/templates/CRM/Admin/Page/Extensions.tpl b/templates/CRM/Admin/Page/Extensions.tpl index fbfcd84894c7..c50ce1b60174 100644 --- a/templates/CRM/Admin/Page/Extensions.tpl +++ b/templates/CRM/Admin/Page/Extensions.tpl @@ -101,20 +101,7 @@ {/literal} - {* Tab management *} - + {include file="CRM/common/TabSelected.tpl" defaultTab="summary"} {* Refresh buttons *} {literal} diff --git a/templates/CRM/Admin/Page/MessageTemplates.tpl b/templates/CRM/Admin/Page/MessageTemplates.tpl index c8e41a24e4dd..6ab271be3987 100644 --- a/templates/CRM/Admin/Page/MessageTemplates.tpl +++ b/templates/CRM/Admin/Page/MessageTemplates.tpl @@ -173,16 +173,7 @@ {/foreach} - +{include file="CRM/common/TabSelected.tpl" defaultTab="user"} {elseif $action ne 1 and $action ne 2 and $action ne 4 and $action ne 8}
diff --git a/templates/CRM/Contribute/Page/Tab.tpl b/templates/CRM/Contribute/Page/Tab.tpl index 4f989cdf6e6d..0d955cb65c55 100644 --- a/templates/CRM/Contribute/Page/Tab.tpl +++ b/templates/CRM/Contribute/Page/Tab.tpl @@ -31,18 +31,8 @@ {* reserved profile*} -
{* maincontainer*} - + +{include file="CRM/common/TabSelected.tpl" defaultTab="user-profiles"} {else} {if $action ne 1} {* When we are adding an item, we should not display this message *} diff --git a/templates/CRM/common/TabSelected.tpl b/templates/CRM/common/TabSelected.tpl new file mode 100644 index 000000000000..2b32581b8528 --- /dev/null +++ b/templates/CRM/common/TabSelected.tpl @@ -0,0 +1,12 @@ +