Jump to content

pagefield selectable pages "custom find" or?


neosin
 Share

Recommended Posts

This issue is related to the backend only, not frontend templates.

I have a pagefield called "programs_list" that displays a list of "programs" and this works fine however the ID's assigned to those items are "PW" page id's.

How can I match a selected item to a custom field value instead of the default PW ID ?

I've imported a large volume of data using the API and this data has a field called "program_id" that I need to match with the "programs_list" pagefield.

The "programs_list" pagefield uses a template that contains a "legacy_id" field that I need to match up with the imported datas "program_id" so that it shows the correct item as being selected.

Any examples on how to go about achieving the desired result would be much appreciated.

thanks in advance

 

 

Link to comment
Share on other sites

Hi, If I understand you right, you need to hook into getSelectablePages. I presume you use ASM select, so one example can be found here:

https://processwire.com/talk/topic/15267-best-way-to-setup-room-availability/?do=findComment&comment=136584

Also, you can perform a google search like : https://www.google.hu/search?q="getSelectablePages"+site%3Aprocesswire.com%2Ftalk

 

Edited by szabesz
link's href fix
Link to comment
Share on other sites

I thin what you are looking for is the "Custom PHP code" in the Input tab of the field cnfiguration screen for your programs_list field

5ac8be6e244c9_2018-04-07-194801.thumb.png.23339c3992f74c3764e8ab064987d6e4.png

In my case the field name is "myplaces"

Now Go and insert this hook into site/ready.php

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->hasField == 'programs_list') {
    $page = $event->arguments('page');
    $event->return = $event->pages->find("template=yourTemplateForProgramPages, program_id={$page->legacy_id});
  }
});

This gets the legazy_id of the page that you are currently editing and then finds all program pages with that id in field program_id.

  • Like 3
Link to comment
Share on other sites

4 minutes ago, neosin said:

Admin CMS

Yeah, we got that ;) Since inputfields are used by the admin, hooking into InputfieldPage::getSelectablePages is what makes ASM selects (and other multi page inputfields) "customizable".

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