neosin Posted April 6, 2018 Share Posted April 6, 2018 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 More sharing options...
szabesz Posted April 7, 2018 Share Posted April 7, 2018 (edited) 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 April 7, 2018 by szabesz link's href fix Link to comment Share on other sites More sharing options...
gebeer Posted April 7, 2018 Share Posted April 7, 2018 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 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. 3 Link to comment Share on other sites More sharing options...
neosin Posted April 7, 2018 Author Share Posted April 7, 2018 @szabesz @gebeer hi thank you both I am looking at how to do this only in the Admin CMS, is it possible? it seems the code you shared is for frontend, can it be done for admin cms ? Link to comment Share on other sites More sharing options...
szabesz Posted April 7, 2018 Share Posted April 7, 2018 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". 1 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