See also: Writing Registry Plugins
Some additional conventions are required when writing a Dashboard Widget Plugin.
- The name of the Plugin must match the format
FooWidget
. - The Plugin must implement a
CoFooWidget
model and a corresponding Controller.- The Model
CoFooWidget
should extendCoDashboardWidgetBackend
, which provides some behind the scenes common functionality. - The Controller should to extend
SDWController
("Standard Dashboard Widget" Controller), which provides some common functionality. The controller should use$this->calculateParentPermissions($roles);
to calculate permissions fordisplay()
, in accordance with the current user and the Dashboard's visibility. - When a new Dashboard Widget is instantiated, a skeletal row in the corresponding
co_foo_widgets
table will be created. There is noadd
operation or view required. The skeletal row will point to the parent Dashboard Widget Model. - When a Dashboard Widget Backend is edited, the entry point to the Dashboard Widget Plugin will be
foo_widget/foo_widgets/edit/#
. This will be called immediately after the Widget is first instantiated.
- The Model
- Note
CoDashboardWidget
has ahasOne
(ie: 1 to 1) relationship withFooWidget
. - The table
cm_foo_widgets
should include a foreign key tocm_dashboard_widgets:id
.- Other tables used by the plugin should reference
cm_foo_widgets:id
.
- Other tables used by the plugin should reference
The Plugin must implement
CoFooWidgetsController::display($id)
, and a corresponding viewCoFooWidgets/display.ctp
. These will generate the widget's content when the dashboard is rendered.The widget should always render content, even if there is no "relevant" content to render. In such cases, render a message like "No Foos found."
- The Plugin's instantiated configuration is available in
$this->CoFooWidget->getConfig()
. - If the Plugin is rendering CO Person-specific content, the CO Person ID for which the widget should render content is available in
$this->reqCoPersonId
. Use this rather than reading session information to allow support for administrators viewing Dashboards as other users.
1 Comment
Ioannis Eythymios Igoumenos
Since the
CoDashboardWidget
has a hasOne relationship with the FooWidget, the latter can not implement the Changelog behavior.