PWaddict Posted September 18, 2024 Posted September 18, 2024 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);
bernhard Posted September 18, 2024 Posted September 18, 2024 if(wire()->user->isSuperuser()) { // your code } ?
PWaddict Posted September 18, 2024 Author Posted September 18, 2024 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.
bernhard Posted September 18, 2024 Posted September 18, 2024 Then you can do this: $field = $modules->get('InputfieldText'); $field->collapsed = wire()->user->isSuperuser() ? Inputfield::collapsedNo : Inputfield::collapsedHidden; ... 1
PWaddict Posted September 18, 2024 Author Posted September 18, 2024 Thank you @bernhard, it works perfectly!
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