namespace Combodo\iTop\Form\Field; use Closure; use DBObject; use InlineImage; use AttributeText; /** * Description of TextAreaField * * @author Guillaume Lajarige * @package \Combodo\iTop\Form\Field * @since 2.3.0 */ class TextAreaField extends TextField { /** @var string */ const ENUM_FORMAT_TEXT = 'text'; /** @var string */ const ENUM_FORMAT_HTML = 'html'; /** @var string */ const DEFAULT_FORMAT = 'html'; /** @var string */ protected $sFormat; protected $oObject; /** @var string|null */ protected $sTransactionId; /** * TextAreaField constructor. * * @param string $sId * @param \Closure|null $onFinalizeCallback * @param \DBObject|null $oObject */ public function __construct(string $sId, Closure $onFinalizeCallback = null, DBObject $oObject = null) { parent::__construct($sId, $onFinalizeCallback); $this->sFormat = static::DEFAULT_FORMAT; $this->oObject = $oObject; $this->sTransactionId = null; } /** * * @return string */ public function GetFormat() { return $this->sFormat; } /** * * @param string $sFormat * @return \Combodo\iTop\Form\Field\TextAreaField */ public function SetFormat(string $sFormat) { $this->sFormat = $sFormat; return $this; } /** * * @return DBObject */ public function GetObject() { return $this->oObject; } /** * * @param DBObject $oObject * @return \Combodo\iTop\Form\Field\TextAreaField */ public function SetObject(DBObject $oObject) { $this->oObject = $oObject; return $this; } /** * Returns the transaction id for the field. This is usally used/setted when using a html format that allows upload of files/images * * @return string */ public function GetTransactionId() { return $this->sTransactionId; } /** * * @param string $sTransactionId * @return \Combodo\iTop\Form\Field\TextAreaField */ public function SetTransactionId(string $sTransactionId) { $this->sTransactionId = $sTransactionId; return $this; } public function GetDisplayValue() { if ($this->GetFormat() == TextAreaField::ENUM_FORMAT_TEXT) { $sValue = \Str::pure2html($this->GetCurrentValue()); $sValue = AttributeText::RenderWikiHtml($sValue); return "
".str_replace("\n", "
\n", $sValue).'
'; } else { $sValue = AttributeText::RenderWikiHtml($this->GetCurrentValue(), true /* wiki only */); return "
".InlineImage::FixUrls($sValue).'
'; } } }