You are here

function entityform_form_wrapper in Entityform 7.2

Same name and namespace in other branches
  1. 7 entityform.admin.inc \entityform_form_wrapper()

Form callback wrapper: create or edit a entityform.

Parameters

$entityform: The entityform object being edited by this form.

$mode: Current mode for this form Submit - user is submitting the form Edit - user with permission is editingform

$form_context: How is form being used shown? 'page' - on submit page 'embedded' - called form EntityformTypeController->view() 'preview' - Preview on Entityform type management

See also

entityform_edit_form()

2 calls to entityform_form_wrapper()
EntityformTypeController::view in ./entityform.module
Implements EntityAPIControllerInterface.
entityform_form_wrapper_preview in ./entityform.admin.inc
Form callback wrapper: preview an entityform.
1 string reference to 'entityform_form_wrapper'
EntityformUIController::hook_menu in ./entityform.admin.inc
Overrides hook_menu() defaults. Main reason for doing this is that parent class hook_menu() is optimized for entity type administration.

File

./entityform.admin.inc, line 247
Entityform editing UI.

Code

function entityform_form_wrapper(Entityform $entityform, $mode = 'submit', $form_context = 'page') {
  $make_form = TRUE;
  $entityform_type = entityform_type_load($entityform->type);
  if ($form_context == 'page') {
    drupal_set_title($entityform_type
      ->getTranslation('label'));
  }
  if (!empty($entityform->is_new)) {
    $draft = FALSE;
    if ($entityform_type->data['draftable']) {
      $draft = entityform_user_draft($entityform->type);
      if (!empty($draft)) {
        $entityform = $draft;
      }
    }
    if (!$draft) {

      // @todo add logic or other resubmit action.
      $old_submission = entityform_user_previous_submission($entityform_type->type);
      if ($old_submission) {
        switch ($entityform_type->data['resubmit_action']) {
          case 'old':
            $entityform = $old_submission;
            break;
          case 'confirm':
            $confirm_path = entity_ui_controller('entityform')
              ->confirm_path($old_submission->type, $old_submission->entityform_id);
            drupal_goto($confirm_path[0], $confirm_path[1]);
            break;
          case 'disallow':

            // @todo how should this be handled.
            $entityform_type
              ->get_prop('disallow_resubmit_msg');
            $make_form = FALSE;
            break;
        }
      }
    }
  }
  $output = array();
  if ($mode == 'submit' && (user_access('view own entityform') || user_access('view any entityform'))) {

    // Only show link if this user has a submission that will show up in the selected View.
    if (!empty($entityform_type->data['user_submissions_view'])) {
      $results = views_get_view_result($entityform_type->data['user_submissions_view'], NULL, $entityform_type->type);
      if (!empty($results)) {
        $output['submissions_link'] = array(
          '#type' => 'markup',
          '#markup' => "<div class='submissions-link' >" . l(t('View your previous submissions'), "eform/{$entityform_type->type}/submissions") . "</div>",
          '#weight' => -100,
        );
      }
    }
  }

  // Instructions get printed even if form is not created.
  $instructions_pre = $entityform_type
    ->get_prop('instruction_pre');
  if (!empty($instructions_pre)) {
    $output['intro'] = array(
      '#type' => 'markup',
      '#markup' => "<div class='pre-instructions' >" . $instructions_pre . "</div>",
      '#weight' => -100,
    );
  }
  if ($make_form) {
    $output += drupal_get_form($entityform->type . '_entityform_edit_form', $entityform, $mode, $form_context);

    // Hide fields that have been set to hide.
    $fields = field_info_instances('entityform', $entityform->type);
    foreach ($fields as $key => $field) {
      if (!empty($field['settings']['entityform']['entityform_hide_form_field'])) {
        $output[$key]['#access'] = FALSE;
      }
    }
  }
  if (user_access('administer entityform types')) {

    // Make contextual links if user has access.
    $contextual_links = array();
    $contextual_links['entityform_edit'] = array(
      'admin/structure/entityform_types/manage',
      array(
        $entityform_type->type,
      ),
    );
    $output['#contextual_links'] = $contextual_links;
  }
  return $output;
}