Skip to content

Instantly share code, notes, and snippets.

@dtbaker
Created January 20, 2015 23:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtbaker/03695a18c601b94aae39 to your computer and use it in GitHub Desktop.
Save dtbaker/03695a18c601b94aae39 to your computer and use it in GitHub Desktop.
This is an example of how to add widgets to the UCM dashboard
<?php
// upload this file to includes/plugin_custom_dashboard_widgets/custom_dashboard_widgets.php
class module_custom_dashboard_widgets extends module_base{
public static function can_i($actions,$name=false,$category=false,$module=false){
if(!$module)$module=__CLASS__;
return parent::can_i($actions,$name,$category,$module);
}
public static function get_class() {
return __CLASS__;
}
public function init(){
$this->links = array();
$this->module_name = "custom_dashboard_widgets";
$this->module_position = 1;
$this->version = 1;
hook_add( 'dashboard_widgets', 'module_custom_dashboard_widgets::my_widgets' );
}
public static function my_widgets() {
$widgets = array();
// start first widget:
ob_start();
?>
<div>
Put your Widget HTML Code Here
</div>
<?php
$widgets[] = array(
'title' => "My Widget Title",
'columns' => 2, // this can be 1, 2, 3 or 4
'content' => ob_get_clean(),
);
// end first widget.
// start second widget:
ob_start();
?>
<div>
Put your Widget HTML Code Here
</div>
<?php
$widgets[] = array(
'title' => "My Widget Title",
'columns' => 2, // this can be 1, 2, 3 or 4
'content' => ob_get_clean(),
);
// end second widget.
return $widgets;
} // end hook function
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment