PWaddict Posted yesterday at 04:21 PM Share Posted yesterday at 04:21 PM Hello! How can I set access to superuser only to a field that is created programmatically and doesn't belong to any template? Here is the code of the field that is part of a process module where that field is accessed by a custom page under setup: $field = $modules->get('InputfieldText'); $field->attr('name', 'myfield'); $field->label = $this->_('My Field'); $field->attr('value', $this->myfield); $form->add($field); Link to comment Share on other sites More sharing options...
bernhard Posted yesterday at 04:29 PM Share Posted yesterday at 04:29 PM if(wire()->user->isSuperuser()) { // your code } ? Link to comment Share on other sites More sharing options...
PWaddict Posted yesterday at 04:48 PM Author Share Posted yesterday at 04:48 PM 11 minutes ago, bernhard said: if(wire()->user->isSuperuser()) { // your code } ? Unfortunately that way if a site editor edit the custom page and the superuser never edited it before, the default field value from construct method will not get saved. Feel free to check my process module code here. Link to comment Share on other sites More sharing options...
bernhard Posted yesterday at 04:53 PM Share Posted yesterday at 04:53 PM Then you can do this: $field = $modules->get('InputfieldText'); $field->collapsed = wire()->user->isSuperuser() ? Inputfield::collapsedNo : Inputfield::collapsedHidden; ... 1 Link to comment Share on other sites More sharing options...
PWaddict Posted yesterday at 05:01 PM Author Share Posted yesterday at 05:01 PM Thank you @bernhard, it works perfectly! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now