PWaddict Posted September 18 Share Posted September 18 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 September 18 Share Posted September 18 if(wire()->user->isSuperuser()) { // your code } ? Link to comment Share on other sites More sharing options...
PWaddict Posted September 18 Author Share Posted September 18 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 September 18 Share Posted September 18 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 September 18 Author Share Posted September 18 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