1 <?php
2
3 class extends SidebarWidget {
4 static $db = array(
5 'ProductCount' => 'Int'
6 );
7
8 static $has_one = array(
9 'Holder' => 'SpecialCatalog'
10 );
11
12 static $defaults = array(
13 'ProductCount' => 2
14 );
15
16 public $needObjects = array(
17 'SpecialCatalog' => 'Page'
18 );
19
20 function getCMSFields() {
21 if (!$this->canCreate()) {
22 return $this->getFailCMSFields();
23 }
24
25 $fields = parent::getCMSFields();
26 $holders = DataObject::get('SpecialCatalog');
27 if ($holders) {
28 $holders = $holders->map();
29 } else {
30 $holders = array();
31 }
32
33 $fields->replaceField('HolderID', new DropdownField('HolderID', $this->fieldLabel('Holder'), $holders));
34 return $fields;
35 }
36
37 function Products() {
38 if ($this->HolderID && $this->Holder()) {
39 $holder = $this->Holder();
40 return $holder->LinkedProducts(null, 'RAND()', null, $this->ProductCount);
41 }
42 return false;
43 }
44
45 function hasContent() {
46 if ($this->Products()) {
47 return true;
48 }
49 return false;
50 }
51
52 function getMoreLink() {
53 if ($this->HolderID && $this->Holder()) {
54 return $this->Holder()->Link();
55 }
56 return false;
57 }
58 }
59
60
[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.
-