Dashboard ​
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\Dashboard » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
Dashboard service.
An instance of the service is available via Craft::$app->dashboard
.
Public Properties ​
Property | Description |
---|---|
allWidgetTypes | string[] |
allWidgets | craft\base\WidgetInterface[] – The widgets |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
allWidgetTypes
​
- Type
- string[]
- Default value
null
- Access
- Read-only
allWidgets
​
- Type
- craft\base\WidgetInterface[]
- Default value
null
- Access
- Read-only
The widgets
Public Methods ​
Method | Description |
---|---|
__call() | Calls the named method which is not a class method. |
__clone() | This method is called after the object is created by cloning an existing one. |
__construct() | Constructor. |
__get() | Returns the value of a component property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be null. |
attachBehavior() | Attaches a behavior to this component. |
attachBehaviors() | Attaches a list of behaviors to the component. |
behaviors() | Returns a list of behaviors that this component should behave as. |
canGetProperty() | Returns a value indicating whether a property can be read. |
canSetProperty() | Returns a value indicating whether a property can be set. |
changeWidgetColspan() | Changes the colspan of a widget. |
className() | Returns the fully qualified name of this class. |
createWidget() | Creates a widget with a given config. |
deleteWidget() | Deletes a widget. |
deleteWidgetById() | Deletes a widget by its ID. |
detachBehavior() | Detaches a behavior from the component. |
detachBehaviors() | Detaches all behaviors from the component. |
doesUserHaveWidget() | Returns whether the current user has a widget of the given type. |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
getAllWidgetTypes() | Returns all available widget type classes. |
getAllWidgets() | Returns the dashboard widgets for the current user. |
getBehavior() | Returns the named behavior object. |
getBehaviors() | Returns all behaviors attached to this component. |
getWidgetById() | Returns a widget by its ID. |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() | Returns a value indicating whether a method is defined. |
hasProperty() | Returns a value indicating whether a property is defined for this component. |
init() | Initializes the object. |
off() | Detaches an existing event handler from this component. |
on() | Attaches an event handler to an event. |
reorderWidgets() | Reorders widgets. |
saveWidget() | Saves a widget for the current user. |
trigger() | Triggers an event. |
changeWidgetColspan()
​
Changes the colspan of a widget.
Arguments ​
Returns ​
createWidget()
​
Creates a widget with a given config.
Arguments ​
$config
(string, array) – The widget’s class name, or its config, with atype
value and optionally asettings
value.
Returns ​
\craft\services\T
deleteWidget()
​
Deletes a widget.
Arguments ​
$widget
(craft\base\WidgetInterface) – The widget to be deleted
Returns ​
boolean – Whether the widget was deleted successfully
Throws ​
- Throwable
if reasons
deleteWidgetById()
​
Deletes a widget by its ID.
Arguments ​
$widgetId
(integer) – The widget’s ID
Returns ​
boolean – Whether the widget was deleted successfully
doesUserHaveWidget()
​
Returns whether the current user has a widget of the given type.
Arguments ​
$type
(string) – The widget type
Returns ​
boolean – Whether the current user has a widget of the given type
getAllWidgetTypes()
​
Returns all available widget type classes.
Returns ​
string[]
getAllWidgets()
​
Returns the dashboard widgets for the current user.
Returns ​
craft\base\WidgetInterface[] – The widgets
getWidgetById()
​
Returns a widget by its ID.
Arguments ​
$id
(integer) – The widget’s ID
Returns ​
craft\base\WidgetInterface, null – The widget, or null if it doesn’t exist
reorderWidgets()
​
Reorders widgets.
Arguments ​
$widgetIds
(integer[]) – The widget IDs
Returns ​
boolean – Whether the widgets were reordered successfully
Throws ​
- Throwable
if reasons
saveWidget()
​
Saves a widget for the current user.
Arguments ​
$widget
(craft\base\WidgetInterface) – The widget to be saved$runValidation
(boolean) – Whether the widget should be validated
Returns ​
boolean – Whether the widget was saved successfully
Throws ​
- Throwable
if reasons
Events ​
EVENT_AFTER_DELETE_WIDGET ​
The event that is triggered after a widget is deleted.
EVENT_AFTER_SAVE_WIDGET ​
The event that is triggered after a widget is saved.
EVENT_BEFORE_DELETE_WIDGET ​
The event that is triggered before a widget is deleted.
EVENT_BEFORE_SAVE_WIDGET ​
The event that is triggered before a widget is saved.
EVENT_REGISTER_WIDGET_TYPES ​
The event that is triggered when registering Dashboard widget types.
Dashboard widgets must implement craft\base\WidgetInterface. \craft\services\Widget
provides a base implementation.
See Widget Types for documentation on creating Dashboard widgets.
Example ​
use craft\events\RegisterComponentTypesEvent;
use craft\services\Dashboard;
use yii\base\Event;
Event::on(Dashboard::class,
Dashboard::EVENT_REGISTER_WIDGET_TYPES,
function(RegisterComponentTypesEvent $event) {
$event->types[] = MyWidgetType::class;
}
);