Jump to content

Restrict pages in "insert link" autocomplete dialog


bartelsmedia
 Share

Recommended Posts

The autocomplete feature of the "link insert" is absurdly useful. However it quickly becomes flooded with similar sounding pages in my setup.

Is there a way to filter/exclude certain branches of the page tree from here?

noshow.thumb.png.15222859212a9122bceac196527f3fb4.png

I tried this setting for the unwanted "/menu/" branch but it still shows up:

2019-03-28_1414.thumb.png.9d8745f8a93a69a14d4086147ef0b0a0.png

 

In an ideal world, each "insert link" dialog would be customizable. Example: The "insert page"dialog fro a page under "/faq/" would show only URL matches of page tree branch "/tech/", etc.

Does this make sense?

Link to comment
Share on other sites

You can use a hook like this in /site/ready.php:

$wire->addHookBefore('InputfieldPageAutocomplete(name=link_page_url)::render', function(HookEvent $event) {
	$inputfield = $event->object;
	// Get the page being edited
	$page_id = $event->wire('input')->get->int('id');
	$edited_page = $event->wire('pages')->get($page_id);
	// If the edited page is one that you want to target
	if($edited_page->template == 'basic_page') {
		// Append to the findPagesSelector property to exclude pages you don't want to match
		$inputfield->findPagesSelector .= ', has_parent!=/menus/';
	}
});

 

  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...