This forum is in read-only mode. Please continue to browse, but replying and other actions are disabled for now.

arall
arall

Hi there,

I'm trying to hide some columns and fields on my backend plugin. Here is what I have:

I've set my permission (acme.test.admin), and have some user groups without it. I've created /models/post/columns.yaml and /models/post/columns_limited.yaml. And finaly, I have /controllers/posts/config.list.yaml (poiting list parameter to /models/post/columns.yaml) and /controllers/posts/config_limited.list.yaml (poiting list parameter to /models/post/columns_limited.yaml).

What I'm trying to do is, on Posts controller, switch config files, like this:

public function __construct()
{
    // Permissions
    if (!$this->user->hasAccess('acme.test.admin')) {
        $this->listConfig = 'config_list_limited.yaml';
    }

    parent::__construct();

    BackendMenu::setContext('Acme.Test', 'test', 'posts');
}

I've checked the Backend\Classes\Controller code, and user is beign set on run method, not in __contruct.

How I can do this in best practice?

Last updated

arall
arall

I think I should use Extend list columns method.

omdreamreg6295
omdreamreg6295

Have you found a solution? I have the same problem. I need to disable field in back end form depending on permission.

omdreamreg6295
omdreamreg6295

I understand :)

Just override field options

public function formExtendFields($form)
    {
        if (!$this->user->hasAccess('acme.plugin.edit_limited')) {
            $form->addFields([
                'someFieldName' => [
                    'label' => 'SomeLabel',
                    'type' => 'text',
                    'hidden' => 'true'
                ],
            ]);
        }
    }

Last updated

ademin
ademin
'someFieldName'       => ['invisible' => 'true']

Last updated

Sebastiaan Kloos (ICTBelang)
Sebastiaan Kloos (ICTBelang)

You can change the path to the list in the variable in the controller. If you you make several forms, you can assign the path for the right permission.

Davox
Davox

In the columns.yaml file you must place only the columns that an user without permissions can view. Then, you can extend the column definitions in the Controller, for example:

public function listExtendColumns($list)
{
    if ($this->user->hasAccess('acme.plugin.permission')) {
        $list->addColumns([     
            'is_published' => [
              'label' =>  'Is published?',
              'type' =>  'switch',
            ],
        ]);
    }
}

If you need to filter the fields.yaml depending of the permissions you can use the filterFields() function in your Model. This example is from RainLab Blog plugin:

public function filterFields($fields, $context = null)
{
    if (!isset($fields->published, $fields->published_at)) {
        return;
    }

    $user = BackendAuth::getUser();

    if (!$user->hasAnyAccess(['rainlab.blog.access_publish'])) {
        $fields->published->hidden = true;
        $fields->published_at->hidden = true;
    }
    else {
        $fields->published->hidden = false;
        $fields->published_at->hidden = false;
    }
}

Last updated

jhgfwerhjer5411631853
jhgfwerhjer5411631853

You can change the path to the list in the variable in the controller. If you you make several forms, you can assign the path for the right permission.

gclub https://gclub.royal-ruby888.com

gclub https://gclub.gclubslot.com/

Last updated

1-8 of 8

You cannot edit posts or make replies: the forum is disabled.