Search code examples
titlesilverstripemodeladmin

Silverstripe 4.6 ModelAdmin dynamic $menu_Title


Is it possible to dynamically change the ModelAdmins $menu_Title to e.g.

Member::currentUser()->Name ?

How ? Thanks.


Solution

  • Ok. I got it.

    <?php
    
    use SilverStripe\Admin\ModelAdmin;
    //...
    //...
    
    class UserAdmin extends ModelAdmin
    { 
        
         private static $managed_models = array(
            'YourDataObject'
        );
        
        private static $url_segment = 'test';
        private  static $menu_title = 'Test';
        private static $menu_icon_class = 'fa fa-pagelines';
    
        
        public function getEditForm($id = null, $fields = null)
        {
            $form = parent::getEditForm($id, $fields);
            //.......
            //.......
            return $form;
        }
        
        
         public static function menu_title($class = null, $localise = true){
             //return 'YOUR MENU TITLE';
             return Member::currentUser()->Name; 
         }
        
    }