Skip to content

Commit afd96a0

Browse files
committed
N°7995 - Allow to redefine portal twig template for all bricks in a portal (#686)
* N°7995 - Allow to redefine portal twig template for all bricks in a portal * Apply modifications from code review * Fix variable name * Apply changes from code review
1 parent a77765e commit afd96a0

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

datamodels/2.x/itop-portal-base/portal/src/Brick/AbstractBrick.php

+34
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,38 @@ public function LoadFromXml(DesignElement $oMDElement)
659659
return $this;
660660
}
661661

662+
/**
663+
* Load brick configuration that is not part of the brick definition but is part of the portal global properties.
664+
*
665+
* @param $aPortalProperties
666+
*
667+
* @return void
668+
* @throws \DOMFormatException
669+
* @since 3.2.1
670+
*/
671+
public function LoadFromPortalProperties($aPortalProperties)
672+
{
673+
// Get the bricks templates
674+
$aBricksTemplates = $aPortalProperties['templates']['bricks'];
675+
$sClassFQCN = get_class($this);
676+
677+
// Get the current brick templates
678+
$aCurrentBricksTemplates = array_key_exists($sClassFQCN, $aBricksTemplates) ? $aBricksTemplates[$sClassFQCN] : [];
679+
foreach($aCurrentBricksTemplates as $sTemplateKey => $sTemplate) {
680+
// Clean the template id
681+
$sTemplateId = str_ireplace($sClassFQCN.':', '', $sTemplateKey);
682+
683+
// Call the set method for the template
684+
$sSetTemplateMethodName = 'Set'.$sTemplateId.'TemplatePath';
685+
686+
if(method_exists($this, $sSetTemplateMethodName)) {
687+
$this->{$sSetTemplateMethodName}($sTemplate);
688+
}
689+
else {
690+
throw new DOMFormatException(
691+
'Template "'.$sTemplateId.'" is not a valid template for brick ' . $sClassFQCN,
692+
null, null);
693+
}
694+
}
695+
}
662696
}

datamodels/2.x/itop-portal-base/portal/src/Brick/BrickCollection.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
use DOMFormatException;
2323
use Exception;
24+
use Symfony\Component\DependencyInjection\ContainerInterface;
2425
use UserRights;
2526
use ModuleDesign;
2627
use Combodo\iTop\Portal\Helper\ApplicationHelper;
@@ -47,22 +48,29 @@ class BrickCollection
4748
private $aHomeOrdering;
4849
/** @var array $aNavigationMenuOrdering */
4950
private $aNavigationMenuOrdering;
51+
/** @var \array $aCombodoPortalInstanceConf
52+
* @since 3.2.1
53+
*/
54+
private $aCombodoPortalInstanceConf;
5055

5156
/**
5257
* BrickCollection constructor.
5358
*
5459
* @param \ModuleDesign $oModuleDesign
60+
* @param $aCombodoPortalInstanceConf
5561
*
5662
* @throws \Exception
63+
* @since 3.2.1 Added $aCombodoPortalInstanceConf parameter
5764
*/
58-
public function __construct(ModuleDesign $oModuleDesign)
65+
public function __construct(ModuleDesign $oModuleDesign, $aCombodoPortalInstanceConf)
5966
{
6067
$this->oModuleDesign = $oModuleDesign;
6168
$this->aAllowedBricks = null;
6269
$this->iDisplayedInHome = 0;
6370
$this->iDisplayedInNavigationMenu = 0;
6471
$this->aHomeOrdering = array();
6572
$this->aNavigationMenuOrdering = array();
73+
$this->aCombodoPortalInstanceConf = $aCombodoPortalInstanceConf;
6674

6775
$this->Load();
6876
}
@@ -196,6 +204,11 @@ private function GetRawBrickList()
196204
{
197205
/** @var \Combodo\iTop\Portal\Brick\PortalBrick $oBrick */
198206
$oBrick = new $sBrickClass();
207+
208+
// Load the portal properties that are common to all bricks of this type
209+
$oBrick->LoadFromPortalProperties($this->aCombodoPortalInstanceConf['properties']);
210+
211+
// Load the brick specific properties from its XML definition
199212
$oBrick->LoadFromXml($oBrickNode);
200213

201214
$aBricks[] = $oBrick;

datamodels/2.x/itop-portal-base/portal/src/DependencyInjection/SilexCompatBootstrap/PortalXmlConfiguration/Basic.php

+9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ private function GetInitialPortalConf()
8585
'templates' => array(
8686
'layout' => 'itop-portal-base/portal/templates/layout.html.twig',
8787
'home' => 'itop-portal-base/portal/templates/home/layout.html.twig',
88+
'bricks' => array(),
8889
),
8990
'urlmaker_class' => null,
9091
'triggers_query' => null,
@@ -185,6 +186,14 @@ private function ParseTemplateAndTheme(array $aPortalConf, DesignElement $oPrope
185186
$aPortalConf['properties']['templates'][$sNodeId] = $oSubNode->GetText(null);
186187
break;
187188
default:
189+
// Try to accept the value as a global brick template, brick id format is "FQCN:page"
190+
[$sBrickFQCN, $sPage] = explode(':', $sNodeId);
191+
if (utils::IsNotNullOrEmptyString($sBrickFQCN) && utils::IsNotNullOrEmptyString($sPage))
192+
{
193+
$aPortalConf['properties']['templates']['bricks'][$sBrickFQCN][$sPage] = $oSubNode->GetText(null);
194+
break;
195+
}
196+
188197
throw new DOMFormatException(
189198
'Value "'.$sNodeId.'" is not handled for template[@id]',
190199
null, null, $oSubNode

0 commit comments

Comments
 (0)