DrQuincy Posted July 16 Share Posted July 16 Just that…once a page is created I do not want to allow the page slug/name to ever be changed. So the name should be available no the initial page during creation but not after that. Is that easy enough to do? Thanks! Link to comment Share on other sites More sharing options...
bernhard Posted July 16 Share Posted July 16 Yes, quite easy ? $wire->addHookAfter( 'ProcessPageEdit::buildForm', function (HookEvent $event) { $form = $event->return; $page = $event->process->getPage(); // if page is young enough don't lock the page name field $lockPagenameAfterSeconds = 60; if ($page->created > time() - $lockPagenameAfterSeconds) return; // get field and set status to collapsed + locked $field = $form->get('_pw_page_name'); $field->collapsed = Inputfield::collapsedLocked; $field->notes = 'Can not be changed any more'; } ); Alternatively you could use $page->meta() to set a flag at some point instead of waiting 60s. 4 Link to comment Share on other sites More sharing options...
DrQuincy Posted July 16 Author Share Posted July 16 Awesome, and thanks for the fast response! Link to comment Share on other sites More sharing options...
Jan Romero Posted July 16 Share Posted July 16 I could have sworn there was a $config->advanced option in template settings to disable this, but apparently there is only one to prevent a page from being moved. Of course, you might want to do that, too, if you need stable urls. Also note Bernhard’s hook only hides the field from the edit form, but it could still be changed through code or even (I believe) with simple browser dev tools trickery on the part of an editor. To prevent it even through the API you could probably hook into Pages::savePageOrFieldReady: https://processwire.com/api/ref/pages/save-page-or-field-ready/ 2 Link to comment Share on other sites More sharing options...
DrQuincy Posted July 16 Author Share Posted July 16 Thank you! Link to comment Share on other sites More sharing options...
da² Posted July 16 Share Posted July 16 (edited) 3 hours ago, bernhard said: // if page is young enough don't lock the page name field I would just use if ($page->isNew()). This is true when we are on the very first page form with only the title and name fields. Then it's false. This is the same as if (!$page->id). Edited July 16 by da² 2 Link to comment Share on other sites More sharing options...
DrQuincy Posted July 17 Author Share Posted July 17 Thanks everyone. I have also noticed that $page->created === 0 works too. 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