1 <?php
2 3 4 5 6 7 8
9 class TabSet extends CompositeField {
10
11 12 13 14 15
16 public function __construct($name) {
17 $args = func_get_args();
18
19 $name = array_shift($args);
20 if(!is_string($name)) user_error('TabSet::__construct(): $name parameter to a valid string', E_USER_ERROR);
21 $this->name = $name;
22
23 $this->id = $name;
24
25
26
27 if(isset($args[0]) && is_string($args[0])) {
28 $title = array_shift($args);
29 }
30 $this->title = (isset($title)) ? $title : FormField::name_to_label($name);
31
32 if($args) foreach($args as $tab) {
33 $isValidArg = (is_object($tab) && (!($tab instanceof Tab) || !($tab instanceof TabSet)));
34 if(!$isValidArg) user_error('TabSet::__construct(): Parameter not a valid Tab instance', E_USER_ERROR);
35
36 $tab->setTabSet($this);
37 }
38
39 parent::__construct($args);
40 }
41
42 public function id() {
43 if($this->tabSet) return $this->tabSet->id() . '_' . $this->id . '_set';
44 else return $this->id;
45 }
46
47 48 49 50
51 public function FieldHolder() {
52 Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");
53 Requirements::javascript(SAPPHIRE_DIR . '/javascript/loader.js');
54 Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
55 Requirements::javascript(SAPPHIRE_DIR . "/javascript/prototype_improvements.js");
56 Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
57 Requirements::javascript(SAPPHIRE_DIR . "/javascript/jquery_improvements.js");
58 Requirements::javascript(THIRDPARTY_DIR . "/tabstrip/tabstrip.js");
59 Requirements::css(THIRDPARTY_DIR . "/tabstrip/tabstrip.css");
60
61 return $this->renderWith("TabSetFieldHolder");
62 }
63
64 65 66
67 public function Tabs() {
68 return $this->children;
69 }
70 public function setTabs($children){
71 $this->children = $children;
72 }
73
74 public function setTabSet($val) {
75 $this->tabSet = $val;
76 }
77 public function getTabSet() {
78 if(isset($this->tabSet)) return $this->tabSet;
79 }
80
81 82 83
84 public function fieldByName($name) {
85 if(strpos($name,'.') !== false) list($name, $remainder) = explode('.',$name,2);
86 else $remainder = null;
87
88 foreach($this->children as $child) {
89 if(trim($name) == trim($child->Name) || $name == $child->id) {
90 if($remainder) {
91 if($child->isComposite()) {
92 return $child->fieldByName($remainder);
93 } else {
94 user_error("Trying to get field '$remainder' from non-composite field $child->class.$name", E_USER_WARNING);
95 return null;
96 }
97 } else {
98 return $child;
99 }
100 }
101 }
102 }
103
104 105 106
107 public function push($field) {
108 parent::push($field);
109 $field->setTabSet($this);
110 }
111
112 113 114 115 116 117
118 public function insertBefore($field, $insertBefore) {
119 parent::insertBefore($field, $insertBefore);
120 if($field instanceof Tab) $field->setTabSet($this);
121 $this->sequentialSet = null;
122 }
123
124 public function insertAfter($field, $insertAfter) {
125 parent::insertAfter($field, $insertAfter);
126 if($field instanceof Tab) $field->setTabSet($this);
127 $this->sequentialSet = null;
128 }
129
130 public function removeByName( $tabName, $dataFieldOnly = false ) {
131 parent::removeByName( $tabName, $dataFieldOnly );
132 }
133 }
134 ?>
[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.
-