You are here

function entityform_form_wrapper in Entityform 7

Same name and namespace in other branches
  1. 7.2 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()

See also

entityform_edit_form()

1 call to entityform_form_wrapper()
EntityformTypeController::view in ./entityform.module
Implements EntityAPIControllerInterface.
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 207
Entityform editing UI.

Code

function entityform_form_wrapper($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->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
            drupal_set_message(t('You have already submitted this form.'));
            $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 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
  if (!empty($entityform_type->data['instruction_pre'])) {
    $output['intro'] = array(
      '#type' => 'markup',
      '#markup' => "<div class='pre-intructions' >" . _entityform_format_text($entityform_type->data['instruction_pre'], array(
        'entityform_type' => $entityform_type,
      )) . "</div>",
      '#weight' => -100,
    );
  }
  if ($make_form) {
    $rule_returns = entityform_invoke_rules($entityform, 'access_rules');
    if (_entityform_rules_all_pass($rule_returns)) {
      $form = drupal_get_form($entityform->type . '_entityform_edit_form', $entityform, $mode);
      $form['#attributes']['class'][] = 'entityform';
      if (!empty($entityform->type)) {
        $form['#attributes']['class'][] = 'entitytype-' . $entityform->type . '-form';
      }
      $output += $form;
    }
  }
  if (user_access('administer entityform types')) {

    //Make contextual likes 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;
}