diff --git a/sources/Renderer/Console/FieldRenderer/ConsoleSimpleFieldRenderer.php b/sources/Renderer/Console/FieldRenderer/ConsoleSimpleFieldRenderer.php index 9e696e1f0..9d8cbabe8 100644 --- a/sources/Renderer/Console/FieldRenderer/ConsoleSimpleFieldRenderer.php +++ b/sources/Renderer/Console/FieldRenderer/ConsoleSimpleFieldRenderer.php @@ -59,8 +59,43 @@ class ConsoleSimpleFieldRenderer extends FieldRenderer else { $oBlock = FieldUIBlockFactory::MakeStandard($this->oField->GetLabel()); - $oBlock->AddDataAttribute("input-id",$this->oField->GetGlobalId()); - $oBlock->AddDataAttribute("input-type",$sFieldClass); + $oBlock->SetAttLabel($this->oField->GetLabel()) + ->AddDataAttribute("input-id",$this->oField->GetGlobalId()) + ->AddDataAttribute("input-type",$sFieldClass); + + // Propagate data attribute from Field to UIBlock + // Note: This might no longer be necessary after the upcoming attributes rework project + foreach ($this->oField->GetMetadata() as $sMetadataKey => $sMetadataValue) { + switch ($sMetadataKey) { + // Important: Only some data attributes can be overloaded, this is done on purpose (eg. "input-type" set previously by an AttributeCustomFields) + case 'attribute-code': + case 'attribute-type': + case 'input-type': + if (utils::IsNotNullOrEmptyString($sMetadataValue)) { + switch ($sMetadataKey) { + case 'attribute-code': + $oBlock->SetAttCode($sMetadataValue); + break; + + case 'attribute-type': + $oBlock->SetAttType($sMetadataValue ?? ''); + break; + + case 'input-type': + $oBlock->AddDataAttribute($sMetadataKey, $sMetadataValue ?? ''); + break; + } + } + break; + + default: + if (false === $oBlock->HasDataAttribute($sMetadataKey)) { + $oBlock->AddDataAttribute($sMetadataKey, $sMetadataValue ?? ''); + } + break; + } + } + switch ($sFieldClass) { case 'Combodo\\iTop\\Form\\Field\\DateTimeField': diff --git a/sources/application/UI/Base/UIBlock.php b/sources/application/UI/Base/UIBlock.php index f0a770184..e40780fd3 100644 --- a/sources/application/UI/Base/UIBlock.php +++ b/sources/application/UI/Base/UIBlock.php @@ -599,6 +599,18 @@ abstract class UIBlock implements iUIBlock return $this; } + /** + * @param string $sName Name of the data attribute + * + * @return bool True if $sName is already defined (even as a null value) in the UIBLock data attributes, false otherwise + * @see static::$aDataAttributes + * @since 3.0.4 3.1.0 N°6140 + */ + public function HasDataAttribute(string $sName): bool + { + return array_key_exists($sName, $this->aDataAttributes); + } + /** * @return bool * @see static::$aDataAttributes