Model Admins with Custom Images

Send Snippet To: Save this snippet to Code Collector Pro -- view all balzan's snippets
language: PHP
license: Other

Code for Snippet:

                
<?php
class UserMessageAdmin extends ModelAdmin {
 
    static $menu_icon = 'mysite/images/picture_16.png';
 
    private static $managed_models = array(
        "UserMessage"
    );
 
    private static $menu_title = "User Messages";
    private static $url_segment = "usermessages";
    private static $menu_priority = 14;
 
 
    public function getEditForm($id = null, $fields = null) {
        $form=parent::getEditForm($id, $fields);
 
        //This check is simply to ensure you are on the managed model you want adjust accordingly
        if($this->modelClass=='UserMessage' && $gridField=$form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) {
            //This is just a precaution to ensure we got a GridField from dataFieldByName() which you should have
            if($gridField instanceof GridField) {
                $gridField->getConfig()->getComponentByType('GridFieldPaginator')->setItemsPerPage(100);
            }
        }
 
        return $form;
    }
 
}
 
 
 
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 139
Date Added: 2016-05-31 03:37:21
Last Modified: 2016-07-05 23:42:18

Web Analytics