Version: current

     1 <?php
     2 /**
     3  * Виджет "Блок контакты"
     4  *
     5  * @package widgets
     6  * @author  menedem
     7  */
     8 class ContactsBlockWidget extends SidebarWidget {
     9     static $db = array(
    10         'FieldsList' => 'Text',
    11         'Text' => 'HTMLText',
    12     );
    13
    14     function getCMSFields() {
    15         $fields = parent::getCMSFields();
    16         $scFields = $this->SiteConfig()->getCMSFields();
    17         $contactTab = $scFields->findOrMakeTab('Root.Contacts');
    18         $contactFields = array();
    19         foreach($contactTab->Fields() as $field) {
    20             $contactFields[$field->Name()] = $field->Title();
    21         }
    22         $fields->replaceField('FieldsList', new CheckboxSetField('FieldsList', $this->fieldLabel('FieldsList'), $contactFields));
    23         return $fields;
    24     }
    25
    26     function SiteConfig() {
    27         return SiteConfig::current_site_config();
    28     }
    29
    30     function ContactsList($showLinks = false) {
    31         $list = new DataObjectSet();
    32         $enabledFields = explode(',', $this->FieldsList);
    33         foreach($enabledFields as $enabledField) {
    34             $isLink = (substr($enabledField, 0, 4) == 'Link') ? 1 : 0;
    35             if (!$showLinks && $isLink) continue;
    36             if ($showLinks && !$isLink) continue;
    37
    38             if ($enabledField && ($field = $this->SiteConfig()->getFrontendFields()->dataFieldByName($enabledField))) {
    39                 $t = new DataObject();
    40                 $t->Name = $field->Name();
    41                 $t->ContactTitle = $field->Title();
    42                 $t->Value = $this->SiteConfig()->{$enabledField};
    43                 $t->Type = WebylonSiteConfig::get_field_type($enabledField);
    44                 $list->push($t);
    45             }
    46         }
    47         return $list;
    48     }
    49
    50     function LinkList() {
    51         return $this->ContactsList(true);
    52     }
    53
    54     function isEnabled($fieldName) {
    55         return preg_match("/\b$fieldName\b/", $this->FieldsList);
    56     }
    57
    58     // есть выбранные для отображения контакты или текст в визреде
    59     function hasContent() {
    60         if (trim($this->FieldsList . $this->Text)) {
    61             return true;
    62         }
    63         return false;
    64     }
    65 }
    66
    67

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