Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

ModelAdmin without a DataObject - Static page


Go to End


4 Posts   2595 Views

Avatar
Double-A-Ron

Community Member, 607 Posts

5 March 2014 at 2:27pm

SS 3.1

I have need for a section in the the CMS admin where one tab is a GridField for a DataObject, but the other is a small form (one field, one button) linked to nothing. The action on the form will be completely custom and external to Silverstripe.

The DataObject is fine as per documentation, but how do I add a tab to this ModelAdmin that contains nothing more than static HTML?

I've downloaded both the Dashboard and SwipeStripe modules to get some guidance, but I can't decipher the structure in either.

Avatar
Willr

Forum Moderator, 5523 Posts

6 March 2014 at 8:07pm

ModelAdmin is designed for managing your DataObjects, if you want to push additional fields into an existing ModelAdmin you can override getEditForm() in your ModelAdmin subclass to provide additional buttons etc. If you just want a generic panel in the admin you can manage, subclass 'LeftAndMain'. An overview is available at http://doc.silverstripe.org/framework/en/reference/cms-architecture

Avatar
Double-A-Ron

Community Member, 607 Posts

6 March 2014 at 8:48pm

Thanks again Will,

Since posting I've started playing with the second option, LeftAndMain, loosely based on the default SiteAdmin -> SiteConfig relationship and overriding getCMSFields as per SiteConfig.

Limited success so far. I have a manual form displaying, and a dataObject form displaying (the later I plan to replace with a read-only GridField). But they're all on one page instead of split over two tabs as I have defined.

Actually I think they really are split, but the tabs are just links sitting in the top right corner. E.G. I'm missing some JS for handling the tabs.

Will continue in the morn and post my code for future ref on success. There's not much specifically for this sort of thing out there.

Avatar
lugor

Community Member, 2 Posts

30 November 2014 at 9:29am

I had the same requirement and I solved it like this:

a regular class providing the static html


class Documentation
{
    static $singular_name = 'ℹHelp';
    static $plural_name = 'Help';
    var $isVersioned = false;

    function i18n_singular_name()
    {
        return self::$singular_name;
    }

    public static function getHTML()
    {

        $html = <<< EOT
Some static html ...
EOT;
        return $html;

    }
}

add class to the managed models in modeladmin

    private static $managed_models = array(
        'Documentation',
# other classes ...
);

a little tweak in getEditForm in my modeladmin



    private static $no_tools_models = array(
        'Documentation',
    );

...

   public function getEditForm($id = null, $fields = null) 
   {
        if ($this->modelClass == 'Documentation'){
            return Documentation::getHTML();
        }
	}

...

    public function Tools()
    {
        if (in_array($this->modelClass, self::$no_tools_models)){
            return false;
        }
        return parent::Tools();
    }