Jump to content

How get the name of a DOM element for use in hook


abmcr
 Share

Recommended Posts

Schermata 2021-11-05 alle 19.06.13.png

I want to change the label of the View anchor and i have created an hook as

 

$wire->addHookAfter('ProcessPageEdit::buildForm', function(HookEvent $event) {
    $form = $event->return; 
    $ppe = $event->object; 
    $page = $ppe->getPage();
    if(in_array($page->template->name, ['trail'])) {
        $button = $form->getChildByName('_ProcessPageEditView'); // How get this value??????
        if($button) $button->value = 'My new text'; // Change the text
    }
});

but how can get the exact reference to element; as you see in the attached image i have used the ID of the element  but this is not the correct way because the code don't work...

What is the correct logic for get the name for using it in an hook code?

 

Thank you

Link to comment
Share on other sites

  • abmcr changed the title to How get the name of a DOM element for use in hook

Hi, I’m on my phone, but I think you might want to hook ProcessPageEdit::getSubmitActions and change the label in the returned array. It will look like this:

$event->return['view']['label']

Apologies if this is not 100% correct – I’m looking through the code on a first gen iphone SE ?

You should also be able to change the text using ProcessWire’s translation capabilities.

  • Like 1
Link to comment
Share on other sites

I want also change the label "view" in PageList: i have searched into the code and the data for showing the buttons is created in the ProcessPageList.js; the data used in this file is send from ProcessPageList.module in the public function renderReady not hookable.... 

It is possible in a way i not suppose, achieve my purpose? Thanks

Schermata 2021-11-08 alle 17.45.37.png

Link to comment
Share on other sites

Thank you Zeka... i have not clear the workflow of processwire admin .... Thank you : now i have a new  info ?

This is my working code

$wire->addHookAfter('ProcessPageListActions::getActions', function($event) {
    $actions = $event->return;
    $page = ( $event->arguments('page'));
    if(in_array($page->template->name, ['myTemplate'])) {
        $actions['view']['name'] = 'My label';
    }
    $event->return = $actions;
});

 

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