gingebaker Posted August 13, 2018 Share Posted August 13, 2018 Hello I am having an issue with hooking the SearchBox in the Admin Interface in PW >= 3.0.108 where the new Search Features are added. I hooked: $this->addHookAfter('ProcessPageSearch::executeFor',$this,'executeFor'); to change the title format of specific pages in the SearchBox of the Admin. This looked something like this: public function executeFor($event) { $return = json_decode($event->return); if($this->input->get->admin_search) { $return = json_decode($event->return); if(isset($return->matches)) { $didChange = false; foreach($return->matches as $key => $match) { if($match->template == "templateX" || $match->template == "templateY") { // add vorname and nachname to title $matchPage = $this->pages->get($match->id); $return->matches[$key]->title = $match->title.' - '.$matchPage->get('nachname').' '.$matchPage->get('vorname'); $didChange = true; } } if($didChange) { $event->return = json_encode($return); } } } } The reason I am doing this is that on some special templates I don´t want to show only the title field of this template in the Search Autocomplete but show some other fields to get a better usability. Now with the new ProcessPageSearchLive.php Module it seems that this is not possible anymore? There are the two hookable functions ___renderList and ___renderItem, but the are only called by viewAll Output. So the code where I should hook into is somewhere in the findPages() function of ProcessPageSearchLive.php, but I could not find a way to Hook into and modify it? https://github.com/processwire/processwire/blob/dev/wire/modules/Process/ProcessPageSearch/ProcessPageSearchLive.php#L736 Is there a way to get this done as it was with the old search? Perhaps i am overseeing something? Thanks for any help! 1 Link to comment Share on other sites More sharing options...
Robin S Posted August 15, 2018 Share Posted August 15, 2018 Yes, it seems we have sadly lost the ability to manipulate the search results like that. I've used that approach a few times myself. Maybe you could make a GitHub request that Ryan make ProcessPageSearchLive::find() hookable? It looks like manipulating the $items array that the method returns could be a good solution. On 8/14/2018 at 1:17 AM, gingebaker said: The reason I am doing this is that on some special templates I don´t want to show only the title field of this template in the Search Autocomplete but show some other fields to get a better usability. And maybe add some thumbs-up support to this existing request too: https://github.com/processwire/processwire-requests/issues/214 ? 2 Link to comment Share on other sites More sharing options...
gingebaker Posted August 16, 2018 Author Share Posted August 16, 2018 Hello Robin Thanks for the reply. I just opened an Issue:https://github.com/processwire/processwire-issues/issues/675 I mentioned your request there and als gave him a thumbs up! 5 Link to comment Share on other sites More sharing options...
OLSA Posted August 16, 2018 Share Posted August 16, 2018 Hello gingebaker, in that situation, until the issue will be resolved, you can copy core module to site/modules and there change it to get working temporarily solution. If you want to do that, here are steps: 1) copy core ProcessPageSearch module from wire/modules/Process/ProcessPageSearch to site/modules/ 2) after it configure PW to use that variant (administration, Modules->Configure->PageSearch...). 3) inside ProcessPageSearchLive.php, execute() do small changes: public function execute($getJSON = true) { /** @var WireInput $input */ $input = $this->wire('input'); $liveSearch = $this->init(); if((int) $input->get('version') > 1) { // version 2+ keep results in native format, for future use $items = $this->find($liveSearch); } else { // version 1 is currently used by PW admin themes $items = $this->convertItemsFormat($this->find($liveSearch)); } $result = array( 'matches' => &$items ); // --- START if(count($result['matches'])){ foreach($result['matches'] as $key => $match) { if($match['template_label'] == "templateX" || $match['template_label'] == "templateY") { // add vorname and nachname to title $matchPage = $this->pages->get($match['id']); $result['matches'][$key]['title'] = $match['title'] .' - '.$matchPage->get('nachname').' '.$matchPage->get('vorname'); } } } //--- END return $getJSON ? json_encode($result) : $items; } Regards. 1 Link to comment Share on other sites More sharing options...
gingebaker Posted August 17, 2018 Author Share Posted August 17, 2018 Hello OLSA Just tried your temporarily solution. Works perfect, Didn´t know that I can replace core modules so easy! Thanks for the hint! regards, Link to comment Share on other sites More sharing options...
gingebaker Posted September 13, 2018 Author Share Posted September 13, 2018 Hi Ryan Just added a fix for this in 3.0.112. See the Issue here on github:https://github.com/processwire/processwire-issues/issues/675#issuecomment-420958397 I also added my final hook in the comments. regards, tom 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now