function modal_entityform_form in Modal operations 7
Build the Modal Entityform Form.
Parameters
string $entityform: Entityform type machine name.
string $title: The Modal Popup Title.
string $entityform_type_entity: Entityform type entity.
boolean $force_page_reload: Indicates if page should be reloaded after form submission.
2 calls to modal_entityform_form()
- modal_entityform_page_edit in modal_entityform/
modal_entityform.module - Modal Entityform edit page callback.
- modal_entityform_page_submit in modal_entityform/
modal_entityform.module - Modal Entityform add page callback.
File
- modal_entityform/
modal_entityform.module, line 146 - Allows entityform submitting and editing in modal window.
Code
function modal_entityform_form($entityform, $title, $entityform_type_entity, $force_page_reload = FALSE) {
ctools_include('entityform.admin', 'entityform', '');
$form_state = array(
'title' => $title,
'ajax' => TRUE,
// This property can be used in hook_form_alter() to separate modal and full-page forms.
'modal_edit' => TRUE,
'build_info' => array(
'args' => array(
$entityform,
'submit',
),
),
);
if (isset($_GET['destination'])) {
$form_state['modal_destination'] = $_GET['destination'];
unset($_GET['destination']);
}
$form_wrapper = ctools_modal_form_wrapper('entityform_edit_form', $form_state);
if (!empty($form_state['ajax']) && (!$form_state['executed'] || $form_state['rebuild'])) {
$commands = array();
$commands[] = ajax_command_invoke('#modalContent', 'addClass', array(
'modal-entityform modal-entityform-' . $entityform->type,
));
drupal_alter('modal_entityform_edit', $commands, $entityform_type_entity, $entityform);
$commands = array_merge($form_wrapper, $commands);
return array(
'#type' => 'ajax',
'#commands' => $commands,
);
}
// Window is to be closed.
ctools_add_js('ajax-responder');
$commands = array();
$commands[] = ctools_modal_command_dismiss();
drupal_alter('modal_entityform_edit_close', $commands, $entityform_type_entity, $entityform);
$message_commands = array();
if (module_exists('modal_message')) {
$message_commands = modal_message_get_as_ajax_commands($force_page_reload);
}
if (!empty($message_commands)) {
$commands = array_merge($commands, $message_commands);
}
elseif ($force_page_reload) {
if (isset($form_state['modal_destination'])) {
$commands[] = ctools_ajax_command_redirect($form_state['modal_destination']);
}
else {
$commands[] = ctools_ajax_command_reload();
}
}
elseif (isset($form_state['modal_destination'])) {
$commands[] = ctools_ajax_command_redirect($form_state['modal_destination']);
}
return array(
'#type' => 'ajax',
'#commands' => $commands,
);
}