mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-26 03:58:45 +02:00
Add UIBlocks to twig (new blocks)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\TwigBase\UI\Component;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\TwigBase\UI\UIBlockHelper;
|
||||
use Twig\Compiler;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\Node;
|
||||
|
||||
class UITitleNode extends Node
|
||||
{
|
||||
public function __construct($sType, $oParams, $lineno = 0, $tag = null)
|
||||
{
|
||||
parent::__construct([], ['type' => $sType, 'params' => $oParams], $lineno, $tag);
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler)
|
||||
{
|
||||
$sBlockVar = UIBlockHelper::GetBlockVarName('oFieldSet');
|
||||
$oParams = $this->getAttribute('params');
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("\$aParams = ")
|
||||
->subcompile($oParams)
|
||||
->raw(";\n");
|
||||
|
||||
$sType = $this->getAttribute('type');
|
||||
switch ($sType) {
|
||||
case 'ForPage':
|
||||
$compiler
|
||||
->write("\$sTitle = \$aParams['title'] ?? '';\n")
|
||||
->write("\$sId = \$aParams['id'] ?? null;\n")
|
||||
->write("\${$sBlockVar} = Combodo\\iTop\\Application\\UI\\Base\\Component\\Title\\TitleFactory::Make{$sType}(\$sTitle, \$sId);\n");
|
||||
break;
|
||||
// TODO 3.0 add other Factory methods
|
||||
|
||||
default:
|
||||
throw new SyntaxError(sprintf('%s: Bad type "%s" for %s at line %d', $this->getTemplateName(), $sType, $this->tag, $this->lineno), $this->lineno, $this->getSourceContext());
|
||||
|
||||
}
|
||||
$compiler->write(UIBlockHelper::AddToParentBlock($sBlockVar));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user