netcarver Posted October 16, 2014 Share Posted October 16, 2014 Can anyone point me in the right direction to rename the "content" tab of pages in the admin page editor? I wan't to rename it when editing pages of one of my templates. It wouldn't surprise me if I had to hook a render method somewhere. I've googled for this but not found anything particularly useful. Thanks in advance! Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 16, 2014 Share Posted October 16, 2014 could you try this: $this->addHookAfter("ProcessPageEdit::buildForm", $this, "tryThis"); public function tryThis(HookEvent $event) { $form = $event->return; $content = $form->find("id=ProcessPageEditContent")->first(); $content->label = 'steve'; } sitting on the livin' room giving the baby milk, so no time to test what I wrote. 4 Link to comment Share on other sites More sharing options...
netcarver Posted October 16, 2014 Author Share Posted October 16, 2014 @Martijn Thanks for the snippet. Here's the result... ...not quite what I'm after - but interesting. Enjoy your time with your little one. 1 Link to comment Share on other sites More sharing options...
mr-fan Posted October 16, 2014 Share Posted October 16, 2014 languages: /wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module translate or change "content" regards mr-fan 1 Link to comment Share on other sites More sharing options...
netcarver Posted October 16, 2014 Author Share Posted October 16, 2014 @mr-fan Thanks for the reply. I thought about that already but it does it for all labels. I only want to do it for the labels of one particular template's children. I'm actually getting a little closer to this now as Martijn's answer has pointed me in the right direction; which seems to be to hook buildFormContent(). Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 16, 2014 Share Posted October 16, 2014 Looks like protected,hmmm. You could play it Dirty if you don't mind and go for AdminCustomFiles and change it with Javascript. (Don't tell anyone) But I do like to know how to change this the 'right' way. 1 Link to comment Share on other sites More sharing options...
jordanlev Posted October 16, 2014 Share Posted October 16, 2014 Furthermore, does anyone know how I can actually removing the visual "tab top" altogether (not the contents of the tab, just the rectangle at the top). This is because I have a template set to have "no settings" ($template->noSettings = 1), so there is *only* the content tab being shown... and it is redundant and wastes space when I show the edit fields in a modal. Link to comment Share on other sites More sharing options...
netcarver Posted October 16, 2014 Author Share Posted October 16, 2014 (edited) From the source code it looks like the title of the first tab is set by adding the title attribute to the form in buildFormContent. I can successfully overwrite that attribute with this code... wire()->addHookAfter("ProcessPageEdit::buildFormContent", $this, "tryThis"); public function tryThis(HookEvent $event) { $form = $event->return; $new_title = $this->_("Personal Info"); $title = $form->attr('title'); $this->message("Updating form title [$title -> $new_title]"); $form->attr('title', $new_title); } And I've verified (by single stepping the code) that the attribute gets overwritten and returned and even makes it through several stages of hook return. Despite this, as Martijn mentioned, it seems to be protected as it still gets rendered as "Content" even with the change. I have no idea why at the moment. Update 1: Ok, it is getting saved in an instance variable ($this->tabs[$id] = $title) and it is that variable that's being used to render the tab via WireTabs. Will need to look at hooking execute() and doing a replace on the rendered output. Not a pretty way to do it - but at least I know it should work. Update 2: Just to confirm, I have succeeded in doing this using an after hook on ProcessPageEdit::execute - but it's not a particularly elegant solution. Edited October 16, 2014 by netcarver 4 Link to comment Share on other sites More sharing options...
jordanlev Posted October 16, 2014 Share Posted October 16, 2014 @netcarver, Would you mind sharing the code you used to successfully override the title (as mentioned in your "update 2")? It would be quite helpful to me. Thanks! Link to comment Share on other sites More sharing options...
netcarver Posted October 16, 2014 Author Share Posted October 16, 2014 @jordanlev Sure, but be warned, my code currently does it across all pages you edit as I've not added anything to restrict it to just the template I'm after. In fact, I'm now worried that I won't be able to do it on a per-template basis this way. But the day is late and I'll worry about that tomorrow. In the meantime, here it is... public function init() { wire()->addHookAfter("ProcessPageEdit::execute", $this, "tryThis"); } public function tryThis(HookEvent $event) { $render = $event->return; $event->return = str_replace("Content</a>", "New Title</a>", $render); } That's part of a little auto-loaded module. Oh, yeah, it also currently updates any links that end with the word "Content" but that's fixable with a more complex match. 2 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 17, 2014 Share Posted October 17, 2014 Big thanks steve, you've solved this mystery ! Link to comment Share on other sites More sharing options...
netcarver Posted October 17, 2014 Author Share Posted October 17, 2014 @Martijn, I've unmarked this as solved as it's not quite the whole story. If I put a breakpoint in my hook routine I can examine the $event object and I can see all the information I need to be able to make a rename decision as the $event object's page's template has a title that I want to compare against - but it doesn't seem possible for me to access that information via the API using $event->object->page->template->title which always gives a blank, despite me being able to inspect the data in the debugger. I suspect that some of these fields are protected or private members of the $event->object. If I do find a full solution I'll post it. 2 Link to comment Share on other sites More sharing options...
netcarver Posted October 17, 2014 Author Share Posted October 17, 2014 Ok, as promised, here's my solution. public function init() { wire()->addHookAfter("ProcessPageEdit::execute", $this, "tryThis"); } public function tryThis(HookEvent $event) { $render = $event->return; $template_name = "xyz"; // Change this to match the exact template name of pages you want to apply tab-renaming to. if (false !== strpos($render, "template_{$template_name} ")) { $render = str_replace("Content</a>", "New Title</a>", $render); $event->return = $render; } } I'm not totally satisfied with it as it makes no allowance for possible changes to the default string or the internationalisation of it - but it is still relatively easy in PW. I've raised an issue about this over on the home repo as I think PW should be able to solve this more elegantly. It will do for this current site as I only expect to use the English default string for the content tab. 4 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted October 17, 2014 Share Posted October 17, 2014 Now I see.. Thats dirty Great you've solved this Steve ! Thanks about the issue rapport ! 1 Link to comment Share on other sites More sharing options...
renobird Posted October 17, 2014 Share Posted October 17, 2014 Thanks for this Steve. I've been cheating and changing the names via JS - which is clumsy at best. 1 Link to comment Share on other sites More sharing options...
netcarver Posted October 18, 2014 Author Share Posted October 18, 2014 Thanks for that guys. This solution is quite brittle and may break with future releases of PW as it relies on the current way that PW marks up the submission form with a class that contains the template name. If PW ever stops adding that markup class, this will break. Also take note of that space after the end of the template name in the search string - which is needed if you have templates with matching substrings: like "patient" and "patients" where both would match if you tried to apply it only to "patient" and don't have the space at the end. I'd much rather be able to access the template name directly somehow from the hook method (preferably as the form is built rather than post-rendered) but I just couldn't find the right way to access it. 1 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