function modalframe_example_form_alter in Modal Frame API 6
Same name and namespace in other branches
- 7 modules/modalframe_example/modalframe_example.module \modalframe_example_form_alter()
Implementation of hook_form_alter().
This function is part of the node edit form example.
See also
modalframe_example_node_edit_page()
modalframe_example_form_submit()
File
- modules/
modalframe_example/ modalframe_example.module, line 195 - Example for the Modal Frame module.
Code
function modalframe_example_form_alter(&$form, $form_state, $form_id) {
// Look for a node edit form.
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
$node =& $form['#node'];
// Is this node the one we are testing?
if (!empty($GLOBALS['modalframe_example_node_edit_page_nid']) && $GLOBALS['modalframe_example_node_edit_page_nid'] == $node->nid) {
// Keep this example as simple as possible by hidding a few buttons.
// If we wanted to show all buttons, then we probably need to take
// additional actions, for example to alter the delete confirmation
// page so that we also send the modal frame javascript to that page,
// and we also alter that particular form to append out submit handler
// where we may wish to close the modal frame dialog.
// So let's keep this as simple as possible. We are now hidding all
// buttons, except "Save" and "Preview".
foreach (element_children($form['buttons']) as $key) {
if (!in_array($key, array(
'submit',
'preview',
)) && isset($form['buttons'][$key]) && $form['buttons'][$key]) {
unset($form['buttons'][$key]);
}
}
// Append our submit handler. This is required if we want a chance to
// close the modal frame dialog.
$form['#submit'][] = 'modalframe_example_form_submit';
}
}
}