@@ -9,21 +9,21 @@ |
||
| 9 | 9 | |
| 10 | 10 | class NewsPageTest extends SapphireTest |
| 11 | 11 | { |
| 12 | - protected $usesDatabase = true; |
|
| 12 | + protected $usesDatabase = true; |
|
| 13 | 13 | |
| 14 | - public function testGetNewsPageAuthor() |
|
| 15 | - { |
|
| 16 | - $holder = new NewsHolder(); |
|
| 17 | - $holder->Title = 'Holder'; |
|
| 18 | - $holder->write(); |
|
| 14 | + public function testGetNewsPageAuthor() |
|
| 15 | + { |
|
| 16 | + $holder = new NewsHolder(); |
|
| 17 | + $holder->Title = 'Holder'; |
|
| 18 | + $holder->write(); |
|
| 19 | 19 | |
| 20 | - $page = new NewsPage(); |
|
| 21 | - $page->Author = 'Leslie Lawless'; |
|
| 22 | - $page->ParentID = $holder->ID; |
|
| 23 | - $page->write(); |
|
| 20 | + $page = new NewsPage(); |
|
| 21 | + $page->Author = 'Leslie Lawless'; |
|
| 22 | + $page->ParentID = $holder->ID; |
|
| 23 | + $page->write(); |
|
| 24 | 24 | |
| 25 | - $field = $page->getNewsPageAuthor(); |
|
| 26 | - $this->assertInstanceOf(DBField::class, $field); |
|
| 27 | - $this->assertSame('Leslie Lawless', $field->getValue()); |
|
| 28 | - } |
|
| 25 | + $field = $page->getNewsPageAuthor(); |
|
| 26 | + $this->assertInstanceOf(DBField::class, $field); |
|
| 27 | + $this->assertSame('Leslie Lawless', $field->getValue()); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -10,71 +10,71 @@ |
||
| 10 | 10 | |
| 11 | 11 | class NewsPage extends DatedUpdatePage |
| 12 | 12 | { |
| 13 | - private static $description = 'Describes an item of news'; |
|
| 14 | - |
|
| 15 | - private static $default_parent = 'NewsHolderPage'; |
|
| 16 | - |
|
| 17 | - private static $can_be_root = false; |
|
| 18 | - |
|
| 19 | - private static $icon_class = 'font-icon-p-news-item'; |
|
| 20 | - |
|
| 21 | - private static $singular_name = 'News Page'; |
|
| 22 | - |
|
| 23 | - private static $plural_name = 'News Pages'; |
|
| 24 | - |
|
| 25 | - private static $db = [ |
|
| 26 | - 'Author' => 'Varchar(255)', |
|
| 27 | - ]; |
|
| 28 | - |
|
| 29 | - private static $has_one = [ |
|
| 30 | - 'FeaturedImage' => Image::class, |
|
| 31 | - ]; |
|
| 32 | - |
|
| 33 | - private static $owns = [ |
|
| 34 | - 'FeaturedImage', |
|
| 35 | - ]; |
|
| 36 | - |
|
| 37 | - private static $table_name = 'NewsPage'; |
|
| 38 | - |
|
| 39 | - public function fieldLabels($includerelations = true) |
|
| 40 | - { |
|
| 41 | - $labels = parent::fieldLabels($includerelations); |
|
| 42 | - $labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author'); |
|
| 43 | - $labels['FeaturedImageID'] = _t( |
|
| 44 | - 'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel', |
|
| 45 | - 'Featured Image' |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - return $labels; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function getCMSFields() |
|
| 52 | - { |
|
| 53 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 54 | - $fields->addFieldToTab( |
|
| 55 | - 'Root.Main', |
|
| 56 | - TextField::create('Author', $this->fieldLabel('Author')), |
|
| 57 | - 'Abstract' |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - $fields->addFieldToTab( |
|
| 61 | - 'Root.Main', |
|
| 62 | - UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')), |
|
| 63 | - 'Abstract' |
|
| 64 | - ); |
|
| 65 | - }); |
|
| 66 | - return parent::getCMSFields(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Returns the Author DB field for this page type. |
|
| 71 | - * |
|
| 72 | - * Used to avoid conflicts with `Versioned::Author()` |
|
| 73 | - * |
|
| 74 | - * @return DBField |
|
| 75 | - */ |
|
| 76 | - public function getNewsPageAuthor() |
|
| 77 | - { |
|
| 78 | - return $this->dbObject('Author'); |
|
| 79 | - } |
|
| 13 | + private static $description = 'Describes an item of news'; |
|
| 14 | + |
|
| 15 | + private static $default_parent = 'NewsHolderPage'; |
|
| 16 | + |
|
| 17 | + private static $can_be_root = false; |
|
| 18 | + |
|
| 19 | + private static $icon_class = 'font-icon-p-news-item'; |
|
| 20 | + |
|
| 21 | + private static $singular_name = 'News Page'; |
|
| 22 | + |
|
| 23 | + private static $plural_name = 'News Pages'; |
|
| 24 | + |
|
| 25 | + private static $db = [ |
|
| 26 | + 'Author' => 'Varchar(255)', |
|
| 27 | + ]; |
|
| 28 | + |
|
| 29 | + private static $has_one = [ |
|
| 30 | + 'FeaturedImage' => Image::class, |
|
| 31 | + ]; |
|
| 32 | + |
|
| 33 | + private static $owns = [ |
|
| 34 | + 'FeaturedImage', |
|
| 35 | + ]; |
|
| 36 | + |
|
| 37 | + private static $table_name = 'NewsPage'; |
|
| 38 | + |
|
| 39 | + public function fieldLabels($includerelations = true) |
|
| 40 | + { |
|
| 41 | + $labels = parent::fieldLabels($includerelations); |
|
| 42 | + $labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author'); |
|
| 43 | + $labels['FeaturedImageID'] = _t( |
|
| 44 | + 'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel', |
|
| 45 | + 'Featured Image' |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + return $labels; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function getCMSFields() |
|
| 52 | + { |
|
| 53 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 54 | + $fields->addFieldToTab( |
|
| 55 | + 'Root.Main', |
|
| 56 | + TextField::create('Author', $this->fieldLabel('Author')), |
|
| 57 | + 'Abstract' |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + $fields->addFieldToTab( |
|
| 61 | + 'Root.Main', |
|
| 62 | + UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')), |
|
| 63 | + 'Abstract' |
|
| 64 | + ); |
|
| 65 | + }); |
|
| 66 | + return parent::getCMSFields(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Returns the Author DB field for this page type. |
|
| 71 | + * |
|
| 72 | + * Used to avoid conflicts with `Versioned::Author()` |
|
| 73 | + * |
|
| 74 | + * @return DBField |
|
| 75 | + */ |
|
| 76 | + public function getNewsPageAuthor() |
|
| 77 | + { |
|
| 78 | + return $this->dbObject('Author'); |
|
| 79 | + } |
|
| 80 | 80 | } |