<p>The dashboard is surprisingly unflexible. There's no permission to control whether users are allowed to change their dashboard widgets, no default widget options for new users and no access controls for widgets. But you can use the <a href="https://docs.craftcms.com/api/v3/craft-services-dashboard.html" rel="nofollow noreferrer">Dashboard service</a> to change the dashboard widgets for a given user, and hide the dashboard options using CSS.</p>
<h2>Hiding dashboard options from users</h2>
<p>First install the <a href="https://plugins.craftcms.com/cp-body-classes" rel="nofollow noreferrer">Control Panel Body Classes plugin</a> to be able to target specific user groups in CSS. Then you can include some CSS (using a site module) in the Control Panel to hide the Dashboard configuration from specific user groups.</p>
<p>The following snippet hides the dashboard configuration (the
<em>New Widget</em> dropdown and the configuration button) from the user group <code>collaborator</code>:</p>
<pre class="lang-php prettyprint-override"><code>use Craft;

if (Craft::$app-&gt;getRequest()-&gt;getIsCpRequest()) {
    /** @var craft\web\View $view */
    $view = Craft::$app-&gt;getView();
    $view-&gt;registerCss(&lt;&lt;&lt;CSS
        body.usergroup-collaborator.currentsection-dashboard #action-button {
            display: none;
        }
    CSS);
}
</code></pre>
<p>If you only want to limit the widgets that are available for a particular user group, you can hide those in the <em>New widget</em> dropdown using CSS as well. You can even enforce this on the server-side with an event hook for <a href="https://docs.craftcms.com/api/v3/craft-services-dashboard.html#event-before-save-widget" rel="nofollow noreferrer">Dashboard::EVENT_BEFORE_SAVE_WIDGET</a>. The callback can prevent saving a widget that the current user shouldn't have access to.</p>
<h2>Changing dashboard widgets programmatically</h2>
<p>Now this particular user group can't modify their own dashboard widgets any more, but they're still stuck with the default widgets. To change them, you can use event handlers to force a particular set of widgets. You can do this either upon registration or login (I prefer the latter, in case you want to change the available widgets at some point).</p>
<pre class="lang-php prettyprint-override"><code>use craft\web\User;
use yii\base\Event;
use yii\web\UserEvent;

Event::on(
    User::class,
    User::EVENT_AFTER_LOGIN,
    fn(UserEvent $e) =&gt; $this-&gt;ensureDefaultDashboardWidgets($e-&gt;sender),
);
</code></pre>
<p>The function needs to remove the default widgets and then register the predefined set of widgets you want to provide to that user group:</p>
<pre class="lang-php prettyprint-override"><code>use Craft;
use craft\web\User;

public function ensureDefaultDashboardWidgets(User $user): void
{
    /** @var craft\elements\User */
    $userIdentity = $user-&gt;getIdentity();
    /** @var craft\services\Dashboard $dashboard */
    $dashboard = Craft::$app-&gt;dashboard;

    $userGroups = $userIdentity-&gt;getGroups();
    $isCollaborator = count($userGroups) === 1 &amp;&amp; $userGroups[0]-&gt;handle === 'collaborator';
    if (!$isCollaborator) return;

    // remove all existing widgets
    $existingWidgets = $dashboard-&gt;getAllWidgets();
    foreach ($existingWidgets as $widget) {
        $dashboard-&gt;deleteWidget($widget);
    }

    $defaultWidgets = [
        $dashboard-&gt;createWidget([
            'type' =&gt; 'craft\\widgets\\MyDrafts',
            'settings' =&gt; ['limit' =&gt; 10],
        ]),
        $dashboard-&gt;createWidget('modules\\MyCustomWidgetsModule\\widgets\\MyCustomWidget'),
    ];

    // add all default widgets in order
    foreach ($defaultWidgets as $widget) {
        $dashboard-&gt;saveWidget($widget);
    }
}
</code></pre>
<p>Now you can add more widgets (including your own custom widgets) to the <code>$defaultWidgets</code> array and they will be added to all <code>collaborator</code> users upon login. You can further refine this; for example, by comparing the existing widgets with the default widgets and only overwriting them if they differ in some way.</p>

CC BY-SA 4.0
2021-12-09T13:32:17.687Z
Thank you for the detailed explanation @moritzLost. Super helpful for my needs.
Parthiban
CC BY-SA 4.0
2021-12-09T11:07:23.227Z
2021-12-09T11:07:23.227Z
MoritzLost
<p>I would like to display only the selected widgets to the particular user group. Also is there a way to disable default widgets like craft news, Recent entries etc?</p>

