mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
validator component
This commit is contained in:
@@ -7,18 +7,23 @@
|
||||
|
||||
namespace Combodo\iTop\Forms\Block\DataModel;
|
||||
|
||||
use Combodo\iTop\Forms\Block\FormBlockException;
|
||||
use Combodo\iTop\Forms\Register\RegisterException;
|
||||
use Combodo\iTop\Service\DependencyInjection\DIException;
|
||||
use Combodo\iTop\Service\DependencyInjection\DIService;
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
|
||||
use Combodo\iTop\Forms\IO\Format\AttributeIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\ClassIOFormat;
|
||||
use Combodo\iTop\Forms\Register\IORegister;
|
||||
use Combodo\iTop\Forms\Register\OptionsRegister;
|
||||
use ModelReflection;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Form block for choice of class attributes.
|
||||
* A block to choose an attribute from a given class.
|
||||
*
|
||||
* @package DataModel
|
||||
* @package Combodo\iTop\Forms\Block\DataModel
|
||||
* @since 3.3.0
|
||||
*/
|
||||
class AttributeChoiceFormBlock extends ChoiceFormBlock
|
||||
{
|
||||
@@ -44,33 +49,33 @@ class AttributeChoiceFormBlock extends ChoiceFormBlock
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Combodo\iTop\Forms\Register\OptionsRegister $oOptionsRegister
|
||||
* @inheritdoc
|
||||
*
|
||||
* @throws \Combodo\iTop\Service\DependencyInjection\DIException
|
||||
* @throws \Combodo\iTop\Forms\Block\FormBlockException
|
||||
* @throws \Combodo\iTop\Forms\Register\RegisterException
|
||||
* @throws DIException
|
||||
* @throws FormBlockException
|
||||
* @throws RegisterException
|
||||
*/
|
||||
public function UpdateOptions(OptionsRegister $oOptionsRegister): void
|
||||
{
|
||||
parent::UpdateOptions($oOptionsRegister);
|
||||
|
||||
// Get class name
|
||||
$sClass = strval($this->GetInputValue(self::INPUT_CLASS_NAME));
|
||||
|
||||
// Empty class => no choices
|
||||
if (utils::IsNullOrEmptyString($sClass)) {
|
||||
$oOptionsRegister->SetOption('choices', []);
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var \ModelReflection $oModelReflection */
|
||||
/** List attributes @var ModelReflection $oModelReflection */
|
||||
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
|
||||
$aAttributeCodes = array_keys($oModelReflection->ListAttributes($sClass));
|
||||
|
||||
$aAttributes = [];
|
||||
foreach ($aAttributeCodes as $sAttCode) {
|
||||
$sLabel = $oModelReflection->GetLabel($sClass, $sAttCode);
|
||||
$aAttributes[$sLabel] = $sAttCode;
|
||||
}
|
||||
|
||||
$oOptionsRegister->SetOption('choices', $aAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user