mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-30 14:08:46 +02:00
Add UIBlocks to twig (WIP)
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?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\Node\Node;
|
||||
|
||||
class UIFieldSetNode extends Node
|
||||
{
|
||||
public function __construct($oParams, $oBody, $lineno = 0, $tag = null)
|
||||
{
|
||||
parent::__construct(['body' => $oBody], ['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")
|
||||
->write("\$sLegend = \$aParams['legend'] ?? '';\n")
|
||||
->write("\$sName = \$aParams['value'] ?? null;\n")
|
||||
->write("\${$sBlockVar} = new Combodo\\iTop\\Application\\UI\\Base\\Component\\FieldSet\\FieldSet(\$sLegend, \$sName);\n")
|
||||
->write(UIBlockHelper::AddToParentBlock($sBlockVar))
|
||||
->write(UIBlockHelper::PushParentBlock($sBlockVar))
|
||||
->subcompile($this->getNode('body'))
|
||||
->write(UIBlockHelper::PopParentBlock());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
|
||||
namespace Combodo\iTop\Application\TwigBase\UI\Component;
|
||||
|
||||
|
||||
use Twig\Token;
|
||||
use Twig\TokenParser\AbstractTokenParser;
|
||||
|
||||
class UIFieldSetParser extends AbstractTokenParser
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$iLineno = $token->getLine();
|
||||
$oStream = $this->parser->getStream();
|
||||
|
||||
$oParams = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
$oStream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$oBody = $this->parser->subparse([$this, 'decideForEnd'], true);
|
||||
$oStream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new UIFieldSetNode($oParams, $oBody, $iLineno, $this->getTag());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
return 'UIFieldSet';
|
||||
}
|
||||
|
||||
public function decideForEnd(Token $token)
|
||||
{
|
||||
return $token->test('EndUIFieldSet');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user