Craft CMS Asked by nstCactus on March 15, 2021
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?
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 modulesappModule;
use Craft;
use crafteventsRegisterCpNavItemsEvent;
use craftwebtwigvariablesCp;
use yiibaseModule;
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');
});
}
}
}
Answered by nstCactus on March 15, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP