I'm working on a plugin that dynamically adds some form inputs and form data to existing forms. These forms could also be on modular pages. I need to read the header data (frontmatter) of the pages that include the relevant form (or forms). Doing it this way works if the form is included in a regular page:
public function onFormInitialized(Event $event) {
$page = $this->grav['page'];
$header = $page->header();
/* ... */
}
However, if the form is included in a modular page, then the first line, $this->grav['page'] will cause the entire page to display a 404.
What's the right way to achieve this that will work for any type of page?