You are here

function entityform_edit_form in Entityform 7

Same name and namespace in other branches
  1. 7.2 entityform.admin.inc \entityform_edit_form()

Form callback: create or edit a entityform.

Parameters

$entityform: The entityform object to edit or for a create form an empty entityform object with only a entityform type defined.

1 string reference to 'entityform_edit_form'
entityform_forms in ./entityform.module
Implements hook_forms().

File

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

Code

function entityform_edit_form($form, &$form_state, $entityform, $mode = 'submit') {
  global $user;
  $entityform_type = entityform_type_load($entityform->type);

  // Add the field related form elements.
  $form_state['entityform'] = $entityform;
  $form_state['entityform_form_mode'] = $mode;
  field_attach_form('entityform', $entityform, $form, $form_state);
  $form['actions'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'form-actions',
      ),
    ),
    '#weight' => 400,
  );

  // We add the form's #submit array to this button along with the actual submit
  // handler to preserve any submit handlers added by a form callback_wrapper.
  $submit = array();
  if (!empty($form['#submit'])) {
    $submit += $form['#submit'];
  }
  if ($mode == 'submit') {

    //If form is draftable and user is logged in add draft button
    if ($entityform_type->data['draftable'] && !empty($user->uid)) {
      $form['actions']['save'] = array(
        '#type' => 'submit',
        '#value' => empty($entityform_type->data['draft_button_text']) ? t('Save Draft') : t($entityform_type->data['draft_button_text']),
        //'#limit_validation_errors' => array(), //cause erros
        '#entityform_draft' => '1',
        '#submit' => $submit + array(
          'entityform_edit_form_submit',
        ),
      );
    }
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => empty($entityform_type->data['submit_button_text']) ? t('Submit Form') : t($entityform_type->data['submit_button_text']),
      '#entityform_draft' => 0,
      '#submit' => $submit + array(
        'entityform_edit_form_submit',
      ),
    );
  }
  else {
    $form['user_info'] = array(
      '#type' => 'markup',
      '#markup' => _entityform_get_submit_info($entityform),
      '#weight' => -200,
    );
    $form['actions']['save'] = array(
      '#type' => 'submit',
      '#value' => t('Save Changes'),
      '#entityform_draft' => '0',
      '#submit' => $submit + array(
        'entityform_edit_form_submit',
      ),
    );
  }
  if (!empty($entityform->name)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete entityform'),
      '#suffix' => l(t('Cancel'), 'admin/structure/entityforms'),
      '#submit' => $submit + array(
        'entityform_form_submit_delete',
      ),
      '#weight' => 45,
    );
  }

  // We append the validate handler to #validate in case a form callback_wrapper
  // is used to add validate handlers earlier.
  $form['#validate'][] = 'entityform_edit_form_validate';

  // Make sure the proper files are loaded if they is form is being called embedded with an ajax callback
  // This happens in image field upload for instance.
  $form['#after_build'][] = 'entityform_load_required_entityform_admin';
  $form['#after_build'][] = 'entityform_clear_required';
  $form['#validate'][] = 'entityform_set_required';
  return $form;
}