diff --git a/core/attributedef/AttributeURL.php b/core/attributedef/AttributeURL.php new file mode 100644 index 000000000..89dc55c67 --- /dev/null +++ b/core/attributedef/AttributeURL.php @@ -0,0 +1,110 @@ +GetSQLColSpec() : ''); + } + + public function GetMaxSize() + { + return 2048; + } + + public function GetEditClass() + { + return "String"; + } + + public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true) + { + $sTarget = $this->Get("target"); + if (empty($sTarget)) { + $sTarget = "_blank"; + } + $sLabel = Str::pure2html($sValue); + if (strlen($sLabel) > 128) { + // Truncate the length to 128 characters, by removing the middle + $sLabel = substr($sLabel, 0, 100) . '.....' . substr($sLabel, -20); + } + + return "$sLabel"; + } + + public function GetValidationPattern() + { + return $this->GetOptional('validation_pattern', '^' . utils::GetConfig()->Get('url_validation_pattern') . '$'); + } + + public static function GetFormFieldClass() + { + return '\\Combodo\\iTop\\Form\\Field\\UrlField'; + } + + /** + * @param \DBObject $oObject + * @param \Combodo\iTop\Form\Field\UrlField $oFormField + * + * @return null + * @throws \CoreException + */ + public function MakeFormField(DBObject $oObject, $oFormField = null) + { + if ($oFormField === null) { + $sFormFieldClass = static::GetFormFieldClass(); + $oFormField = new $sFormFieldClass($this->GetCode()); + } + parent::MakeFormField($oObject, $oFormField); + + $oFormField->SetTarget($this->Get('target')); + + return $oFormField; + } + + protected function GetChangeRecordClassName(): string + { + return CMDBChangeOpSetAttributeURL::class; + } +} \ No newline at end of file