Jump to content

Disable editing of "Name" (ie, slug) field


benjaminE
 Share

Recommended Posts

Is there any way to disable a user from being able to edit the Name field - that is the field that determines that page's URL?

I've hidden the title field, so that can't be edited.

I know you disable editing of a page, which would solve this. However, disabling a role from editing a page stop that role from being able to sort its children (see here) and I do want to keep that behavior.

Any advice would be kindly appreciated!

b

Link to comment
Share on other sites

I think PageRenameOptions should be able to help you out - just use the "Prevent Manual Changes" option.

Or, you could make use of Martijn's AdminCustomFiles to insert this JS (which is what PageRenameOptions uses):

$(document).ready(function() {
    $('.InputfieldPageName input').attr("readonly", "readonly");
});

You would attach it to: ProcessPageEdit

  • Like 4
Link to comment
Share on other sites

You can also use the following hook (inside a module):

public function ready() {
  if (!$this->user->isSuperUser())
    $this->addHookAfter('ProcessPageEdit::buildFormSettings', function($event) {
      $wrapper = $event->return;
      $pageName = $wrapper->get('_pw_page_name');
      $event->return = $wrapper->remove($pageName);
    });
}

As written, the module allows only a superuser to change the name, but using a custom permission would probably make more sense, e.g.,

if (!$user->hasPermission('page-edit-name')) {
  ...
}
  • Like 2
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

×
×
  • Create New...