October CMS resources and help articles

Simple and to the point. Optimized by the community.

Disable Backend User Groups

13
by danharrin, last modified on June 11th, 2020

Disabling user group UI items is a great way of decluttering your backend for projects that don't use the features.

Firstly, this code is required in your plugin's Plugin.php:

use Backend\Controllers\Users as BackendUserController;
// ...
    public function boot()
    {
            BackendUserController::extend(function ($controller) {
                    $controller->listConfig = $controller->makeConfig($controller->listConfig);
                    $controller->listConfig->toolbar = array_merge($controller->listConfig->toolbar, ['buttons' => '$/acme/blog/partials/toolbar.users.htm']);
            });

            BackendUserController::extendListColumns(function ($list, $model) {
                    $list->removeColumn('groups');
            });

            BackendUserController::extendFormFields(function($form, $model, $context) {
                    $form->removeField('groups');
            });
    }

Make sure to replace acme/blog with the name of your plugin.

Finally, create the file partials/toolbar.users.htm in your plugin's root directory, with the following code:

<div data-control="toolbar">
    <a href="<?= Backend::url('backend/users/create') ?>" class="btn btn-primary oc-icon-plus">
        <?= e(trans('backend::lang.user.new')) ?>
    </a>
    <?php if ($this->user->isSuperUser()): ?>
        <a href="<?= Backend::url('backend/userroles') ?>" class="btn btn-default oc-icon-address-card">
            <?= e(trans('backend::lang.user.role.list_title')) ?>
        </a>
    <?php endif ?>
</div>

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?