Version: current

     1 <?php
     2 /**
     3  * Implements a single tab in a {@link TabSet}.
     4  * @package forms
     5  * @subpackage fields-structural
     6  */
     7 class Tab extends CompositeField {
     8     protected $tabSet;
     9
    10     /**
    11      * @uses FormField::name_to_label()
    12      *
    13      * @param string $name Identifier of the tab, without characters like dots or spaces
    14      * @param string $title Natural language title of the tab. If its left out,
    15      *  the class uses {@link FormField::name_to_label()} to produce a title from the {@link $name} parameter.
    16      * @param FormField All following parameters are inserted as children to this tab
    17      */
    18     public function __construct($name) {
    19         $args = func_get_args();
    20
    21         $name = array_shift($args);
    22         if(!is_string($name)) user_error('TabSet::__construct(): $name parameter to a valid string', E_USER_ERROR);
    23         $this->name = $name;
    24
    25         $this->id = preg_replace('/[^0-9A-Za-z]+/', '', $name);
    26
    27         // Legacy handling: only assume second parameter as title if its a string,
    28         // otherwise it might be a formfield instance
    29         if(isset($args[0]) && is_string($args[0])) {
    30             $title = array_shift($args);
    31         }
    32         $this->title = (isset($title)) ? $title : FormField::name_to_label($name);
    33
    34         parent::__construct($args);
    35     }
    36
    37     public function id() {
    38         return $this->tabSet->id() . '_' . $this->id;
    39     }
    40
    41     public function Fields() {
    42         return $this->children;
    43     }
    44
    45     public function setTabSet($val) {
    46         $this->tabSet = $val;
    47     }
    48
    49     /**
    50      * Returns the named field
    51      */
    52     public function fieldByName($name) {
    53         foreach($this->children as $child) {
    54             if($name == $child->Name()) return $child;
    55         }
    56     }
    57 }
    58
    59 ?>

[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. -