Jump to content

Modifying the back-end page search


cjx2240
 Share

Recommended Posts

I'd like to make a tiny tweak to the ajax page search in the top right corner of the CMS.

All I want to do, is add the page's rootParent to the result dropdown. This is because due to the unique structure of a certain site, lots of pages have the same name, it's not clear which one to click on.

Can anyone help me out with this please?

Link to comment
Share on other sites

Would showing the path instead of the title be okay ? I thought of a hook first but you could do the trick with a bit of CSS

ul.pw-dropdown-menu-shorter li.ui-menu-item a::before {
  content: attr(title);
  margin-right: 3px;
}

ul.pw-dropdown-menu-shorter li.ui-menu-item a span {
  display: none;
}

(hopefully it doesn't target anything else, but from my quick testing it looks ok !)

Before: 115547922_Screenshotfrom2021-02-2521_36_38.png.436b720f6eeb1bdfe2397e99888be886.png After: 1818762104_Screenshotfrom2021-02-2521_37_12.png.9c83ced58c98b332e3940841edbda090.png

  • Like 4
Link to comment
Share on other sites

6 hours ago, cjx2240 said:

This is because due to the unique structure of a certain site, lots of pages have the same name, it's not clear which one to click on.

The page path is in the title attribute, so you can hover on results to see the path in the browser tooltip:

2021-02-26_095234.png.b410aef4448cd6a65fd0092eb520bbf2.png

PW doesn't make it easy to manipulate the markup of admin search results. You could try the hook below in /site/ready.php to append the root parent title to the result title:

$wire->addHookBefore('ProcessPageSearchLive::execute', function(HookEvent $event) {
	$event->wire()->addHookAfter('FieldtypePageTitle::wakeupValue', function(HookEvent $event) {
		$page = $event->arguments(0);
		// Limit by template or some other property of $page
		if($page->template == 'basic_page' && !$page->get_original_title) {
			$root_parent = $page->rootParent;
			// Set custom page property to avoid affecting root parent title
			$root_parent->get_original_title = true;
			// Append root parent title
			$event->return .= " (Root parent: {$root_parent->title})";
		}
	});
});

2021-02-26_095831.png.b2deeecbd5dfa9731a88cbce438f0a86.png

Edited by Robin S
code tweak
  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Some notes on this topic:

Spoiler
On 2/25/2021 at 9:59 PM, Robin S said:

 

$wire->addHookBefore('ProcessPageSearchLive::execute', function(HookEvent $event) {
	$event->wire()->addHookAfter('FieldtypePageTitle::wakeupValue', function(HookEvent $event) {
		$page = $event->arguments(0);
		// Limit by template or some other property of $page
		if($page->template == 'basic_page' && !$page->get_original_title) {
			$root_parent = $page->rootParent;
			// Set custom page property to avoid affecting root parent title
			$root_parent->get_original_title = true;
			// Append root parent title
			$event->return .= " (Root parent: {$root_parent->title})";
		}
	});
});

The example above in the spoiler does not seem to work as expected (ProcessWire 3.0.184).

What works for me is this: https://github.com/processwire/processwire-issues/issues/675#issuecomment-420958397

Also worth reading this discussion: https://processwire.com/talk/topic/19781-issue-with-hooking-processpagesearchexecutefor-and-the-new-search-feature-in-pw-30108/

 

 

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