Dashboard

Type
Class
Namespace
craft\services
Inherits
craft\services\Dashboard » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

Dashboard service.

An instance of the Dashboard service is globally accessible in Craft via Craft::$app->dashboard.

View source

Public Properties

PropertyDescription
allWidgetTypesstring[]
allWidgetscraft\base\WidgetInterface[] – The widgets
behaviorsyii\base\Behavior – List of behaviors attached to this component

allWidgetTypes

Type
string[]
Access
Read-only

View source

allWidgets

Type
craft\base\WidgetInterface[]
Access
Read-only

The widgets

View source

Public Methods

MethodDescription
__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 an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to 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()Soft-deletes a widget.
deleteWidgetById()Soft-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.
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.

View source

Arguments

Returns

boolean

createWidget()

Creates a widget with a given config.

View source

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()

Soft-deletes a widget.

View source

Arguments

Returns

boolean – Whether the widget was deleted successfully

Throws

deleteWidgetById()

Soft-deletes a widget by its ID.

View source

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.

View source

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.

View source

Returns

string[]

getAllWidgets()

Returns the dashboard widgets for the current user.

View source

Returns

craft\base\WidgetInterface[] – The widgets

getWidgetById()

Returns a widget by its ID.

View source

Arguments

  • $id (integer) – The widget’s ID

Returns

craft\base\WidgetInterface, null – The widget, or null if it doesn’t exist

reorderWidgets()

Reorders widgets.

View source

Arguments

  • $widgetIds (integer[]) – The widget IDs

Returns

boolean – Whether the widgets were reordered successfully

Throws

saveWidget()

Saves a widget for the current user.

View source

Arguments

Returns

boolean – 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\base\Widget provides a base implementation.

See Widget Types for documentation on creating Dashboard widgets.

Example