From 2a3e6384d9464a4635b3eac6685202fa523bcc75 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 1 Feb 2022 17:45:04 +0100 Subject: [PATCH] :recycle: After dev team code review --- .../TwigBase/Controller/Controller.php | 63 +++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/sources/application/TwigBase/Controller/Controller.php b/sources/application/TwigBase/Controller/Controller.php index 0d803dfc3..c0544575f 100644 --- a/sources/application/TwigBase/Controller/Controller.php +++ b/sources/application/TwigBase/Controller/Controller.php @@ -59,6 +59,10 @@ abstract class Controller private $m_aLinkedStylesheets; private $m_aSaas; private $m_aAjaxTabs; + /** @var boolean false to disable breadcrumb */ + private $m_bIsBreadCrumbEnabled = true; + /** @var array contains same parameters as {@see iTopWebPage::SetBreadCrumbEntry()} */ + private $m_aBreadCrumbEntry = []; /** @@ -515,6 +519,23 @@ abstract class Controller $this->m_aAjaxTabs[$sCode] = array('label' => $sLabel, 'url' => $sURL, 'cache' => $bCache); } + /** + * @param bool $bIsBreadCrumbEnabled true to display the breadcrumb, false to hide it + * @since 2.7.7 3.0.1 3.1.1 method creation + * @see Controller::SetBreadCrumbEntry() to set breadcrumb content (by default will be title) + */ + public function SetIsOperationBreadCrumbEnabled($bIsBreadCrumbEnabled) { + $this->m_bIsBreadCrumbEnabled = $bIsBreadCrumbEnabled; + } + + /** + * @since 2.7.7 3.0.1 3.1.1 method creation + * @see iTopWebPage::SetBreadCrumbEntry() + */ + public function SetBreadCrumbEntry($sId, $sLabel, $sDescription, $sUrl = '', $sIcon = '') { + $this->m_aBreadCrumbEntry = [$sId, $sLabel, $sDescription, $sUrl, $sIcon]; + } + /** * @param $aParams * @param $sName @@ -557,6 +578,16 @@ abstract class Controller case 'html': $this->m_oPage = new iTopWebPage($this->GetOperationTitle()); $this->m_oPage->add_xframe_options(); + + if ($this->m_bIsBreadCrumbEnabled) { + if (count($this->m_aBreadCrumbEntry) > 0) { + @list($sId, $sTitle, $sDescription, $sUrl, $sIcon) = $this->m_aBreadCrumbEntry; + $this->m_oPage->SetBreadCrumbEntry($sId, $sTitle, $sDescription, $sUrl ?: '', $sIcon ?: ''); + } + } else { + $this->m_oPage->DisableBreadCrumb(); + } + break; case 'ajax': @@ -567,16 +598,6 @@ abstract class Controller $this->m_oPage = new SetupPage($this->GetOperationTitle()); break; } - - if ($this->IsOperationBreadCrumbEnabled()) { - $aBreadCrumbEntry = $this->GetOperationBreadCrumbEntry(); - if ((false === empty($aBreadCrumbEntry)) && (is_array($aBreadCrumbEntry)) && (count($aBreadCrumbEntry) >= 3)) { - @list($sId, $sTitle, $sDescription, $sUrl, $sIcon) = $aBreadCrumbEntry; - $this->m_oPage->SetBreadCrumbEntry($sId, $sTitle, $sDescription, $sUrl ?: '', $sIcon ?: ''); - } - } else { - $this->m_oPage->DisableBreadCrumb(); - } } /** @@ -589,28 +610,6 @@ abstract class Controller return Dict::S($this->m_sModule.'/Operation:'.$this->m_sOperation.'/Title'); } - /** - * @return bool true to display the breadcrumb, false to hide it - * @since 2.7.7 3.0.1 3.1.1 method creation - * @see Controller::GetOperationBreadCrumbEntry to set breadcrumb content (by default will be title) - */ - public function IsOperationBreadCrumbEnabled() { - return true; - } - - /** - * @see Controller::IsOperationBreadCrumbEnabled() - * @return string[] empty array, or one containing 3 to 5 items containing : - * 0. id - * 1. title - * 2. description - * 3. url - * 4. icon - */ - public function GetOperationBreadCrumbEntry() { - return []; - } - /** * @param $sContent *