1 <?php
2 3 4 5 6 7 8
9 class ButtonsBlockHomepageWidget extends HomepageWidget {
10 static $db = array(
11 'Text' => 'HTMLText',
12 'SectionLinkTitle' => 'Varchar(200)',
13 );
14
15
16 static $has_one = array(
17 'SectionLink' => 'SiteTree',
18 );
19
20 static $has_many = array(
21 'Items' => 'ButtonsBlockHomepageWidget_Item'
22 );
23
24 function getCMSFields() {
25 $fields = parent::getCMSFields();
26 $dom = new DataObjectManager(
27 $this,
28 'Items',
29 'ButtonsBlockHomepageWidget_Item',
30 null,
31 null,
32 "WidgetID = {$this->ID}"
33 );
34 $dom->setRelationAutoSetting(true);
35 $fields->replaceField('Items', $dom);
36
37 $parentIDField = new TreeDropdownField('SectionLinkID', $this->fieldLabel('SectionLink'), 'SiteTree');
38 $fields->replaceField('SectionLinkID', $parentIDField);
39 $fields->insertAfter($fields->dataFieldByName('SectionLinkTitle'), 'SectionLinkID');
40
41 return $fields;
42 }
43
44 function ActiveItems() {
45 return $this->Items('Active = 1');
46 }
47
48 function SectionLinkData() {
49 if ($this->SectionLinkID && ($sectionLink = $this->SectionLink()) && $sectionLink->ID) {
50 return new ArrayData(array(
51 'Title' => ($this->SectionLinkTitle ? $this->SectionLinkTitle : $sectionLink->Title),
52 'Link' => $sectionLink->Link(),
53 ));
54 }
55 return false;
56 }
57 }
58
59 class ButtonsBlockHomepageWidget_Item extends WebylonWidget_Item {
60 static $has_one = array(
61 'Image' => 'Image',
62 );
63
64 function fieldLabels($includerelations = true) {
65 $fields = parent::fieldLabels($includerelations);
66 $fields['Title'] = _t('ButtonsBlockHomepageWidget_Item.db_Title', 'Button text');
67 return $fields;
68 }
69
70 function getCMSFields() {
71 $fields = parent::getCMSFields();
72 $fields->removeByName('SortOrder');
73
74 return $fields;
75 }
76 }
77
[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.
-