mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-28 21:46:10 +02:00
# Conflicts: # .travis.yml # admin/css/ie7.css # admin/css/ie7.css.map # admin/css/ie8.css.map # admin/css/screen.css # admin/css/screen.css.map # admin/javascript/LeftAndMain.js # admin/scss/_style.scss # admin/scss/_uitheme.scss # control/HTTPRequest.php # core/Object.php # css/AssetUploadField.css # css/AssetUploadField.css.map # css/ConfirmedPasswordField.css.map # css/Form.css.map # css/GridField.css.map # css/TreeDropdownField.css.map # css/UploadField.css # css/UploadField.css.map # css/debug.css.map # dev/Debug.php # docs/en/00_Getting_Started/00_Server_Requirements.md # docs/en/02_Developer_Guides/06_Testing/00_Unit_Testing.md # docs/en/02_Developer_Guides/06_Testing/index.md # docs/en/02_Developer_Guides/14_Files/02_Images.md # docs/en/02_Developer_Guides/15_Customising_the_Admin_Interface/How_Tos/Extend_CMS_Interface.md # filesystem/File.php # filesystem/Folder.php # filesystem/GD.php # filesystem/Upload.php # forms/ToggleField.php # forms/Validator.php # javascript/lang/en_GB.js # javascript/lang/fr.js # javascript/lang/src/en.js # javascript/lang/src/fr.js # model/Image.php # model/UnsavedRelationList.php # model/Versioned.php # model/connect/MySQLDatabase.php # model/fieldtypes/DBField.php # model/fieldtypes/Enum.php # scss/AssetUploadField.scss # scss/UploadField.scss # templates/email/ChangePasswordEmail.ss # templates/forms/DropdownField.ss # tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsFormsContext.php # tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsUiContext.php # tests/forms/EnumFieldTest.php # tests/security/MemberTest.php # tests/security/MemberTest.yml # tests/security/SecurityTest.php
119 lines
2.3 KiB
PHP
119 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|HTMLText
|
|
*/
|
|
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;
|
|
}
|
|
}
|