mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°8772 - Form dependencies manager implementation
- Form SDK implementation - Basic Forms - Dynamics Forms - Basic Blocks + Data Model Block - Form Compilation - Turbo integration
This commit is contained in:
43
sources/Forms/IO/Converter/ChoiceValueToLabelConverter.php
Normal file
43
sources/Forms/IO/Converter/ChoiceValueToLabelConverter.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Forms\IO\Converter;
|
||||
|
||||
use Combodo\iTop\Forms\Block\Base\ChoiceFormBlock;
|
||||
use Combodo\iTop\Forms\IO\Format\AttributeIOFormat;
|
||||
use Combodo\iTop\Forms\IO\Format\StringIOFormat;
|
||||
|
||||
/**
|
||||
* Convert a choice value to its label.
|
||||
*
|
||||
* @package Combodo\iTop\Forms\IO\Converter
|
||||
* @since 3.3.0
|
||||
*/
|
||||
class ChoiceValueToLabelConverter extends AbstractConverter
|
||||
{
|
||||
private ChoiceFormBlock $oChoiceBlock;
|
||||
|
||||
public function __construct(ChoiceFormBlock $oChoiceBlock)
|
||||
{
|
||||
$this->oChoiceBlock = $oChoiceBlock;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function Convert(mixed $oData): ?StringIOFormat
|
||||
{
|
||||
if (is_null($oData) || is_array($oData)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$aOptions = array_flip($this->oChoiceBlock->GetOption('choices'));
|
||||
if (!array_key_exists($oData, $aOptions) || is_null($aOptions[$oData])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new StringIOFormat($aOptions[$oData]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user