Jump to content

Partially lock page


MarkE
 Share

Recommended Posts

I want to lock a page from all but superusers doing the following:

  • changing ID, name, title, parent or template
  • deleting the page

But I want them (or, at least, users with the appropriate access set at the template level) to be able to edit other fields on the page.

The description on the settings tab makes it look like setting 'system' status will achieve this: "System: Non-deletable and locked ID, name, template, parent"

However setting system status disables ALL editing by non-superusers, even when all the correct permissions are given, so that description seems misleading.

(a) Am I misunderstanding something?

(b) Is there a simple way of achieving my objective?

Link to comment
Share on other sites

For the title field you can enable access control in template context to limit editability by role.

For deletion you can revoke the delete permission per template per role.

For the settings tab there is a $template->noSettings property: https://github.com/processwire/processwire/blob/38a5320f612a4b38a7353265343219f224f20e6d/wire/core/Template.php#L100

You can conditionally set this with a hook for non-superusers:

$wire->addHookBefore('ProcessPageEdit::execute', function(HookEvent $event) {
	/** @var ProcessPageEdit $ppe */
	$ppe = $event->object;
	/** @var Page $page */
	$page = $ppe->getPage();
	
	if($page->template == 'my_template' && !$event->wire()->user->isSuperuser()) {
		$page->template->noSettings = 1;
	}
});

 

  • Like 2
Link to comment
Share on other sites

Thanks @Robin S. I also need to prevent changing the parent by moving in the page tree, which I had previously sorted here - 

 

The combination of your hook with my second hook in that link seems to work well.

  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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