Jump to content

Loading input field selectable pages in PageTable field just after page creation


LAPS
 Share

Recommended Posts

I'm struggling on this hook that would populate selectable pages in PageTable Edit modal form also when a new page is just created.

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  $page = $event->arguments('page'); // this is a PageTable page i.e. it's created through an InputfieldPageTable field
  $form = $event->object;

  if($form->hasField != 'selectable_page_field') return;

  bd($page);
  // e.g. output: Page('id' => 123, ...)

  $related_page = wire('pages')->get("template=tmpl-name, page_table_field.id={$page->id}");
  
  bd($related_page);
  // output (when $page is just created/added): 
  // => NullPage('id' => 0, ...)
  // output (when $page is reloaded e.g. the edit page form is refreshed):
  // => Page('id' => 456, ...)
  //
  // Note: get() behaves differently depending on the page process flow: add and edit!
  // The problem may be caused by the page_table_field (InputfieldPageTable field) which
  // doesn't create the page until e.g. the related modal window is closed and re-opened,
  // and/or save button is hit in it.
  
  //...
});

As expected, the above hook runs every time the Page Edit form using selectable_page_field is rendered.

However it doesn't get the $related_page during the creation time because get() returns NullPage(), but the same code does get $related_page in all cases other than the creation time e.g. in Page Edit view after refreshing or closing-opening the modal window.

 

Is there a way to make the get() to work even during page creation?

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