mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°2847 - move console specific methods from BlockRenderer to ConsoleBlockRenderer
This commit is contained in:
@@ -22,7 +22,6 @@ namespace Combodo\iTop\Renderer;
|
||||
use Combodo\iTop\Application\TwigBase\Twig\TwigHelper;
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use utils;
|
||||
use WebPage;
|
||||
|
||||
/**
|
||||
* Class BlockRenderer
|
||||
@@ -72,7 +71,6 @@ class BlockRenderer
|
||||
/**
|
||||
* Helper to use directly in TWIG to render a block and its sub blocks
|
||||
*
|
||||
* @param \WebPage $oPage
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
* @param array $aContextParams
|
||||
*
|
||||
@@ -81,60 +79,14 @@ class BlockRenderer
|
||||
* @throws \Twig\Error\LoaderError
|
||||
* @throws \Twig\Error\RuntimeError
|
||||
* @throws \Twig\Error\SyntaxError
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function RenderBlockTemplate(WebPage $oPage, iUIBlock $oBlock, array $aContextParams = []): string
|
||||
public static function RenderBlockTemplates(iUIBlock $oBlock, array $aContextParams = []): string
|
||||
{
|
||||
static::RenderCssJsInPage($oPage, $oBlock, $aContextParams);
|
||||
static::RenderDeferredBlocks($oPage, $oBlock);
|
||||
|
||||
$oSelf = new static($oBlock, $aContextParams);
|
||||
|
||||
return $oSelf->RenderHtml();
|
||||
}
|
||||
|
||||
protected static function RenderDeferredBlocks(WebPage $oPage, iUIBlock $oBlock)
|
||||
{
|
||||
foreach ($oBlock->GetDeferredBlocks() as $oDeferredBlock) {
|
||||
$oPage->AddDeferredBlock($oDeferredBlock);
|
||||
}
|
||||
foreach ($oBlock->GetSubBlocks() as $oSubBlock) {
|
||||
static::RenderDeferredBlocks( $oPage, $oSubBlock);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WebPage $oPage
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
* @param array $aContextParams
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function RenderCssJsInPage(WebPage $oPage, iUIBlock $oBlock, array $aContextParams = []): void
|
||||
{
|
||||
// CSS files
|
||||
foreach ($oBlock->GetCssFilesUrlRecursively(true) as $sFileAbsUrl) {
|
||||
$oPage->add_linked_stylesheet($sFileAbsUrl);
|
||||
}
|
||||
// JS files
|
||||
foreach ($oBlock->GetJsFilesUrlRecursively(true) as $sFileAbsUrl) {
|
||||
$oPage->add_linked_script($sFileAbsUrl);
|
||||
}
|
||||
static::RenderCssJsTemplatesRecursively($oPage, $oBlock, $aContextParams);
|
||||
}
|
||||
|
||||
protected static function RenderCssJsTemplatesRecursively(WebPage $oPage, iUIBlock $oBlock, array $aContextParams = []): void
|
||||
{
|
||||
$oBlockRenderer = new static($oBlock, $aContextParams);
|
||||
$oPage->add_init_script($oBlockRenderer->RenderJsInline(iUIBlock::JS_TYPE_ON_INIT));
|
||||
$oPage->add_script($oBlockRenderer->RenderJsInline(iUIBlock::JS_TYPE_LIVE));
|
||||
$oPage->add_ready_script($oBlockRenderer->RenderJsInline(iUIBlock::JS_TYPE_ON_READY));
|
||||
$oPage->add_style($oBlockRenderer->RenderCssInline());
|
||||
|
||||
foreach ($oBlock->GetSubBlocks() as $oSubBlock) {
|
||||
static::RenderCssJsTemplatesRecursively( $oPage, $oSubBlock, $aContextParams);
|
||||
}
|
||||
}
|
||||
|
||||
/** @var \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock */
|
||||
protected $oBlock;
|
||||
/** @var array $aContextParams Optional context parameters to pass to the template during rendering */
|
||||
|
||||
Reference in New Issue
Block a user