You are here

function modalframe_example_form_alter in Modal Frame API 7

Same name and namespace in other branches
  1. 6 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 204
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['actions']) as $key) {
        if (!in_array($key, array(
          'submit',
          'preview',
        )) && isset($form['actions'][$key]) && $form['actions'][$key]) {
          unset($form['actions'][$key]);
        }
        if ($key == 'submit') {

          // Append our submit handler. This is required if we want a chance to
          // close the modal frame dialog. Submit handler must be attached
          // directly to submit button to work with node edit field.
          $form['actions'][$key]['#submit'][] = 'modalframe_example_form_submit';
        }
      }
    }
  }
}