I wrote this module that print the node/add form for a content type (article) in a ctools modal window. It works and the new node is saved, but the modal window remains opened after submitting the form.
I would like to automatically close the modal window after saving the node, end and optionally redirect drupal to the new node. Any hint?
<?php
function modaltest_menu()
{
$items['modaltest'] = array(
'title' => 'Modaltest Page',
'page callback' => 'modaltest_page',
'access arguments' => TRUE
);
$items['modaltest/%ctools_js'] = array(
'title' => 'Modaltest page 2',
'page callback' => 'modaltest_page_modal',
'page arguments' => array(
1
),
'access arguments' => TRUE
);
return $items;
}
function modaltest_page_modal($js = NULL)
{
$nojs_message = t('Hello World');
if (!$js) {
return $nojs_message;
}
module_load_include('inc', 'node', 'node.pages');
$form = node_add('article');
ctools_include('modal');
ctools_include('ajax');
$output = array();
$output[] = ctools_modal_command_display(t('My modal test'), $form);
print ajax_render($output);
exit();
}
function modaltest_page()
{
ctools_include('modal');
ctools_include('ajax');
ctools_modal_add_js();
return ctools_modal_text_button(t('Popup link'), 'modaltest/nojs', t('test popup'), 'ctools-modal-test-style');
}