Dashboard

Type
Class
Namespace
craft\services
Inherits
craft\services\Dashboard » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
3.0.0

Dashboard service.

An instance of the service is available via Craft::$app->dashboard.

View source (opens new window)

# Public Properties

Property Description
allWidgetTypes string (opens new window)[]
allWidgets craft\base\WidgetInterface[] – The widgets
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component.

# allWidgetTypes

Type
string (opens new window)[]
Default value
null
Access
Read-only

View source (opens new window)

# allWidgets

Type
craft\base\WidgetInterface[]
Default value
null
Access
Read-only

The widgets

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__clone() (opens new window) This method is called after the object is created by cloning an existing one.
__construct() (opens new window) Constructor.
__get() (opens new window) Returns the value of a component property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets the value of a component property.
__unset() (opens new window) Sets a component property to be null.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
behaviors() (opens new window) Returns a list of behaviors that this component should behave as.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
changeWidgetColspan() Changes the colspan of a widget.
className() (opens new window) 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() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
doesUserHaveWidget() Returns whether the current user has a widget of the given type.
ensureBehaviors() (opens new window) Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component.
getAllWidgetTypes() Returns all available widget type classes.
getAllWidgets() Returns the dashboard widgets for the current user.
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getWidgetById() Returns a widget by its ID.
hasEventHandlers() (opens new window) Returns a value indicating whether there is any handler attached to the named event.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined for this component.
init() (opens new window) Initializes the object.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
reorderWidgets() Reorders widgets.
saveWidget() Saves a widget for the current user.
trigger() (opens new window) Triggers an event.

# changeWidgetColspan()

Changes the colspan of a widget.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# createWidget()

Creates a widget with a given config.

View source (opens new window)

Arguments

  • $config (mixed) – The widget’s class name, or its config, with a type value and optionally a settings value.

Returns

craft\base\WidgetInterface

# deleteWidget()

Deletes a widget.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the widget was deleted successfully

Throws

# deleteWidgetById()

Deletes a widget by its ID.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the widget was deleted successfully

# doesUserHaveWidget()

Returns whether the current user has a widget of the given type.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the current user has a widget of the given type

# getAllWidgetTypes()

Returns all available widget type classes.

View source (opens new window)

Returns

string (opens new window)[]

# getAllWidgets()

Returns the dashboard widgets for the current user.

View source (opens new window)

Returns

craft\base\WidgetInterface[] – The widgets

# getWidgetById()

Returns a widget by its ID.

View source (opens new window)

Arguments

Returns

craft\base\WidgetInterface, null (opens new window) – The widget, or null if it doesn’t exist

# reorderWidgets()

Reorders widgets.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the widgets were reordered successfully

Throws

# saveWidget()

Saves a widget for the current user.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the widget was saved successfully

Throws

# Events

# EVENT_AFTER_DELETE_WIDGET

Type
craft\events\WidgetEvent

The event that is triggered after a widget is deleted.

# EVENT_AFTER_SAVE_WIDGET

Type
craft\events\WidgetEvent

The event that is triggered after a widget is saved.

# EVENT_BEFORE_DELETE_WIDGET

Type
craft\events\WidgetEvent

The event that is triggered before a widget is deleted.

# EVENT_BEFORE_SAVE_WIDGET

Type
craft\events\WidgetEvent

The event that is triggered before a widget is saved.

# EVENT_REGISTER_WIDGET_TYPES

Type
craft\events\RegisterComponentTypesEvent

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 (opens new window) 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;
    }
);