function tripal_entity_form

3.x TripalEntityUIController.inc tripal_entity_form($form, &$form_state, $term_id = '', $entity = NULL)
2 string references to 'tripal_entity_form'
TripalEntityUIController::hook_menu in tripal/includes/TripalEntityUIController.inc
Overrides hook_menu() defaults. Main reason for doing this is that parent class hook_menu() is optimized for entity type administration.
tripal_form_alter in tripal/tripal.module
Implements hook_form_alter().

File

tripal/includes/TripalEntityUIController.inc, line 448

Code

function tripal_entity_form($form, &$form_state, $term_id = '', $entity = NULL) {
  global $user;
  $bundle_name = 'bio_data_' . $term_id;

  // Add a vertical tabs element
  $form['entity_form_vtabs'] = array(
    '#type' => 'vertical_tabs',
    '#weight' => 999,
  );

  // If the entity doesn't exist then create one.
  if (!$entity) {
    $entity = entity_get_controller('TripalEntity')->create(array(
      'bundle' => $bundle_name,
      'term_id' => $term_id
    ));
    field_attach_form('TripalEntity', $entity, $form, $form_state);

    $form['add_button'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
      '#name' => 'add_data',
      '#weight' => 1000
    );
  }
  else {
    field_attach_form('TripalEntity', $entity, $form, $form_state);

    $form['update_button'] = array(
      '#type' => 'submit',
      '#value' => t('Update'),
      '#name' => 'update_data',
      '#weight' => 1000
    );

    // Put the delete button on the far-right so that it's harder
    // to accidentally click it.
    if (entity_access('delete', 'TripalEntity', $entity, $user)) {
      $form['delete_button'] = array(
        '#type' => 'submit',
        '#value' => t('Delete'),
        '#name' => 'delete_data',
        '#weight' => 1002,
        '#attributes' => array('style' => 'float: right')
      );
    }
  }
  $form['additional_settings'] = array(
    '#type' => 'vertical_tabs',
    '#weight' => 99,
  );

  // Node author information for administrators
  $form['author'] = array(
    '#type' => 'fieldset',
    '#access' => user_access('administer nodes'),
    '#title' => t('Authoring information'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'additional_settings',
    '#attributes' => array(
      'class' => array('TripalEntity-form-author'),
    ),
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'node') . '/node.js',
        array(
          'type' => 'setting',
          'data' => array('anonymous' => variable_get('anonymous', t('Anonymous'))),
        ),
      ),
    ),

    '#weight' => 90,
  );

  $account = user_load($entity->uid);
  $form['author']['author_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Authored by'),
    '#maxlength' => 60,
    '#autocomplete_path' => 'user/autocomplete',
    '#default_value' => !empty($account->name) ? $account->name : '',
    '#weight' => -1,
    '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))),
  );
  $form['author']['author_date'] = array(
    '#type' => 'textfield',
    '#title' => t('Authored on'),
    '#maxlength' => 25,
    '#description' => t('Format: %time. The date format is YYYY-MM-DD and ' .
      '%timezone is the time zone offset from UTC. Leave blank to use the ' .
      'time of form submission.', 
    array(
      '%time' => !empty($entity->created) ? date('Y-m-d H:i:s O', $entity->created) : format_date($entity->created, 'custom', 'Y-m-d H:i:s O'),
      '%timezone' => !empty($entity->created) ? date('O', $entity->created) : format_date($entity->created, 'custom', 'O'))
    ),
    '#default_value' => !empty($entity->created) ? date('Y-m-d H:i:s O', $entity->created) : '',
  );
  // Node options for administrators
  $form['options'] = array(
    '#type' => 'fieldset',
    '#access' => user_access('administer nodes'),
    '#title' => t('Publishing options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'additional_settings',
    '#attributes' => array(
      'class' => array('node-form-options'),
    ),
    '#attached' => array(
      'js' => array(drupal_get_path('module', 'node') . '/node.js'),
    ),
    '#weight' => 95,
  );
  $form['options']['status'] = array(
    '#type' => 'checkbox',
    '#title' => t('Published'),
    '#default_value' => $entity->status,
  );


  $form['cancel_button'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#name' => 'cancel_data',
    '#weight' => 1001,
    '#limit_validation_errors' => array(array('')),
  );

  // The entity object must be added to the $form_state in order for
  // the Entity API to work. It must have a key of the entity name.
  $form_state['TripalEntity'] = $entity;

  $form['#prefix'] = "<div id='$bundle_name-entity-form'>";
  $form['#suffix'] = "</div>";
  $form['#submit'][] = 'tripal_entity_form_submit';
  return $form;
}