Jump to content

Change labels for Add New bookmarks


bora
 Share

Recommended Posts

I tried the new bookmark system in the dev branch (2.6.17). It's great for quick access, but I have too many parents with the same name "Products" under different parents like "office/products"  "home/products" etc.

So I needed to change the labels for add new button on Tree view.

After a little bit poking I found a solution, so I'm sharing for anyone who might need.

public function init()
{
    //hooking the event for editing list of bookmarked pages from my SiteHelper module
    $this->addHookAfter("ProcessPageAdd::executeNavJSON", $this, 'bookmarksEvent');

}

    public function bookmarksEvent(HookEvent $event)
    {

        $eventReturn = $event->return;

        foreach($eventReturn['list'] as $key => $item) {
            //if its a parent url for adding
            if( strpos($item['url'],'parent_id') > 0 ) {
                $url = str_replace('?','',$item['url']);
                parse_str( $url );

                //get page in the bookmark
                $page = wire('pages')->get($parent_id);

                //my scheme is for a label format: parentTitle - title
                $newLabel = "{$page->parent->title} - $page->title";

                $item['label'] = $newLabel;
                $eventReturn['list'][$key] = $item;
            }
        }

        $event->return = $eventReturn;

    }
  • Like 3
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

×
×
  • Create New...