diff --git a/datamodels/2.x/itop-portal-base/portal/src/Brick/AbstractBrick.php b/datamodels/2.x/itop-portal-base/portal/src/Brick/AbstractBrick.php index 599429ece7..798cc8accc 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Brick/AbstractBrick.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Brick/AbstractBrick.php @@ -659,4 +659,28 @@ public function LoadFromXml(DesignElement $oMDElement) return $this; } + /** + * Load brick configuration that is not part of the brick definition but is part of the portal global properties. + * + * @param $aPortalProperties + * + * @return void + * @since 3.2.1 + */ + public function LoadFromPortalProperties($aPortalProperties) { + // Get the bricks templates + $aBricksTemplates = $aPortalProperties['templates']['bricks']; + $sClassFQDN = get_class($this); + + // Get the current brick templates + $aCurrentBricksTemplates = array_key_exists($sClassFQDN, $aBricksTemplates) ? $aBricksTemplates[$sClassFQDN] : []; + foreach($aCurrentBricksTemplates as $sTemplateKey => $sTemplate) { + // Clean the template id + $sTemplateId = str_ireplace($sClassFQDN.':', '', $sTemplateKey); + + // Call the set method for the template + $sSetTemplateMethodName = 'Set'.$sTemplateId.'TemplatePath'; + $this->{$sSetTemplateMethodName}($sTemplate); + } + } } diff --git a/datamodels/2.x/itop-portal-base/portal/src/Brick/BrickCollection.php b/datamodels/2.x/itop-portal-base/portal/src/Brick/BrickCollection.php index 167b4fc110..8dd29fc583 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Brick/BrickCollection.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Brick/BrickCollection.php @@ -21,6 +21,7 @@ use DOMFormatException; use Exception; +use Symfony\Component\DependencyInjection\ContainerInterface; use UserRights; use ModuleDesign; use Combodo\iTop\Portal\Helper\ApplicationHelper; @@ -47,15 +48,21 @@ class BrickCollection private $aHomeOrdering; /** @var array $aNavigationMenuOrdering */ private $aNavigationMenuOrdering; + /** @var \Symfony\Component\DependencyInjection\ContainerInterface $container + * @since 3.2.1 + */ + private $container; /** * BrickCollection constructor. * * @param \ModuleDesign $oModuleDesign + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * * @throws \Exception + * @since 3.2.1 Added $container parameter */ - public function __construct(ModuleDesign $oModuleDesign) + public function __construct(ModuleDesign $oModuleDesign, ContainerInterface $container) { $this->oModuleDesign = $oModuleDesign; $this->aAllowedBricks = null; @@ -63,6 +70,7 @@ public function __construct(ModuleDesign $oModuleDesign) $this->iDisplayedInNavigationMenu = 0; $this->aHomeOrdering = array(); $this->aNavigationMenuOrdering = array(); + $this->container = $container; $this->Load(); } @@ -196,6 +204,12 @@ private function GetRawBrickList() { /** @var \Combodo\iTop\Portal\Brick\PortalBrick $oBrick */ $oBrick = new $sBrickClass(); + + // Load the portal properties that are common to all bricks of this type + $oPortalConf = $this->container->getParameter('combodo.portal.instance.conf'); + $oBrick->LoadFromPortalProperties($oPortalConf['properties']); + + // Load the brick specific properties from its XML definition $oBrick->LoadFromXml($oBrickNode); $aBricks[] = $oBrick; diff --git a/datamodels/2.x/itop-portal-base/portal/src/DependencyInjection/SilexCompatBootstrap/PortalXmlConfiguration/Basic.php b/datamodels/2.x/itop-portal-base/portal/src/DependencyInjection/SilexCompatBootstrap/PortalXmlConfiguration/Basic.php index d9f870eb76..4a96b8f2bc 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/DependencyInjection/SilexCompatBootstrap/PortalXmlConfiguration/Basic.php +++ b/datamodels/2.x/itop-portal-base/portal/src/DependencyInjection/SilexCompatBootstrap/PortalXmlConfiguration/Basic.php @@ -85,6 +85,7 @@ private function GetInitialPortalConf() 'templates' => array( 'layout' => 'itop-portal-base/portal/templates/layout.html.twig', 'home' => 'itop-portal-base/portal/templates/home/layout.html.twig', + 'bricks' => array(), ), 'urlmaker_class' => null, 'triggers_query' => null, @@ -185,6 +186,14 @@ private function ParseTemplateAndTheme(array $aPortalConf, DesignElement $oPrope $aPortalConf['properties']['templates'][$sNodeId] = $oSubNode->GetText(null); break; default: + // Try to accept the value as a global brick template + $sXsiType = $oSubNode->getAttribute('xsi:type'); + if (utils::IsNotNullOrEmptyString($sXsiType)) + { + $aPortalConf['properties']['templates']['bricks'][$sXsiType][$sNodeId] = $oSubNode->GetText(null); + break; + } + throw new DOMFormatException( 'Value "'.$sNodeId.'" is not handled for template[@id]', null, null, $oSubNode