Jump to content

[SOLVED] How to allow only superuser access to a programmatically field?


Recommended Posts

Posted

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);

 

Posted
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.

Posted

Then you can do this:

$field = $modules->get('InputfieldText');
$field->collapsed = wire()->user->isSuperuser()
	? Inputfield::collapsedNo
	: Inputfield::collapsedHidden;
...

 

  • Thanks 1
  • PWaddict changed the title to [SOLVED] How to allow only superuser access to a programmatically field?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...