Skip to content

Manipulating the output of Admin Search Box Autocomplete is not working anymore (PW >= 3.0.108) #675

@gingebaker

Description

@gingebaker

Short description of the issue

Since PW >= 3.0.108 I am not able to hook in the Admin Search Box Autocomplete anymore. I am trying to manipulate the output of the standard title field to some customized output (other fields, concatenating fields, etc.)

Expected behavior

Before 3.0.108 I used:

$this->addHookAfter('ProcessPageSearch::executeFor',$this,'executeFor');

and for example this hook to get this behaviour:

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);
                }
            }
        }
    }

Actual behavior

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

Optional: Suggestion for a possible fix

This could be solved by hooking the ProcessPageSearchLive::find() or ProcessPageSearch::findPages() function to manipulate the returned $items or $matches array. Or even the ProcessPageSearch::execute() function?

There is a related request to also use the standard Page List Display format from template settings in the Admin Search Box. see here: processwire/processwire-requests#214 wich looks like a good addon too.

It would be great to get this working again! Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions