mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-28 13:08:45 +02:00
N°2847 - move console specific methods from BlockRenderer to ConsoleBlockRenderer
This commit is contained in:
84
sources/Renderer/Console/ConsoleBlockRenderer.php
Normal file
84
sources/Renderer/Console/ConsoleBlockRenderer.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Renderer\Console;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\iUIBlock;
|
||||
use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use WebPage;
|
||||
|
||||
class ConsoleBlockRenderer extends 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
|
||||
*
|
||||
* @return string
|
||||
* @throws \ReflectionException
|
||||
* @throws \Twig\Error\LoaderError
|
||||
* @throws \Twig\Error\RuntimeError
|
||||
* @throws \Twig\Error\SyntaxError
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function RenderBlockTemplateInPage(WebPage $oPage, iUIBlock $oBlock, array $aContextParams = []): string
|
||||
{
|
||||
static::AddCssJsToPage($oPage, $oBlock, $aContextParams);
|
||||
static::AddDeferredBlocksToPage($oPage, $oBlock);
|
||||
|
||||
$oSelf = new static($oBlock, $aContextParams);
|
||||
return $oSelf->RenderHtml();
|
||||
}
|
||||
|
||||
protected static function AddDeferredBlocksToPage(WebPage $oPage, iUIBlock $oBlock)
|
||||
{
|
||||
foreach ($oBlock->GetDeferredBlocks() as $oDeferredBlock) {
|
||||
$oPage->AddDeferredBlock($oDeferredBlock);
|
||||
}
|
||||
foreach ($oBlock->GetSubBlocks() as $oSubBlock) {
|
||||
static::AddDeferredBlocksToPage( $oPage, $oSubBlock);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WebPage $oPage
|
||||
* @param \Combodo\iTop\Application\UI\Base\iUIBlock $oBlock
|
||||
* @param array $aContextParams
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function AddCssJsToPage(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::AddCssJsTemplatesToPageRecursively($oPage, $oBlock, $aContextParams);
|
||||
}
|
||||
|
||||
protected static function AddCssJsTemplatesToPageRecursively(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::AddCssJsTemplatesToPageRecursively( $oPage, $oSubBlock, $aContextParams);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user