1 <?php
2 3 4 5 6
7 class NewsSiteConfig extends SiteConfigDecorator {
8
9 static $hidden_fields = array();
10
11 function () {
12 return array(
13 'db' => array(
14 'NewsPerPage' => 'Int',
15 'NewsInRSS' => 'Int',
16 'ShowNewsInTree' => 'Boolean',
17 ),
18 'defaults' => array(
19 'NewsPerPage' => 20,
20 'NewsInRSS' => 20,
21 'NewsOnHomePage' => 5,
22 'ShowNewsInTree' => 0,
23 )
24 );
25 }
26
27 public function updateCMSFields(FieldSet &$fields) {
28 $tab = SiteConfigDecorator::get_config_tab($fields, 'News');
29
30 $tab->push(new NumericField('NewsPerPage', _t('SiteConfig.NewsPerPage', 'News Per Page')));
31 $tab->push(new NumericField('NewsInRSS', _t('SiteConfig.NewsInRSS', 'News In RSS')));
32 if (Director::isDev()) {
33 $tab->push(new CheckboxField('ShowNewsInTree', _t('SiteConfig.ShowNewsInTree', 'Show News In Tree')));
34 }
35
36 $this->hideUnselectedFields($fields);
37 }
38
39 40 41
42 public function onBeforeWrite() {
43 parent::onBeforeWrite();
44 if ($this->owner->isChanged('ShowNewsInTree')) {
45 $state = (1 - $this->owner->ShowNewsInTree);
46
47 DB::query("UPDATE `Page` SET `ShowOnlyInTab` = {$state} WHERE `ID` in (SELECT `ID` FROM `NewsEntry`)");
48
49 DB::query("UPDATE `Page_Live` SET `ShowOnlyInTab` = {$state} WHERE `ID` in (SELECT `ID` FROM `NewsEntry_Live`)");
50 }
51 }
52 }
53
[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.
-