I have a form module that I would like to have on its own page, with no header, footer, etc.. I thought I was successful with adding hook_menu() and a page callback to render the form's block, then added hook_page_alter() to cycle through all available regions and unset them:
function mymodule_menu () {
$menuitems['myform-page'] = [
'title' => 'Survey Form',
'page callback' => 'mymodule_form_page',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
];
return $menuitems;
}
function mymodule_form_page (&$page) {
dpm($GLOBALS['_GET']['q']);
$current_path = $GLOBALS['_GET']['q'];
if ($current_path === 'myform-page') {
$module = 'mymodule';
$delta = 'mymodule_block';
$block = block_load($module, $delta);
$form_page = _block_get_renderable_array(_block_render_blocks(array($block)));
return $form_page;
}
}
function mymodule_page_alter (&$page) {
$current_path = $GLOBALS['_GET']['q'];
if ($current_path === 'myform-page') {
$regions = ['top','header','footer_1','footer_2'];
foreach($regions as $region) {
foreach($page as $key => $value) {
if ($region === $key) {
unset($page[$key]);
}
}
}
}
}
After all of that, I clear cache and visit the "myform-page", er, page. All the undesired regions are gone (though their HTML wrapper DIVs are still rendered, but I'm okay with hiding those with CSS). I leave that page, going to the front page, for example, then manually type in the address for "myform-page" in the browser and hit enter. The header and footer regions are back!
The "mymodule_page_alter" function only runs once and never again until I clear cache again. The "mymodule" block loads, looks, and functions exactly how I want it to, except for the regions returning when I navigate back to the page. I've reproduced this in a virtual OS environment, so I'm afraid I done goofed. I just don't know where. I've tried using hook_theme() to load a simple page template per info found here: PHP Output in module ...with varying results, ultimately with the undesired regions still showing up. Would anyone know why the page alter hook stops working after executing once? I'd appreciate everyone who can point me in the right direction.