CC BY-SA 4.0
2021-12-09T10:38:46.493Z
Do you mean you want to display a fixed selection of widgets to that user group and prevent them from changing them? Or just limit which widgets are available to which specific user groups?
MoritzLost
CC BY-SA 4.0
2021-12-14T09:45:27.473Z
@MoritzLost I would like to display a fixed set of dashboard widgets to the particular user group. and if possible I would like to remove the new widget add option on for those user groups.
Parthiban
CC BY-SA 4.0
2021-12-14T09:53:26.353Z
@Partihiban I think my answer addresses both of those, or is something missing?
MoritzLost
CC BY-SA 4.0
2021-12-14T10:22:10.697Z
@MoritzLost Yes it works. Thanks.
Parthiban
<craft3><dashboard-widgets>
Is there a way to display only the selected widgets to the user group or disable them altogether?
# Is there a way to display only the selected widgets to the user group or disable them altogether?

(Asked by: username_0 on 2021-12-09)

I would like to display only the selected widgets to the particular user group. Also is there a way to disable default widgets like craft news, Recent entries etc?

**Tags:** craft3, dashboard-widgets
> **Comments:**
> **username_1**: Do you mean you want to display a fixed selection of widgets to that user group and prevent them from changing them? Or just limit which widgets are available to which specific user groups?  
> **username_0**: @MoritzLost I would like to display a fixed set of dashboard widgets to the particular user group. and if possible I would like to remove the new widget add option on for those user groups.  
> **username_1**: @Partihiban I think my answer addresses both of those, or is something missing?  
> **username_0**: @MoritzLost Yes it works. Thanks.  

---

## 1 answers

### Answer by username_1 on 2021-12-09. Score: 2 | Accepted answer

The dashboard is surprisingly unflexible. There's no permission to control whether users are allowed to change their dashboard widgets, no default widget options for new users and no access controls for widgets. But you can use the Dashboard service to change the dashboard widgets for a given user, and hide the dashboard options using CSS.
Hiding dashboard options from users
First install the Control Panel Body Classes plugin to be able to target specific user groups in CSS. Then you can include some CSS (using a site module) in the Control Panel to hide the Dashboard configuration from specific user groups.
The following snippet hides the dashboard configuration (the
New Widget dropdown and the configuration button) from the user group collaborator:
use Craft;

if (Craft::$app->getRequest()->getIsCpRequest()) {
    /** @var craft\web\View $view */
    $view = Craft::$app->getView();
    $view->registerCss(<<
If you only want to limit the widgets that are available for a particular user group, you can hide those in the New widget dropdown using CSS as well. You can even enforce this on the server-side with an event hook for Dashboard::EVENT_BEFORE_SAVE_WIDGET. The callback can prevent saving a widget that the current user shouldn't have access to.
Changing dashboard widgets programmatically
Now this particular user group can't modify their own dashboard widgets any more, but they're still stuck with the default widgets. To change them, you can use event handlers to force a particular set of widgets. You can do this either upon registration or login (I prefer the latter, in case you want to change the available widgets at some point).
use craft\web\User;
use yii\base\Event;
use yii\web\UserEvent;

Event::on(
    User::class,
    User::EVENT_AFTER_LOGIN,
    fn(UserEvent $e) => $this->ensureDefaultDashboardWidgets($e->sender),
);

The function needs to remove the default widgets and then register the predefined set of widgets you want to provide to that user group:
use Craft;
use craft\web\User;

public function ensureDefaultDashboardWidgets(User $user): void
{
    /** @var craft\elements\User */
    $userIdentity = $user->getIdentity();
    /** @var craft\services\Dashboard $dashboard */
    $dashboard = Craft::$app->dashboard;

    $userGroups = $userIdentity->getGroups();
    $isCollaborator = count($userGroups) === 1 && $userGroups[0]->handle === 'collaborator';
    if (!$isCollaborator) return;

    // remove all existing widgets
    $existingWidgets = $dashboard->getAllWidgets();
    foreach ($existingWidgets as $widget) {
        $dashboard->deleteWidget($widget);
    }

    $defaultWidgets = [
        $dashboard->createWidget([
            'type' => 'craft\\widgets\\MyDrafts',
            'settings' => ['limit' => 10],
        ]),
        $dashboard->createWidget('modules\\MyCustomWidgetsModule\\widgets\\MyCustomWidget'),
    ];

    // add all default widgets in order
    foreach ($defaultWidgets as $widget) {
        $dashboard->saveWidget($widget);
    }
}

Now you can add more widgets (including your own custom widgets) to the $defaultWidgets array and they will be added to all collaborator users upon login. You can further refine this; for example, by comparing the existing widgets with the default widgets and only overwriting them if they differ in some way.

> **Comments:**
> **username_0**: Thank you for the detailed explanation @moritzLost. Super helpful for my needs.  

---

