Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N°7995 - Allow to redefine portal twig template for all bricks in a portal #686

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions datamodels/2.x/itop-portal-base/portal/src/Brick/AbstractBrick.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,4 +659,36 @@ 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) {
steffunky marked this conversation as resolved.
Show resolved Hide resolved
// 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';

if(method_exists($this, $sSetTemplateMethodName)) {
$this->{$sSetTemplateMethodName}($sTemplate);
}
else {
throw new DOMFormatException(
'Template "'.$sTemplateId.'" is not a valid template for brick ' . $sClassFQDN,
null, null);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use DOMFormatException;
use Exception;
use Symfony\Component\DependencyInjection\ContainerInterface;
use UserRights;
use ModuleDesign;
use Combodo\iTop\Portal\Helper\ApplicationHelper;
Expand All @@ -47,22 +48,29 @@ class BrickCollection
private $aHomeOrdering;
/** @var array $aNavigationMenuOrdering */
private $aNavigationMenuOrdering;
/** @var \array $aCombodoPortalInstanceConf
* @since 3.2.1
*/
private $aCombodoPortalInstanceConf;

/**
* BrickCollection constructor.
*
* @param \ModuleDesign $oModuleDesign
* @param $aCombodoPortalInstanceConf
*
* @throws \Exception
* @since 3.2.1 Added $aCombodoPortalInstanceConf parameter
*/
public function __construct(ModuleDesign $oModuleDesign)
public function __construct(ModuleDesign $oModuleDesign, $aCombodoPortalInstanceConf)
{
$this->oModuleDesign = $oModuleDesign;
$this->aAllowedBricks = null;
$this->iDisplayedInHome = 0;
$this->iDisplayedInNavigationMenu = 0;
$this->aHomeOrdering = array();
$this->aNavigationMenuOrdering = array();
$this->aCombodoPortalInstanceConf = $aCombodoPortalInstanceConf;

$this->Load();
}
Expand Down Expand Up @@ -196,6 +204,11 @@ 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
$oBrick->LoadFromPortalProperties($this->aCombodoPortalInstanceConf['properties']);

// Load the brick specific properties from its XML definition
$oBrick->LoadFromXml($oBrickNode);

$aBricks[] = $oBrick;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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');
steffunky marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down