1 <?php
2
3 4 5 6 7
8 class extends DataObject {
9
10 static $db = array(
11 'Title' => 'Text',
12 'OtherLink' => 'Text',
13 'MenuLinkID' => 'Int',
14 'CSS' => 'Varchar(255)',
15 );
16 static $has_one = array(
17 'Parent' => 'CustomMenuHolder',
18 'PageLink' => 'SiteTree',
19 'Icon' => 'Image',
20 );
21 static $summary_fields = array(
22 'Title', 'Link'
23 );
24
25 static $default_sort = 'SortOrder, ID';
26
27 function getCMSFields() {
28 $fields = parent::getCMSFields();
29 $fields->replaceField('Title', new TextField('Title', _t('CustomMenuItem.db_Title', 'Title')));
30 $fields->replaceField('OtherLink', new TextField('OtherLink', _t('CustomMenuItem.db_OtherLink', 'Other Link')));
31 $fields->addFieldToTab('Root.Main', new TreeDropdownField('PageLinkID', _t('CustomMenuItem.has_one_PageLink', 'PageLink'), 'SiteTree'), 'OtherLink');
32
33 $fields->removeByName('SortOrder');
34 $fields->removeByName('MenuLinkID');
35
36 $fields->findOrMakeTab('Root.Design', _t('CustomMenuItem.tab_Design', 'Design'));
37 $fields->addFieldToTab('Root.Design', $fields->dataFieldByName('CSS'));
38 $i = $fields->dataFieldByName('Icon');
39 $i->setFolderName('CustomMenu');
40 $fields->addFieldToTab('Root.Design', $i);
41 return $fields;
42 }
43
44 function () {
45 if ($this->MenuLinkID != 0) {
46 return TRUE;
47 }
48 return FALSE;
49 }
50
51 function Link() {
52 if ($this->PageLinkID == 0 && $this->MenuLinkID == 0) {
53 return $this->OtherLink;
54 }
55 if ($this->MenuLinkID != 0) {
56 return 'CustomMenu';
57 }
58 return $this->PageLink()->Link();
59 }
60
61 function Items() {
62 if ($this->MenuLinkID != 0) {
63 $menu = DataObject::get_by_id('CustomMenuHolder', $this->MenuLinkID);
64 return ($menu) ? $menu : null;
65 }
66 return null;
67 }
68
69 function LinkOrSection() {
70 return ($this->PageLinkID) ? $this->PageLink()->LinkOrSection() : 'link';
71 }
72
73 function LinkOrCurrent() {
74 return ($this->PageLinkID) ? $this->PageLink()->LinkOrCurrent() : 'link';
75 }
76
77 function LinkingMode() {
78 return ($this->PageLinkID) ? $this->PageLink()->LinkingMode() : 'link';
79 }
80
81 }
82
[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.
-