1 <?php
2
3 4 5 6 7 8
9 class HomepageWidget extends WebylonWidget {
10
11 static $db = array(
12 'BackgroundColor' => 'Varchar'
13 );
14
15 static $has_one = array(
16 'BackgroundImage' => 'Image'
17 );
18
19 20 21 22
23 static $background_colors = array();
24
25 26 27 28 29 30
31 static function set_background_colors($colors = array()) {
32 if (!is_array($colors)) $colors = array($colors);
33 self::$background_colors = $colors;
34 }
35
36 function getCMSFields() {
37 $fields = parent::getCMSFields();
38 $tab = $fields->findOrMakeTab('Root.Background', _t('HomepageWidget.tab_Background'));
39 if (count(self::$background_colors) == 0) {
40 $fields->removeByName('BackgroundColor');
41 } elseif (count(self::$background_colors) == 1) {
42 $fields->replaceField('BackgroundColor', new HiddenField('BackgroundColor', '', self::$background_colors[0]));
43 } else {
44 $tab->push(new DropdownField('BackgroundColor', $this->fieldLabel('BackgroundColor'), WebylonWidget::get_array_localization('HomepageWidget', 'BackgroundColor', self::$background_colors)));
45 }
46 $bgField = $fields->dataFieldByName('BackgroundImage');
47 $bgField->AutoresizeMaxWidth = WebylonWidget::$max_image_width;
48 $bgField->AutoresizeMaxHeight = WebylonWidget::$max_image_heigth;
49 $tab->push($bgField);
50 return $fields;
51 }
52
53 function populateDefaults() {
54 parent::populateDefaults();
55 if (count(self::$background_colors)) {
56 $this->BackgroundColor = self::$background_colors[0];
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.
-