Juergen Posted October 25, 2017 Share Posted October 25, 2017 With this little tutorial I want to show you how you can change the text of the add new button inside the children tab. This is the default button text which will be rendered on every template where children are allowed: And this is how it look likes after the manipulation: So it is a little bit customized. Maybe you can make it also with JS but I show you a way to change it via a hook inside the ready.php. Copy and adapt the following code into your ready.php. $pages->addHook('ProcessPageEdit::buildForm', function($event) { $page = $this->pages->get($this->input->get->id); $template = $this->pages->get($this->input->get->id)->template; //run the code only on the following templates -> adapt it to your needs if(($template == "event_events") || ($template == "event_dates") || ($template == "event_businessvacations") || ($template == "event_specialbusinesshours")) { $form = $event->return; $field = $event->object; $href = $this->config->urls->admin.'page/add/?parent_id='.$page; $field = $this->modules->get('InputfieldButton'); $field->attr('id+name', 'add_event'); $field->attr('class', $field->class); $field->attr('value', 'Add new event'); $field->attr('href',$href); $field->attr('icon','plus-circle'); $form->insertAfter($field, $form->get("AddPageBtn")); $form->remove($form->get("AddPageBtn")); } }); You can use the code as it is, but you have to adapt the if conditions to run it only on the templates you want. In my case I run it on 4 different templates. You can also change the icon if you want. Hope this will be helpful for some of you! 4 Link to comment Share on other sites More sharing options...
Robin S Posted October 25, 2017 Share Posted October 25, 2017 There is a little error in your hook code: //... $field = $event->object; $href = $this->config->urls->admin.'page/add/?parent_id='.$page; $field = $this->modules->get('InputfieldButton'); //... In this hook, the event object is ProcessPageEdit, not a field. And you also overwrite $field two lines below. Rather than removing the existing button and adding a new one, you can change the text of the existing button. Here is another way it could be done: $wire->addHookAfter('ProcessPageEdit::buildFormChildren', function(HookEvent $event) { $form = $event->return; // The InputfieldWrapper on the "children" tab $ppe = $event->object; // ProcessPageEdit $page = $ppe->getPage(); // ProcessPageEdit contains a method to get the page being edited if(in_array($page->template->name, ['event_events', 'event_dates', 'event_businessvacations', 'event_specialbusinesshours'])) { $button = $form->getChildByName('AddPageBtn'); // Get the button if($button) $button->value = 'Add new event'; // Change the text } }); 5 Link to comment Share on other sites More sharing options...
Juergen Posted October 26, 2017 Author Share Posted October 26, 2017 Thanks @Robin S, your version is much cleaner. 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