mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 09:08:42 +02:00
N°3123 - Add variables for templates (html, js and css)
This commit is contained in:
@@ -111,12 +111,12 @@ class BlockRenderer
|
||||
public function RenderHtml()
|
||||
{
|
||||
$sOutput = '';
|
||||
if(!empty($this->oBlock::GetHtmlTemplateRelPath()))
|
||||
if(!empty($this->oBlock->GetHtmlTemplateRelPath()))
|
||||
{
|
||||
$sOutput = TwigHelper::RenderTemplate(
|
||||
static::$oTwigEnv,
|
||||
$this->GetTemplateParameters(),
|
||||
$this->oBlock::GetHtmlTemplateRelPath(),
|
||||
$this->oBlock->GetHtmlTemplateRelPath(),
|
||||
TwigHelper::ENUM_FILE_TYPE_HTML
|
||||
);
|
||||
}
|
||||
@@ -136,12 +136,12 @@ class BlockRenderer
|
||||
public function RenderJsInline()
|
||||
{
|
||||
$sOutput = '';
|
||||
if(!empty($this->oBlock::GetJsTemplateRelPath()))
|
||||
if(!empty($this->oBlock->GetJsTemplateRelPath()))
|
||||
{
|
||||
$sOutput = TwigHelper::RenderTemplate(
|
||||
static::$oTwigEnv,
|
||||
$this->GetTemplateParameters(),
|
||||
$this->oBlock::GetJsTemplateRelPath(),
|
||||
$this->oBlock->GetJsTemplateRelPath(),
|
||||
TwigHelper::ENUM_FILE_TYPE_JS
|
||||
);
|
||||
}
|
||||
@@ -161,12 +161,12 @@ class BlockRenderer
|
||||
public function RenderCssInline()
|
||||
{
|
||||
$sOutput = '';
|
||||
if(!empty($this->oBlock::GetCssTemplateRelPath()))
|
||||
if(!empty($this->oBlock->GetCssTemplateRelPath()))
|
||||
{
|
||||
$sOutput = TwigHelper::RenderTemplate(
|
||||
static::$oTwigEnv,
|
||||
$this->GetTemplateParameters(),
|
||||
$this->oBlock::GetCssTemplateRelPath(),
|
||||
$this->oBlock->GetCssTemplateRelPath(),
|
||||
TwigHelper::ENUM_FILE_TYPE_CSS
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,14 @@ abstract class UIBlock implements iUIBlock
|
||||
/** @var string $sId */
|
||||
protected $sId;
|
||||
|
||||
/** @var string */
|
||||
protected $sGlobalTemplateRelPath;
|
||||
/** @var string */
|
||||
protected $sHtmlTemplateRelPath;
|
||||
/** @var string */
|
||||
protected $sJsTemplateRelPath;
|
||||
/** @var string */
|
||||
protected $sCssTemplateRelPath;
|
||||
/** @var array */
|
||||
protected $aJsFilesRelPath;
|
||||
/** @var array */
|
||||
@@ -77,45 +85,49 @@ abstract class UIBlock implements iUIBlock
|
||||
public function __construct(?string $sId = null)
|
||||
{
|
||||
$this->sId = $sId ?? $this->GenerateId();
|
||||
$this->aJsFilesRelPath = [];
|
||||
$this->aCssFilesRelPath = [];
|
||||
$this->aJsFilesRelPath = static::JS_FILES_REL_PATH;
|
||||
$this->aCssFilesRelPath = static::CSS_FILES_REL_PATH;
|
||||
$this->sHtmlTemplateRelPath = static::HTML_TEMPLATE_REL_PATH;
|
||||
$this->sJsTemplateRelPath = static::JS_TEMPLATE_REL_PATH;
|
||||
$this->sCssTemplateRelPath = static::CSS_TEMPLATE_REL_PATH;
|
||||
$this->sGlobalTemplateRelPath = static::GLOBAL_TEMPLATE_REL_PATH;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function GetGlobalTemplateRelPath()
|
||||
public function GetGlobalTemplateRelPath()
|
||||
{
|
||||
return static::GLOBAL_TEMPLATE_REL_PATH;
|
||||
return $this->sGlobalTemplateRelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function GetHtmlTemplateRelPath() {
|
||||
return static::HTML_TEMPLATE_REL_PATH;
|
||||
public function GetHtmlTemplateRelPath() {
|
||||
return $this->sHtmlTemplateRelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function GetJsTemplateRelPath() {
|
||||
return static::JS_TEMPLATE_REL_PATH;
|
||||
public function GetJsTemplateRelPath() {
|
||||
return $this->sJsTemplateRelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetJsFilesRelPaths() {
|
||||
return array_merge(static::JS_FILES_REL_PATH, $this->aJsFilesRelPath);
|
||||
return $this->aJsFilesRelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function GetCssTemplateRelPath()
|
||||
public function GetCssTemplateRelPath()
|
||||
{
|
||||
return static::CSS_TEMPLATE_REL_PATH;
|
||||
return $this->sCssTemplateRelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +135,7 @@ abstract class UIBlock implements iUIBlock
|
||||
*/
|
||||
public function GetCssFilesRelPaths()
|
||||
{
|
||||
return array_merge(static::CSS_FILES_REL_PATH, $this->aCssFilesRelPath);
|
||||
return $this->aCssFilesRelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,21 +34,21 @@ interface iUIBlock {
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function GetGlobalTemplateRelPath();
|
||||
public function GetGlobalTemplateRelPath();
|
||||
|
||||
/**
|
||||
* Return the relative path (from <ITOP>/templates/) of the HTML template to use or null if no HTML to render
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function GetHtmlTemplateRelPath();
|
||||
public function GetHtmlTemplateRelPath();
|
||||
|
||||
/**
|
||||
* Return the relative path (from <ITOP>/templates/) of the JS template to use or null if there is no inline JS to render
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function GetJsTemplateRelPath();
|
||||
public function GetJsTemplateRelPath();
|
||||
|
||||
/**
|
||||
* Return an array of the relative paths (from <ITOP>/) of the JS files to use for the block itself
|
||||
@@ -62,7 +62,7 @@ interface iUIBlock {
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function GetCssTemplateRelPath();
|
||||
public function GetCssTemplateRelPath();
|
||||
|
||||
/**
|
||||
* Return an array of the relative paths (from <ITOP>/) of the CSS files to use for the block itself
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\UI;
|
||||
|
||||
/**
|
||||
* Trait tBlockParams
|
||||
*
|
||||
* Add generic parameters to blocks
|
||||
*
|
||||
* @package Combodo\iTop\Application\UI
|
||||
*/
|
||||
trait tBlockParams
|
||||
{
|
||||
/** @var array */
|
||||
protected $aParameters;
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function GetParameter(string $sName)
|
||||
{
|
||||
if (isset($this->aParameters[$sName])) {
|
||||
return $this->aParameters[$sName];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param $value
|
||||
*/
|
||||
public function AddParameter(string $sName, $value)
|
||||
{
|
||||
$this->aParameters[$sName] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetParameters(): array
|
||||
{
|
||||
return $this->aParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aParameters
|
||||
*/
|
||||
public function SetParameters(array $aParameters): void
|
||||
{
|
||||
$this->aParameters = $aParameters;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user