mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-19 00:28:47 +02:00
N°8772 - Compiler: add static inputs
This commit is contained in:
@@ -31,10 +31,16 @@ class Property extends AbstractProperty
|
||||
public function ToPHPFormBlock(&$aPHPFragments = []): string
|
||||
{
|
||||
$sFormBlockClass = $this->oValueType->GetFormBlockClass();
|
||||
|
||||
$sInputs = '';
|
||||
foreach ($this->oValueType->GetInputs() as $sInput => $sValue) {
|
||||
$sInputs .= "\n ->SetInputValue('$sInput', '$sValue')";
|
||||
}
|
||||
|
||||
return <<<PHP
|
||||
\$this->Add('$this->sId', '$sFormBlockClass', [
|
||||
'label' => '$this->sLabel',
|
||||
]);
|
||||
]){$sInputs};
|
||||
|
||||
PHP;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,11 @@ PHP;
|
||||
$aPHPFragments[] = $sLocalPHP;
|
||||
|
||||
if ($bIsRoot) {
|
||||
// $sOutputPHP = <<<PHP
|
||||
//namesapace Combodo\iTop\Forms\Block\Generated;
|
||||
//
|
||||
//PHP;
|
||||
|
||||
return implode("\n", $aPHPFragments);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
namespace Combodo\iTop\PropertyTree\ValueType;
|
||||
|
||||
use Combodo\iTop\DesignElement;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @since 3.3.0
|
||||
@@ -16,8 +17,23 @@ abstract class AbstractValueType
|
||||
{
|
||||
abstract public function GetFormBlockClass(): string;
|
||||
|
||||
protected array $aInputs = [];
|
||||
|
||||
public function InitFromDomNode(DesignElement $oDomNode): void
|
||||
{
|
||||
$sBlockNodeClass = $this->GetFormBlockClass();
|
||||
$oBlockNode = new $sBlockNodeClass('foo');
|
||||
foreach ($oBlockNode->GetInputs() as $oInput) {
|
||||
$sInputName = $oInput->GetName();
|
||||
$sInputValue = $oDomNode->GetChildText($sInputName);
|
||||
if (utils::IsNotNullOrEmptyString($sInputValue)) {
|
||||
$this->aInputs[$sInputName] = $sInputValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function GetInputs(): array
|
||||
{
|
||||
return $this->aInputs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
|
||||
namespace Combodo\iTop\PropertyTree\ValueType;
|
||||
|
||||
use Combodo\iTop\DesignElement;
|
||||
use Combodo\iTop\Forms\Block\DataModel\AttributeChoiceFormBlock;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @since 3.3.0
|
||||
|
||||
@@ -29,6 +29,12 @@ class ValueTypeFactory
|
||||
return static::$oInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\DesignElement $oDomNode
|
||||
*
|
||||
* @return \Combodo\iTop\PropertyTree\ValueType\AbstractValueType
|
||||
* @throws \Combodo\iTop\PropertyTree\PropertyTreeException
|
||||
*/
|
||||
public function CreateValueTypeFromDomNode(DesignElement $oDomNode): AbstractValueType
|
||||
{
|
||||
$sNodeType = $oDomNode->getAttribute('xsi:type');
|
||||
|
||||
@@ -268,6 +268,35 @@ PHP,
|
||||
'sMessage' => '',
|
||||
],
|
||||
|
||||
'Input static' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="input_static_test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
<node id="class_attribute_property" xsi:type="Combodo-Property">
|
||||
<label>UI:ClassAttribute</label>
|
||||
<value-type xsi:type="Combodo-ValueTypeClassAttribute">
|
||||
<class>Contact</class>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__input_static_test extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
{
|
||||
protected function BuildForm(): void
|
||||
{
|
||||
\$this->Add('class_attribute_property', 'Combodo\iTop\Forms\Block\DataModel\AttributeChoiceFormBlock', [
|
||||
'label' => 'UI:ClassAttribute',
|
||||
])
|
||||
->SetInputValue('class', 'Contact');
|
||||
}
|
||||
}
|
||||
PHP,
|
||||
'sMessage' => '',
|
||||
],
|
||||
|
||||
'test' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
Reference in New Issue
Block a user