Version: current

      1 <?php
      2
      3 /**
      4  * Defines the HomePage page type
      5  */
      6 class HomePage extends Page {
      7
      8     static $icon = 'webylon/img/home';
      9     static $db = array(
     10         'NewsOnPage' => 'DBInt',
     11         'Address' => 'HTMLText',
     12         'Counters' => 'HTMLText',
     13     );
     14     static $can_create = false;
     15     static $defaults = array(
     16         'NewsOnPage' => 5,
     17         'DevEditType' => 'Fixed',
     18         'AutoChild' => 0,
     19     );
     20
     21     static $show_content = false;
     22
     23     static function set_show_content($val = true) {
     24         self::$show_content = $val;
     25     }
     26
     27     static $show_mobile_content = false;
     28
     29     static function set_show_mobile_content($val = true) {
     30         self::$show_mobile_content = $val;
     31     }
     32
     33     function getCMSFields() {
     34         $fields = parent::getCMSFields();
     35         if (!Director::isDev()) { // Если в в режиме разаработки
     36             $fields->removeByName('AutoChild');
     37         }
     38         //$fields->removeByName('ClassName');
     39         $fields->removeByName('ParentType');
     40         $fields->removeByName('ParentID');
     41         $fields->removeByName('NumberCMSChildren');
     42         $fields->removeByName('NewsOnPage');
     43
     44         if (!self::$show_content && ClassInfo::exists('WebylonWidget'))
     45             $fields->replaceField('Content', new HeaderField('Content', _t('HomePage.NoContent', 'Go to widgets section.'), 3, true));
     46
     47         if (!self::$show_mobile_content && ClassInfo::exists('WebylonWidget'))
     48             $fields->replaceField('MobileContent', new HeaderField('MobileContent', _t('HomePage.NoContent', 'Go to widgets section.'), 3, true));
     49
     50         return $fields;
     51     }
     52
     53     function canCreate($member = false) {
     54         return Director::isDev() && parent::canCreate($member);
     55     }
     56
     57     function canDelete($member= false) {
     58         return $this->canCreate($member);
     59     }
     60
     61     function requireDefaultRecords() {
     62         parent::requireDefaultRecords();
     63
     64         if ($this->class != 'HomePage') return;
     65
     66         // default pages
     67         if($homepage = SiteTree::get_by_link('home')) {
     68             if ($homepage->ClassName == 'Page') {
     69                 $homepage->ClassName = 'HomePage';
     70                 $homepage->populateDefaults();
     71                 if (class_exists('WebylonWidget'))
     72                     $homepage->Content = '';
     73                 $homepage->write();
     74                 $homepage->publish('Stage', 'Live');
     75                 $homepage->flushCache();
     76                 DB::alteration_message('Home page class changed to HomePage', 'updated');
     77             }
     78         }
     79         else {
     80             $homepage = new HomePage();
     81             $homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home');
     82             if (!class_exists('WebylonWidget'))
     83                 $homepage->Content = _t('SiteTree.DEFAULTHOMECONTENT', '<p>Welcome to SilverStripe! This is the default homepage. You can edit this page by opening <a href="admin/">the CMS</a>. You can now access the <a href="http://doc.silverstripe.org">developer documentation</a>, or begin <a href="http://doc.silverstripe.org/doku.php?id=tutorials">the tutorials.</a></p>');
     84             $homepage->URLSegment = 'home';
     85             $homepage->Status = 'Published';
     86             $homepage->Sort = 1;
     87             $homepage->write();
     88             $homepage->publish('Stage', 'Live');
     89             $homepage->flushCache();
     90             DB::alteration_message('Home page created', 'created');
     91         }
     92     }
     93
     94     function onBeforeWrite() {
     95         parent::onBeforeWrite();
     96         $this->DevEditType = 'Fixed';
     97 //      $this->URLSegment = 'home';
     98     }
     99
    100     function ShowContent() {
    101         return self::$show_content;
    102     }
    103
    104     function ShowMobileContent() {
    105         return self::$show_mobile_content;
    106     }
    107 }
    108
    109 class HomePage_Controller extends Page_Controller {
    110
    111 }
    112

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