mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°2847 - Add page content layout feature
This commit is contained in:
@@ -24,6 +24,8 @@ require_once(APPROOT."/application/user.preferences.class.inc.php");
|
||||
use Combodo\iTop\Application\TwigBase\Twig\TwigHelper;
|
||||
use Combodo\iTop\Application\UI\iUIBlock;
|
||||
use Combodo\iTop\Application\UI\Layout\NavigationMenu\NavigationMenuFactory;
|
||||
use Combodo\iTop\Application\UI\Layout\PageContent\PageContent;
|
||||
use Combodo\iTop\Application\UI\Layout\PageContent\PageContentFactory;
|
||||
use Combodo\iTop\Application\UI\Layout\TopBar\TopBarFactory;
|
||||
use Combodo\iTop\Application\UI\UIBlock;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
@@ -40,10 +42,14 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
|
||||
/** @var string DEFAULT_BREADCRUMB_ENTRY_ICON_TYPE */
|
||||
const DEFAULT_BREADCRUMB_ENTRY_ICON_TYPE = self::ENUM_BREADCRUMB_ENTRY_ICON_TYPE_IMAGE;
|
||||
|
||||
private $m_sMenu;
|
||||
// private $m_currentOrganization;
|
||||
/** @var string DEFAULT_PAGE_TEMPLATE_REL_PATH The relative path (from <ITOP>/templates/) to the default page template */
|
||||
const DEFAULT_PAGE_TEMPLATE_REL_PATH = 'pages/backoffice/layout';
|
||||
|
||||
private $m_aMessages;
|
||||
private $m_aInitScript = array();
|
||||
protected $sTemplateRelPath;
|
||||
/** @var \Combodo\iTop\Application\UI\Layout\PageContent\PageContent $oContentLayout */
|
||||
protected $oContentLayout;
|
||||
protected $m_oTabs;
|
||||
protected $bBreadCrumbEnabled;
|
||||
protected $sBreadCrumbEntryId;
|
||||
@@ -69,6 +75,10 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
|
||||
$this->m_oTabs = new TabManager();
|
||||
$this->oCtx = new ContextTag(ContextTag::TAG_CONSOLE);
|
||||
|
||||
$this->SetTemplateRelPath(static::DEFAULT_PAGE_TEMPLATE_REL_PATH);
|
||||
// By default, content layout is empty, only manually added content will be displayed (eg. $this->add(xxx))
|
||||
$this->SetContentLayout(PageContentFactory::MakeStandardEmpty());
|
||||
|
||||
ApplicationContext::SetUrlMakerClass('iTopStandardURLMaker');
|
||||
|
||||
if ((count($_POST) == 0) || (array_key_exists('loginop', $_POST)))
|
||||
@@ -147,6 +157,31 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the template path to use for the page
|
||||
*
|
||||
* @param string $sTemplateRelPath Relative path (from <ITOP>/templates/) to the template path
|
||||
*
|
||||
* @return $this
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function SetTemplateRelPath($sTemplateRelPath)
|
||||
{
|
||||
$this->sTemplateRelPath = $sTemplateRelPath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the relative path (from <ITOP>/templates/) to the page template
|
||||
*
|
||||
* @return string
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function GetTemplateRelPath()
|
||||
{
|
||||
return $this->sTemplateRelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -811,6 +846,35 @@ JS
|
||||
return TopBarFactory::MakeStandard($this->GetBreadCrumbsNewEntry());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content layout (main content, [side content,] manually added content, ...)
|
||||
* This function is public as the developer needs to be able to set how the content will be displayed.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param \Combodo\iTop\Application\UI\Layout\PageContent\PageContent $oLayout
|
||||
*
|
||||
* @return $this
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function SetContentLayout(PageContent $oLayout)
|
||||
{
|
||||
$this->oContentLayout = $oLayout;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the content layout (main content, [side content,] manually added content, ...)
|
||||
*
|
||||
* @internal
|
||||
* @return \Combodo\iTop\Application\UI\Layout\PageContent\PageContent
|
||||
* @since 2.8.0
|
||||
*/
|
||||
protected function GetContentLayout()
|
||||
{
|
||||
return $this->oContentLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the new breadcrumbs entry or null if we don't create a new entry for the current page
|
||||
*
|
||||
@@ -1002,6 +1066,7 @@ EOF
|
||||
// TODO: Check if we can keep this as is
|
||||
// Render the tabs in the page (if any)
|
||||
$this->s_content = $this->m_oTabs->RenderIntoContent($this->s_content, $this);
|
||||
$this->GetContentLayout()->SetExtraHtmlContent(self::FilterXSS($this->s_content));
|
||||
|
||||
// Base structure of data to pass to the TWIG template
|
||||
$aData['aPage'] = [
|
||||
@@ -1031,6 +1096,8 @@ EOF
|
||||
$aData['aLayouts']['oNavigationMenu'] = $this->GetNavigationMenuLayout();
|
||||
// - Prepare top bar
|
||||
$aData['aLayouts']['oTopBar'] = $this->GetTopBarLayout();
|
||||
// - Prepare content
|
||||
$aData['aLayouts']['oPageContent'] = $this->GetContentLayout();
|
||||
// - Retrieve layouts linked files
|
||||
// Note: Adding them now instead of in the template allow us to remove duplicates and lower the browser parsing time
|
||||
/** @var \Combodo\iTop\Application\UI\UIBlock|string $oLayout */
|
||||
@@ -1073,7 +1140,6 @@ EOF
|
||||
);
|
||||
|
||||
$oTwigEnv = TwigHelper::GetTwigEnvironment(APPROOT.'templates/');
|
||||
$sTemplateRelPath = 'pages/backoffice/layout';
|
||||
|
||||
// Send headers
|
||||
if ($this->GetOutputFormat() === 'html')
|
||||
@@ -1086,7 +1152,7 @@ EOF
|
||||
|
||||
// Render final TWIG into global HTML
|
||||
$oKpi = new ExecutionKPI();
|
||||
$sHtml = TwigHelper::RenderTemplate($oTwigEnv, $aData, $sTemplateRelPath);
|
||||
$sHtml = TwigHelper::RenderTemplate($oTwigEnv, $aData, $this->GetTemplateRelPath());
|
||||
$oKpi->ComputeAndReport('TWIG rendering');
|
||||
|
||||
// Echo global HTML
|
||||
|
||||
Reference in New Issue
Block a user