This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
info13179
Hi,
I want to extend the backend controller with a field. But, this extra field had to be only visible when the logged in user has the right permissions. I tried something like this, but this is not working:
if (!$this->user->hasAccess('roywcm.storeblogs.manage_own_store')) {
UsersController::extendFormFields(function($form, $model, $context){
if (!$model instanceof UserModel)
return;
$form->addFields([
'store' => [
'label'=> 'Store',
'type'=>'relation',
'nameFrom'=> 'name'
],
]);
});
}
i'm getting this error:
Undefined property: Roywcm\Storeblogs\Plugin::$user
Last updated
info13179
Allright, I figured it out:
UsersController::extendFormFields(function($form, $model, $context){
if (!$model instanceof UserModel)
return;
$user = BackendAuth::getUser();
if($user->hasAccess('manage_stores')){
$form->addFields([
'store' => [
'label'=> 'Store',
'type'=>'relation',
'nameFrom'=> 'name'
],
]);
}
});
bayram4ik
info13179 said:
In the boot() function in your plugin.php file.
Note, that you can also create init.php in plugins root directory and put such stuff there.
1-5 of 5