Jump to content

Changing the label of the View tab


BillH
 Share

Recommended Posts

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

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:

image.png.41405b5906502db7a01d5c5ea0f3dee1.png

I think I must be getting something else wrong too!

Link to comment
Share on other sites

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;
    }

});

 

  • Like 1
Link to comment
Share on other sites

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

@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.

2020-07-29_103310.png.55150aafdc4f54ac3d56d6448a67eba5.png

2020-07-29_103755.png.4cbdb3bae44c394e776aa97016a192e8.png

2020-07-29_103821.png.cd3aa462190557a0ad05bd1972d21a9f.png

2020-07-29_103849.png.4e5289dd41d5310062c4d06c260a37cc.png

  • Like 2
Link to comment
Share on other sites

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

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...