Version: current

     1 <?php
     2
     3 /**
     4  * Виджеты для главной страницы
     5  *
     6  * @package  widgets
     7  * @author  menedem
     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      * @param array $colors
    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. -