Jump to content

'InputfieldPage::getSelectablePages' and ajax loaded field


Jonathan Lahijani
 Share

Recommended Posts

I have a page field that I am hooking into and providing the custom dropdown values like this:

$this->addHookAfter('InputfieldPage::getSelectablePages', function(HookEvent $event) {
  if($event->object->hasField == 'my_page_field') {
    $ids = [];
    foreach(wire('pages')->find("...") as $p) {
      $ids[] = $p;
    }
    $event->return = $ids;
  }
});

Due to the nature of my site, the amount of items that will populate in that dropdown field will be quite high (over 2000 pages).  Due to this high amount of pages in that dropdown, the PW admin slows down quite a bit (extra 2 seconds) on edit pages that utilize that field.  To counteract this, I have made that field have the Visibility Presentation of Closed + Load when opened (AJAX), however because I am using the hook described above, it will still load the pages even if the field has not yet been opened.

So my question is, how do I improve the the hook above to execute only after the field has been opened?

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