Jump to content

Admin search results link to view page instead of edit page.


elabx
 Share

Recommended Posts

Hi people!

Is there a way to hook into the way the results of the admin search results are rendered? I'd love to make the links to the pages in the list go to the "view" page instead of the "edit" page specially in modules rendering a Process module. For example, look for the Fields page, and it will link you to edit the Field page. 

I've looked into the ProcessPageSearch module but can't find any javascript that renders the actual list, any clue?

Thanks for further help!

Link to comment
Share on other sites

$this->addHookAfter('ProcessPageSearch::executeFor

You can see here: https://github.com/adrianbj/AdminRestrictBranch/blob/838858fd36a78df808b7690b4cddcb3a6c25ffa3/AdminRestrictBranch.module#L167-L180

where I have removed items from the search results, but you could easily use array_map to search and replace edit with view links in the returned array of matches.

Hopefully this will help to get you going.

  • Like 1
Link to comment
Share on other sites

@elabx - thought I'd take a quick look into what is actually required and this seems to work well:

$this->addHookAfter('ProcessPageSearch::executeFor', function($event) {
    $response = $event->return;
    $responseArray = json_decode($response, true);
    $matches = $responseArray['matches'];
    $i=0;
    foreach($matches as $match) {
        if($match['type'] == 'Pages' && strpos($match['path'], $this->config->urls->admin) === false) $matches[$i]['editUrl'] = $match['path'];
        $i++;
    }
    $responseArray['matches'] = $matches;
    $event->return = json_encode($responseArray);
});

Note that it only changes the link if the match has type of "Pages" and also doesn't point to an admin url.

Let me know if this works at your end ok.

  • Like 6
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...