Jump to content

Setting the name field to "Always collapsed"


sosoba
 Share

Recommended Posts

First of all i'd like to say hello to all the community!

Me and a co-worker are fresh users of Processwire. We've been wandering trough various cms's but this is a really high quality enviroment. Both flexible and powerful. I suspect we'll use it for many sites to come...

I also wanted to share the site that was created (almost finished) with this fantastic CMS. Thanks Ryan! :)

www.concinaprata.org

Sorry but only Italian content.

Back to the topic, the question i need answer to is: How can i set the name field visibility to Always collapsed? I noticed that my client, when creating pages, can't resist the urge to modify that field and that will surely create problems with the seo. 

I tried searching in the fields page, but name isn't listed there. Even in the database i couldn't find it...and i'd prefer not to touch core files. So i apologise beforehand if it was a crystal clear thing and i didn't see it!

  • Like 1
Link to comment
Share on other sites

Wel



Welcome sosoba!

This would be possible by making a hook to any of the the form building methods in ProcessPageEdit.module. All methods with three underscores are hookable. All about hooks.

Take the HelloWorld.module and add this hook to the init()

$this->addHookAfter('ProcessPageEdit::buildFormSettings', $this, 'buildFormSettings');

And then add this function to the class.

public function buildFormSettings(HookEvent $event){
    $fieldset = $event->return; // get the fieldwrapper returned
    $field = $fieldset->get("_pw_page_name"); // get the name field
    $field->collapsed = Inputfield::collapsedYes; 
}
  • Like 5
Link to comment
Share on other sites

Name is not a normal field, so it doesn't even appear when you show build-in fields. I don't think you can't do this in an elegant way. The non elegant way is with javascript.

Still, I think the most elegant way of all is telling the client to leave it alone :)

edit:

there you have it, Soma to the rescue! I keep my second statement though ;)

Link to comment
Share on other sites

Welcome sosoba!

This would be possible by making a hook to any of the the form building methods in ProcessPageEdit.module. All methods with three underscores are hookable. All about hooks.

Take the HelloWorld.module and add this hook to the init()

$this->addHookAfter('ProcessPageEdit::buildFormSettings', $this, 'buildFormSettings');

And then add this function to the class.

public function buildFormSettings(HookEvent $event){
    $fieldset = $event->return; // get the fieldwrapper returned
    $field = $fieldset->get("_pw_page_name"); // get the name field
    $field->collapsed = Inputfield::collapsedYes; 
}

Thanks!

I studied the page you mentioned (didn't know it) and all worked like a charm :)

With your code the name field was correctly hided in edit page, but also wanted it to be collapsed on page creation.

My solution was to transform the ProcessPageAdd::buildForm() method in a hookable one (___buildForm()) and add

$this->addHookAfter('ProcessPageAdd::buildForm', $this, 'buildFormSettings');
 

to the init() function you provided.

I know it is inelegant (and probably will create problems during update), but trying to attach the hook to the ProcessPageAdd::execute method, the only one hookable on page creation, was no good

Link to comment
Share on other sites

Wel

Welcome sosoba!

This would be possible by making a hook to any of the the form building methods in ProcessPageEdit.module. All methods with three underscores are hookable. All about hooks.

Take the HelloWorld.module and add this hook to the init()

$this->addHookAfter('ProcessPageEdit::buildFormSettings', $this, 'buildFormSettings');

And then add this function to the class.

public function buildFormSettings(HookEvent $event){
    $fieldset = $event->return; // get the fieldwrapper returned
    $field = $fieldset->get("_pw_page_name"); // get the name field
    $field->collapsed = Inputfield::collapsedYes; 
}
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...