Version: current

     1 <?php
     2 /**
     3  * Defines the ContactsPage page type
     4  */
     5
     6 class ContactsPage extends MediawebPage {
     7     static $hide_ancestor = 'MediawebPage';
     8     static $db = array(
     9         'MapType' => 'DBInt',
    10         'MapBlock' => 'HTMLText',
    11         'MapDescription' => 'HTMLText',
    12         'MapAddress' => 'Varchar(255)',
    13     );
    14
    15     function getCMSFields() {
    16         $fields = parent::getCMSFields();
    17
    18         $fields->addFieldToTab("Root.Content.Main", new LabelField('MapTypeLabel', $this->fieldLabel('MapType')),'Content');
    19         // !!! локализация
    20         $mapTypesTitle = array();
    21         $mapTypesTitle[0] = _t('ContactsPage.MapDontShow', 'Dont Show');
    22         $mapTypesTitle[1] = _t('ContactsPage.MapByAddress', 'By Address');
    23         $mapTypesTitle[2] = _t('ContactsPage.MapByConstructor', 'By Constructor');
    24
    25         $types = array(
    26             "0//{$mapTypesTitle[0]}" => new LabelField('',''),
    27             "1//{$mapTypesTitle[1]}" => new TextField('MapAddress', $this->fieldLabel('MapAddress') . sprintf(' (%s)', Convert::html2raw(SiteConfig::current_site_config()->Address))),
    28             "2//{$mapTypesTitle[2]}" => $map = new TextAreaField('MapBlock', $this->fieldLabel('MapBlock')),
    29         );
    30
    31         // убираем вариант По адресу, если не указан MapApiKey
    32         if (!SiteConfig::current_site_config()->isNeedMapApiKey()) {
    33             unset($types["1//{$mapTypesTitle[1]}"]);
    34         }
    35
    36         $fields->addFieldToTab("Root.Content.Main",
    37             new SelectionGroup("MapType", $types),
    38             'Content'
    39         );
    40         $map->setRightTitle(sprintf('<a target="_blank" href="http://api.yandex.ru/maps/tools/constructor/">%s</a>', _t('ContactsPage.MapConstructorLink', 'Открыть конструктор')));
    41
    42         $fields->addFieldToTab("Root.Content.Main", new TextareaField('MapDescription', $this->fieldLabel('MapDescription')), 'Content');
    43
    44         $fields->addFieldToTab('Root.Content', new Tab("FullContent", _t('ContactsPage.tab_Content', 'Content')), 'PagePhotos');
    45         $fields->addFieldToTab("Root.Content.FullContent", $fields->dataFieldByName('Content'));
    46
    47         return $fields;
    48     }
    49
    50     function Address() {
    51         $address = SiteConfig::current_site_config()->Address;
    52         if ($this->MapAddress) {
    53             $address = $this->MapAddress;
    54         }
    55         return DBField::create('HTMLText', $address);
    56     }
    57
    58     function requireDefaultRecords() {
    59         parent::requireDefaultRecords();
    60
    61         if ($this->class != 'ContactsPage') return;
    62
    63         // default pages
    64         if($page = DataObject::get_by_id('Page', 3)) {
    65             if ($page->ClassName == 'Page') {
    66                 $page->ClassName = 'ContactsPage';
    67                 $page->URLSegment = 'contacts';
    68                 $page->populateDefaults();
    69                 $page->write();
    70                 $page->publish('Stage', 'Live');
    71                 $page->flushCache();
    72                 DB::alteration_message('Contacts page updated', 'created');
    73             }
    74         }
    75     }
    76
    77 }
    78
    79
    80 class ContactsPage_Controller extends MediawebPage_Controller {
    81 }
    82

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