BillH Posted July 28, 2020 Share Posted July 28, 2020 I'm trying to change the name of the View tab (client request) and can't work out how to get at the label property. The closest I've got to it is the url property. I've tried many things, including this: $this->addHookAfter('ProcessPageEdit::buildFormView', function($event) { $arguments = $event->argumentsByName(); bd($arguments); // Result: only 'url' $viewTab = $event->return; bd($viewTab); // Result: null }); And this: $this->addHookAfter('ProcessPageEdit::buildForm', function($event) { $form = $event->return; $viewTab = $form->find("id=ProcessPageEditView")->first(); bd($viewTab); // Result: false }); Does anyone know what I should be doing? Link to comment Share on other sites More sharing options...
adrian Posted July 28, 2020 Share Posted July 28, 2020 ->first() doesn't work for the View tab - try it without and you should be ok. 1 Link to comment Share on other sites More sharing options...
BillH Posted July 28, 2020 Author Share Posted July 28, 2020 Thanks @adrian This works: $viewTab = $form->find("id=ProcessPageEditView"); However, I get the following, which doesn't have any attributes I can change, or anything that seems to correspond to the label or name of the tab: I think I must be getting something else wrong too! Link to comment Share on other sites More sharing options...
dragan Posted July 28, 2020 Share Posted July 28, 2020 There are hints in this thread: https://processwire.com/talk/topic/7971-renaming-the-content-tab-when-editing-pages-of-a-given-template/ As mentioned there, this is a working, albeit very hacky solution: (content instead of view tab) // site/ready.php wire()->addHookAfter("ProcessPageEdit::execute", function($event) { $render = $event->return; $template_name = "basic-page"; // 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>", "Content is King</a>", $render); // EN $render = str_replace("Inhalt</a>", "Inhalt ist Kaiser</a>", $render); // DE $render = str_replace("Contenu</a>", "Le roi, c'est le contenu</a>", $render); // FR $event->return = $render; } }); 1 Link to comment Share on other sites More sharing options...
BillH Posted July 28, 2020 Author Share Posted July 28, 2020 Many thanks @dragan, that works fine. The View tab is very slightly complicated by having a dropdown menu, so in case it's useful for anyone, here's a version that deals with that (changes "View" to "Preview"): wire()->addHookAfter("ProcessPageEdit::execute", function($event) { $render = $event->return; $template_name = "basic-page"; // Change to the relevant template name if (false !== strpos($render, "template_{$template_name} ")) { $render = str_replace("View<span id='_ProcessPageEditViewDropdownToggle'", "Preview<span id='_ProcessPageEditViewDropdownToggle'", $render); $render = str_replace("Exit + View</a>", "Exit + Preview</a>", $render); $event->return = $render; } }); Replacing just "View<span" would probably be enough, but perhaps there's a tiny risk it'd be in a rich text field as well. Link to comment Share on other sites More sharing options...
Robin S Posted July 28, 2020 Share Posted July 28, 2020 @BillH, another way to change such labels is to install LanguageSupport (you don't need to install any of the related language modules if you're not using multi-language in your site). Then edit the Default language under Setup and "translate" any strings in the ProcessPageEdit.module that you want to change. 2 Link to comment Share on other sites More sharing options...
BillH Posted July 29, 2020 Author Share Posted July 29, 2020 Thanks for the suggestion @Robin S Seems like a nice way of doing it. There no risk (however remote) of accidentally replacing something that shouldn't be replaced, and it's more resilient to change. And I suspect there are going to be more requests to change labels and the like in future, so this could be a good approach for keeping things well organised. 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