aAttributes[$sAttributeCode] = $aOptions; return $this; } /** * Get attribute data. * * @throws \CoreException * @throws \ArchivedObjectException */ protected function GetAttributeData(string $sAttributeCode) : mixed { return $this->oDBObject->Get($sAttributeCode); } /** * Get attribute form type options. * * @param \AttributeDefinition $oAttributeDefinition * * @return array */ private function GetAttributeOptions(AttributeDefinition $oAttributeDefinition) : array { $aOptions = []; if($oAttributeDefinition instanceof AttributeString) { $aOptions['required'] = !$oAttributeDefinition->IsNullAllowed(); } return $aOptions; } /** * Get attribute description. * * @param string $sAttributeCode * * @return \Combodo\iTop\FormSDK\Field\Description\FormFieldDescription|null * @throws \Exception */ private function GetAttributeDescription(string $sAttributeCode) : ?FormFieldDescription { $oAttributeDefinition = MetaModel::GetAttributeDef(get_class($this->oDBObject), $sAttributeCode); if($oAttributeDefinition instanceof AttributeString) { return new FormFieldDescription( $this->GetAttributePath($sAttributeCode), FormFieldTypeEnumeration::TEXT, array_merge( $this->GetAttributeOptions($oAttributeDefinition), $this->aAttributes[$sAttributeCode]) ); } return null; } /** * Return attribute path. * * @param string $sAttributeCode * * @return string */ private function GetAttributePath(string $sAttributeCode) : string { return $this->bGroup ? $sAttributeCode : $this->GetIdentifier() . '-' . $sAttributeCode; // return $this->GetIdentifier() . '-' . $sAttributeCode; } /** @inheritdoc */ public function GetFormData() : array { $aData = []; foreach ($this->aAttributes as $sAttributeCode => $oValue){ try { $aData[$this->GetAttributePath($sAttributeCode)] = $this->GetAttributeData($sAttributeCode); } catch (Exception $e) { $aData[$this->GetAttributePath($sAttributeCode)] = null; ExceptionLog::LogException($e); } } if($this->bGroup){ return [ $this->GetIdentifier() => $aData ]; } else{ return $aData; } } /** @inheritdoc */ public function GetFormDescriptions() : array { $aDescriptions = []; foreach ($this->aAttributes as $sKey => $oValue){ try { $aDescriptions[$this->GetIdentifier() .'_' .$sKey] = $this->GetAttributeDescription($sKey); } catch (Exception $e) { ExceptionLog::LogException($e); } } if($this->bGroup){ $oGroupDescriptions = new FormFieldDescription($this->GetIdentifier(), FormFieldTypeEnumeration::DB_OBJECT, [ 'descriptions' => $aDescriptions ]); return [$oGroupDescriptions]; } else{ return $aDescriptions; } } /** @inheritdoc */ public function GetIdentifier(): string { return get_class($this->oDBObject) . '_' . $this->oDBObject->GetKey(); } }