Okay, I couldn't help myself. I jumped into the Dashboard module today and tweaked it to be more customizable with an open API. The basic idea is that every component of the dashboard is a plugin. You can create a plugin by building a subclass of DashboardPlugin and assigning $position and $sort properties to give it a spot on the dashboard. There are a few other properties you can throw at it, as well, such as $icon and $link. Other than that, it's just straight ViewableData, so any functions you need to create are nicely contained within the plugin class and feed the corresponding template.
Let's look at an example. On my site, let's say my client has a custom page type and really wants a view of it on the dashboard. Let's use the old standby "Staff Member" page example.
/mysite/code/StaffMemberPlugin.php
<?php
class StaffMemberPlugin extends DashboardPlugin
{
static $position = "bottom";
static $sort = 1;
static $title = "Recent Staff Members";
static $link = "admin/cms/staffmembers";
static $link_text = "View All";
static $icon = "dashboard/images/22/gear.png";
function RecentStaffMembers()
{
return DataObject::get("StaffMember",null, "Created DESC");
}
}
Let's walk through this..
static $position: this plugin will go on the bottom, by where the "unmoderated comments" box is. Other choices are "left," "middle" (where "recent activity" is), and "top" (where "get updates" is)
static $sort: The sort order of the plugin in its given position. Duplicate sort values will get resolved arbitrarily by the controller.
static $title: Title for the header tag
static $link: Optional link for the header tag
static $link_text: Text fot the link. This defaults to "View All." This line is unnecessary unless you want to assign a value other than "view all." Shown here just for example.
static $icon: Optional link to the icon for the header
function RecentStaffMembers: We'll use this function on the template to get our list of staff members.
Now, on to the template.
/mysite/templates/plugins/StaffMemberPlugin.ss
<% if RecentStaffMembers %>
<ul>
<% control RecentStaffMembers %>
<li>$Name, $JobTitle (<em>$Created.Ago</em>)</li>
<% end_control %>
</ul>
<% else %>
<h4>There are no staff members.</h4>
<% end_if %>
All plugins are enabled by default. But let's say I want to get rid of the "Silverstripe News" plugin on my site.
/mysite/_config.php
DashboardPlugin::disable('SSNews');
The SSNews plugin is no longer visible on my dashboard.
That's it! In the ZIP file attached, I have modified the DashboardAdmin class to use plugins, and have migrated all the functions into their own plugin classes in /dashboard/code/plugins. They include: RecentFiles.php, RecentPages.php, SiteInfo.php, SSNews.php, UnmoderatedComments.php, and Updates.php.
Feedback and bug reports welcome. I think this will help make the dashboard more marketable to all kinds of sites now that users have the ability to create custom feeds. Let's keep this thing going!