silverstripe-framework/forms/ToggleCompositeField.php
Damian Mooyman 5c9044a007 API Enforce default_cast for all field usages
API Introduce HTMLFragment as casting helper for HTMLText with shortcodes disabled
API Introduce DBField::CDATA for XML file value encoding
API RSSFeed now casts from the underlying model rather than by override
API Introduce CustomMethods::getExtraMethodConfig() to allow metadata to be queried
BUG Remove _call hack from VirtualPage
API Remove FormField::$dontEscape
API Introduce HTMLReadonlyField for non-editable readonly HTML
API FormField::Field() now returns string in many cases rather than DBField instance.
API Remove redundant *_val methods from ViewableData
API ViewableData::obj() no longer has a $forceReturnObject parameter as it always returns an object
BUG  Fix issue with ViewableData caching incorrect field values after being modified.
API Remove deprecated DB class methods
API Enforce plain text left/right formfield titles
2016-07-13 17:15:45 +12:00

118 lines
2.3 KiB
PHP

<?php
/**
* Allows visibility of a group of fields to be toggled.
*
* @package forms
* @subpackage fields-structural
*/
class ToggleCompositeField extends CompositeField {
/**
* @var bool
*/
protected $startClosed = true;
/**
* @var int
*/
protected $headingLevel = 3;
/**
* @inheritdoc
*
* @param string $name
* @param string $title
* @param array|FieldList $children
*/
public function __construct($name, $title, $children) {
$this->name = $name;
$this->title = $title;
parent::__construct($children);
}
/**
* @inheritdoc
*
* @param array $properties
* @return string
*/
public function FieldHolder($properties = array()) {
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript(FRAMEWORK_DIR . '/client/dist/js/ToggleCompositeField.js');
Requirements::css(FRAMEWORK_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css');
$context = $this;
if(count($properties)) {
$context = $this->customise($properties);
}
return $context->renderWith($this->getTemplates());
}
/**
* @inheritdoc
*
* @return array
*/
public function getAttributes() {
$attributes = array(
'id' => $this->id(),
'class' => $this->extraClass(),
);
if($this->getStartClosed()) {
$attributes['class'] .= ' ss-toggle ss-toggle-start-closed';
} else {
$attributes['class'] .= ' ss-toggle';
}
return array_merge(
$this->attributes,
$attributes
);
}
/**
* @return bool
*/
public function getStartClosed() {
return $this->startClosed;
}
/**
* Controls whether the field is open or closed by default. By default the field is closed.
*
* @param bool $startClosed
*
* @return $this
*/
public function setStartClosed($startClosed) {
$this->startClosed = (bool) $startClosed;
return $this;
}
/**
* @return int
*/
public function getHeadingLevel() {
return $this->headingLevel;
}
/**
* @param int $headingLevel
*
* @return $this
*/
public function setHeadingLevel($headingLevel) {
$this->headingLevel = (int) $headingLevel;
return $this;
}
}