labelMore = _t('ToggleField.MORE', 'more'); $this->labelLess = _t('ToggleField.LESS', 'less'); $this->startClosed(true); parent::__construct($name, $title, $value); } /** * @inheritdoc * * @param array $properties * * @return string|HTMLText */ public function Field($properties = array()) { Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(FRAMEWORK_DIR . '/javascript/ToggleField.js'); if($this->startClosed) { $this->addExtraClass('startClosed'); } $valueForInput = ''; if($this->value) { $valueForInput = Convert::raw2att($this->value); } $rawInput = Convert::html2raw($valueForInput); if($this->charNum) { $reducedValue = substr($rawInput, 0, $this->charNum); } else { $reducedValue = DBField::create_field('Text', $rawInput)->{$this->truncateMethod}(); } // only create toggle field if the truncated content is shorter if(strlen($reducedValue) < strlen($rawInput)) { $content = << $reducedValue  $this->labelMore
$this->value  $this->labelLess

HTML; } else { $this->dontEscape = true; $content = parent::Field(); } return $content; } /** * Determines if the field should render open or closed by default. * * @param bool $bool */ public function startClosed($bool) { if($bool) { $this->addExtraClass('startClosed'); } else { $this->removeExtraClass('startClosed'); } } /** * @inheritdoc * * @return string */ public function Type() { return "toggleField"; } }