Jonathan Lahijani

Modify "Custom Page Label Format" via hook/API

4 posts in this topic

I have a Page Reference field (ASM Select) and I am utilizing the "Custom Format" for the "Label field".  However even the custom format itself is a bit limiting for a particular use case I have.  Is it possible to hook into it and modify the output cleanly with PHP?  I can't seem to find a proper hook.

Somewhat related... it's possible to do this for the Tree page labels via ProcessPageListRender::getPageLabel.

Share this post


Link to post
Share on other sites

Labels are generated inside InputfieldPage::getPageLabel method (\wire\modules\Inputfield\InputfieldPage\InputfieldPage.module), but unfortunately it's not hookable. You can prefix the method with 3 underscores ___ to enable hooking (it works that way) but when you update the core it will be overwritten with unhookable version. Feel free to make a feature request on Github.

// /site/ready.php

wire()->addHookAfter('InputfieldPage::getPageLabel', function (HookEvent $e) {
    $field = $e->object;
    if($field->name !== 'myPageField') return;
    
    $page = $e->arguments(0);
    $e->return = "$page->title @ {$page->parent->title}";
});

 

1 person likes this

Share this post


Link to post
Share on other sites

I haven't tested it much but it looks like you can hook Page::getMarkup()

$wire->addHookAfter('Page::getMarkup', function(HookEvent $event) {
    $page = $event->object;
    if($page->template->name !== 'TEMPLATE(S)_USED_IN_YOUR_PAGE_FIELD') return;
    $out = $page->title;
    // add more stuff to $out using $page
    $event->return = $out;
});

 

1 person likes this

Share this post


Link to post
Share on other sites

Also consider InputfieldSelectizeMultiple, it can support any complex markup for the select items, and any field, subfield, sub-subfield etc..

2 people like this

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.