Homepage
Main navigation
Main content
Additional information
October Tricks
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
October CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
**This feature is available in Core starting from Build 460: https://github.com/octobercms/october/pull/4520** Create a trait that extends the controller and form fields. ### traits/ColumnFieldPermissions.php ```php trait ColumnFieldPermissions { public function formExtendFields($form, $fields) { foreach ($fields as $name => $field) { $permissionValue = array_get($field->config, 'permission'); if ($permissionValue && !$this->user->hasAccess($permissionValue)) { if (array_get($field->config, 'permissionReadOnly')) { $field->readOnly = true; $field->disabled = true; } else { $form->removeField($name); } } } } public function listExtendColumns($list) { foreach ($list->columns as $name => $column) { $permissionValue = array_get($column, 'permission'); if ($permissionValue && !$this->user->hasAccess($permissionValue)) { $list->removeColumn($name); } } } } ``` ### Example of usage ```php use Samuell\Plugin\Traits\ColumnFieldPermissions; class YourController extends Controller { use ColumnFieldPermissions; .... } ``` Then we can use it in columns or fields like ```yaml name: permission: my.custom.permission ```
References
Add additional online resources to your trick
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline