Version: current

     1 <?php
     2 /**
     3  * Allows visibility of a group of fields to be toggled using '+' and '-' icons
     4  * @package forms
     5  * @subpackage fields-structural
     6  */
     7 class ToggleCompositeField extends CompositeField {
     8
     9     /**
    10      * @var $headingLevel int
    11      */
    12     public $headingLevel = 2;
    13
    14     function __construct($name, $title, $children) {
    15         $this->name = $name;
    16         $this->title = $title;
    17
    18         $this->startClosed(true);
    19
    20         parent::__construct($children);
    21     }
    22
    23     public function FieldHolder() {
    24         Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");
    25         Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
    26         Requirements::javascript(SAPPHIRE_DIR . "/javascript/prototype_improvements.js");
    27         Requirements::javascript(SAPPHIRE_DIR . "/javascript/ToggleCompositeField.js");
    28
    29         return $this->renderWith("ToggleCompositeField");
    30     }
    31
    32     /**
    33      * Determines if the field should render open or closed by default.
    34      *
    35      * @param boolean
    36      */
    37     public function startClosed($bool) {
    38         ($bool) ? $this->addExtraClass('startClosed') : $this->removeExtraClass('startClosed');
    39     }
    40
    41     /**
    42      * @return String
    43      */
    44     public function HeadingLevel() {
    45         return $this->headingLevel;
    46     }
    47
    48     public function Type() {
    49         return ' toggleCompositeField';
    50     }
    51 }
    52
    53 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -