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:

class UserMessageAdmin extends ModelAdmin {
    static $menu_icon = 'mysite/images/picture_16.png';
    private static $managed_models = array(
    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) {
        return $form;
comments powered by Disqus


Link to this snippet:

Download to Code Collector

To use the direct link to your snippet on 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: 189
Date Added: 2016-05-31 03:37:21
Last Modified: 2016-07-05 23:42:18

Web Analytics