diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index b02887af7..fd96f8ee0 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -943,6 +943,7 @@ EOF $val['attcode'] = $sAttCode; $val['atttype'] = $sAttDefClass; $val['attlabel'] = $sAttLabel; + $val['attflags'] = ($bEditMode) ? $this->GetFormAttributeFlags($sAttCode) : OPT_ATT_READONLY; // - How the field should be rendered $val['layout'] = (in_array($oAttDef->GetEditClass(), static::GetAttEditClassesToRenderAsLargeField())) ? 'large' : 'small'; diff --git a/application/webpage.class.inc.php b/application/webpage.class.inc.php index c99659448..387a1d12c 100644 --- a/application/webpage.class.inc.php +++ b/application/webpage.class.inc.php @@ -528,16 +528,37 @@ class WebPage implements Page */ public function GetDetails($aFields) { + $aPossibleAttFlags = MetaModel::EnumPossibleAttributeFlags(); + $sHtml = "
\n"; foreach ($aFields as $aAttrib) { $sLayout = isset($aAttrib['layout']) ? $aAttrib['layout'] : 'small'; + + // Prepare metadata attributes $sDataAttributeCode = isset($aAttrib['attcode']) ? 'data-attribute-code="'.$aAttrib['attcode'].'"' : ''; $sDataAttributeType = isset($aAttrib['atttype']) ? 'data-attribute-type="'.$aAttrib['atttype'].'"' : ''; $sDataAttributeLabel = isset($aAttrib['attlabel']) ? 'data-attribute-label="'.utils::HtmlEntities($aAttrib['attlabel']).'"' : ''; + // - Attribute flags + $sDataAttributeFlags = ''; + if(isset($aAttrib['attflags'])) + { + foreach($aPossibleAttFlags as $sFlagCode => $iFlagValue) + { + // Note: Skip normal flag as we don't need it. + if($sFlagCode === 'normal') + { + continue; + } + $sFormattedFlagCode = str_ireplace('_', '-', $sFlagCode); + $sFormattedFlagValue = (($aAttrib['attflags'] & $iFlagValue) === $iFlagValue) ? 'true' : 'false'; + $sDataAttributeFlags .= 'data-attribute-flag-'.$sFormattedFlagCode.'="'.$sFormattedFlagValue.'" '; + } + } + // - Value raw $sDataValueRaw = isset($aAttrib['value_raw']) ? 'data-value-raw="'.utils::HtmlEntities($aAttrib['value_raw']).'"' : ''; - $sHtml .= "
\n"; + $sHtml .= "
\n"; $sHtml .= "
{$aAttrib['label']}
\n"; $sHtml .= "
\n"; diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index f6175611f..f35d58336 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -1033,6 +1033,20 @@ abstract class AttributeDefinition $oFormField->AddMetadata('attribute-code', $this->GetCode()); $oFormField->AddMetadata('attribute-type', get_class($this)); $oFormField->AddMetadata('attribute-label', utils::HtmlEntities($this->GetLabel())); + // - Attribute flags + $aPossibleAttFlags = MetaModel::EnumPossibleAttributeFlags(); + foreach($aPossibleAttFlags as $sFlagCode => $iFlagValue) + { + // Note: Skip normal flag as we don't need it. + if($sFlagCode === 'normal') + { + continue; + } + $sFormattedFlagCode = str_ireplace('_', '-', $sFlagCode); + $sFormattedFlagValue = (($iFlags & $iFlagValue) === $iFlagValue) ? 'true' : 'false'; + $oFormField->AddMetadata('attribute-flag-'.$sFormattedFlagCode, $sFormattedFlagValue); + } + // - Value raw if ($this::IsScalar()) { $oFormField->AddMetadata('value-raw', utils::HtmlEntities($oObject->Get($this->GetCode()))); diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 230d4df06..af0a52dee 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -2509,6 +2509,32 @@ abstract class MetaModel return array(); } + /** + * Return an hash array of the possible attribute flags (code => value) + * + * Example: + * [ + * "read_only" => OPT_ATT_READONLY, + * "mandatory" => OPT_ATT_MANDATORY, + * ... + * ] + * + * @return array + * @since 2.7.0 + */ + public static function EnumPossibleAttributeFlags() + { + return $aPossibleAttFlags = array( + 'normal' => OPT_ATT_NORMAL, + 'hidden' => OPT_ATT_HIDDEN, + 'read_only' => OPT_ATT_READONLY, + 'mandatory' => OPT_ATT_MANDATORY, + 'must_change' => OPT_ATT_MUSTCHANGE, + 'must_prompt' => OPT_ATT_MUSTPROMPT, + 'slave' => OPT_ATT_SLAVE + ); + } + /** * @param string $sClass * @param string $sState diff --git a/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php b/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php index 2c9282414..486166d92 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php @@ -944,6 +944,12 @@ class ObjectFormManager extends FormManager $oField->SetDisplayMode($aFieldsExtraData[$sAttCode]['display_mode']); } + // Overload (AttributeDefinition) flags metadata as they have been changed while building the form + $oField->AddMetadata('attribute-flag-hidden', $oField->GetHidden() ? 'true' : 'false'); + $oField->AddMetadata('attribute-flag-read-only', $oField->GetReadOnly() ? 'true' : 'false'); + $oField->AddMetadata('attribute-flag-mandatory', $oField->GetMandatory() ? 'true' : 'false'); + $oField->AddMetadata('attribute-flag-must-change', $oField->GetMustChange() ? 'true' : 'false'); + // Do not add hidden fields as they are of no use, if one is necessary because another depends on it, it will be automatically added. // Note: We do this at the end because during the process an hidden field could have become writable if mandatory and empty for example. if($oField->GetHidden() === false)