1

I need to hide the assets section of the control panel to a given user group.

Changing the group permissions to prevent them from viewing all asset volumes also prevents them from uploading assets in entries, which is not what I want.

I want them to be able to upload new assets but prevent them from snooping around in the asset library.

Is there a way to achieve this?

1 Answer 1

2

Using a custom module it's easy to simply hide the Assets section of the CP.

Users would still be able to access the assets library by entering manually the URL but this is good enough for my use case.

Here's the (simplified) code:

<?php

namespace modules\appModule;

use Craft;
use craft\events\RegisterCpNavItemsEvent;
use craft\web\twig\variables\Cp;
use yii\base\Module;

class AppModule extends Module
{
    public function init()
    {
        $user = Craft::$app->getUser();
        if (
            Craft::$app->getRequest()->isCpRequest
            && !$user->isGuest
            && $user->getIdentity()->isInGroup('editors')
        ) {
            Event::on(Cp::class, Cp::EVENT_REGISTER_CP_NAV_ITEMS, function(RegisterCpNavItemsEvent $event) {
                $event->navItems = array_filter($event->navItems, static fn ($item) => $item['url'] !== 'assets');
            });
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.