1 <?php
2
3 4 5 6 7
8 class SiteConfigDecorator extends DataObjectDecorator {
9
10 11 12 13
14 static $hidden_fields = array();
15
16 17 18 19
20 static $unhidden_fields = array();
21
22 23 24 25 26
27 static function hide_config_fields($fields) {
28 if (!is_array($fields)) {
29 $fields = explode(',', $fields);
30 }
31 foreach($fields as $field) {
32 $field = trim($field);
33 unset(self::$unhidden_fields[$field]);
34 self::$hidden_fields[$field] = $field;
35 }
36 }
37
38 39 40 41 42
43 static function show_config_fields($fields) {
44 if (!is_array($fields)) {
45 $fields = explode(',', $fields);
46 }
47 foreach($fields as $field) {
48 $field = trim($field);
49 unset(self::$hidden_fields[$field]);
50 self::$unhidden_fields[$field] = $field;
51 }
52 }
53
54 55 56 57 58 59 60 61 62 63
64 static function get_config_tab(& $fields, $name = false, $title = false, $subTitle = false) {
65 $tab = $fields->findOrMakeTab('Root.Main', _t('SiteConfig.tab_Main', 'Website configuration'));
66
67 if ($name) {
68 @list($tabName, $subName) = explode('.', $name, 2);
69
70 $tab = $fields->fieldByName('Root.' . $tabName);
71 if (!$tab) {
72 if (!$title)
73 $title = _t('SiteConfig.tab_' . $tabName, $tabName);
74
75 $tab = ($subName) ? new TabSet($tabName, $title) : new Tab($tabName, $title);
76 $fields->insertBefore($tab, 'Access');
77 }
78
79 if ($subName) {
80 $parent = $tab;
81 $tab = $parent->fieldByName($subName);
82 if (!$tab) {
83 if (!$subTitle)
84 $subTitle = _t('SiteConfig.tab_' . $tabName . '_' . $subName, $subName);
85
86 $tab = new Tab($subName, $subTitle);
87 $parent->push($tab);
88 }
89 }
90 }
91 return $tab;
92 }
93
94 95 96 97 98
99 function hideUnselectedFields(&$fields) {
100
101 $hidden_fields = SS_Object::combined_static($this->class, 'hidden_fields');
102
103 if (!is_array($hidden_fields)) return;
104
105 $hidden_fields = array_diff(array_unique($hidden_fields), self::$unhidden_fields);
106
107 foreach($hidden_fields as $hidden_field) {
108 if ($hidden_field)
109 $fields->removeByName($hidden_field, true);
110 }
111 }
112
113 }
114
115
[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.
-