Version: current

     1 <?php
     2
     3 /**
     4  * Набор меню
     5  *
     6  * @author inxo
     7  */
     8 class CustomMenuHolder extends DataObject {
     9
    10     static $db = array(
    11         'Title' => 'Varchar(255)',
    12         'Segment' => 'Varchar(25)',
    13         'Order' => 'Text',
    14         'SubsiteID' => 'Int', // подсайт меню - чтоб показывать способы меню по подсайтам
    15     );
    16     static $has_many = array(
    17         'Pages' => 'CustomMenuItem'
    18     );
    19
    20     function  getCMSFields($params = null) {
    21         //$fields = parent::getCMSFields($params);
    22        /* $pagesManager = new HasManyComplexTableField($this, 'Pages', 'CustomMenuItem');
    23         $pagesManager->setPopupSize(640, 480);
    24         $fields->replaceField('Pages', $pagesManager);*/
    25         $pagesManager = new FieldSet(
    26                         new TextField('OtherLink', 'OtherLink'),
    27                         new TreeDropdownField('PageLink', 'Страница', 'SiteTree')
    28         );
    29         $customMenus = DataObject::get('CustomMenuHolder')->toDropdownMap();
    30         $customMenus[0] = 'Не выбрано';
    31
    32         $menuManager = new DataObjectManager(
    33             $this,
    34             'Pages',
    35             'CustomMenuItem',
    36             array(
    37                 'Title' => 'Title',
    38                 'OtherLink' => 'OtherLink'
    39             ),
    40             null
    41         );
    42         $menuManager->setRelationAutoSetting(true);
    43         $fields = new FieldSet(
    44                         new TabSet('Root',
    45                                 new Tab('Main',
    46                                         _t('CustomMenus.FormMain', 'Main'),
    47                                         new HeaderField('MenuHeading', _t('CustomMenus.FormMainHeader', 'Edit Menu')),
    48                                         new TextField('Title', _t('CustomMenus.FormMainTitle', 'Menu Title')),
    49                                         new TextField('Segment', _t('CustomMenus.FormMainSlug', 'Menu Slug (used in your control call)'))
    50                                 ), new Tab('Pages', _t('CustomMenus.FormPages', 'Pages'),
    51                                         new HeaderField('ManageMenu', _t('CustomMenus.ManageMenu', 'Управление меню'), 4),
    52                                         $menuManager
    53                                 )
    54                         )
    55         );
    56         $fields->push(new HiddenField('ID', 'id #'));
    57         return $fields;
    58     }
    59
    60     function onBeforeDelete() {
    61         parent::onBeforeDelete();
    62         if ($this->Pages() && $this->Pages()->Count()) {
    63             foreach($this->Pages() as $item) {
    64                 $item->delete();
    65             }
    66         }
    67     }
    68
    69     function ChildPages() {
    70         return DataObject::get('CustomMenuItem', "ParentID = {$this->ID}");
    71     }
    72 }
    73
    74

[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. -