function tripal_bulk_loader_edit_constant_set_form

2.x tripal_bulk_loader.constants.inc tripal_bulk_loader_edit_constant_set_form($form, &$form_state, $node, $group_id)
3.x tripal_bulk_loader.constants.inc tripal_bulk_loader_edit_constant_set_form($form, &$form_state, $node, $group_id)
1.x tripal_bulk_loader.constants.inc tripal_bulk_loader_edit_constant_set_form($form_state, $node, $group_id)

Edit a constant set (exposed fields in template)

Parameters

$form_state: The current state of the form

$node: The node to set constants for

$group_id: The constant set to edit

Return value

A form array to be rendered by drupal_get_form()

Related topics

1 string reference to 'tripal_bulk_loader_edit_constant_set_form'
tripal_bulk_loader_menu in tripal_bulk_loader/tripal_bulk_loader.module
Implements hook_menu().

File

tripal_bulk_loader/includes/tripal_bulk_loader.constants.inc, line 414
Manages the constants form added to the tripal bulk loader node form

Code

function tripal_bulk_loader_edit_constant_set_form($form, &$form_state, $node, $group_id) {
  $form = array();

  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $node->nid,
  );

  $form['group_id'] = array(
    '#type' => 'hidden',
    '#value' => $group_id,
  );


  $form['explanation'] = array(
    '#type' => 'item',
    '#value' => t('The following fields are constants in the selected template that you need to set values for.')
  );

  // Add textifelds for exposed fields of the current template
  $exposed_fields = FALSE;
  $indexes = array();
  if (tripal_bulk_loader_has_exposed_fields($node)) {
    foreach ($node->exposed_fields as $exposed_index) {

      $record_id = $exposed_index['record_id'];
      $record = $node->template->template_array[$record_id];
      $field_id = $exposed_index['field_id'];
      $field = $node->template->template_array[$record_id]['fields'][$field_id];

      if ($field['exposed']) {
        $exposed_fields = TRUE;
        $indexes[$record_id][] = $field_id;

        switch ($field['type']) {
          case 'table field':
            $form[$record_id . '-' . $field_id] = array(
              '#type' => 'textfield',
              '#title' => t('%title', array('%title' => $field['title'])),
              '#description' => t('%exposed_description', array('%exposed_description' => $field['exposed_description'])),
              '#default_value' => (isset($node->constants[$group_id][$record_id][$field_id]['value'])) ? $node->constants[$group_id][$record_id][$field_id]['value'] : $field['constant value'],
            );
            break;
          case 'constant':
            $form[$record_id . '-' . $field_id] = array(
              '#type' => 'textfield',
              '#title' => t('%title', array('%title' => $field['title'])),
              '#description' => t('Enter the case-sensitive value of this constant for your data file'),
              '#default_value' => (isset($node->constants[$group_id][$record_id][$field_id]['value'])) ? $node->constants[$group_id][$record_id][$field_id]['value'] : $field['constant value'],
            );
            break;
        }

        $form[$record_id . '-' . $field_id . '-table'] = array(
          '#type' => 'hidden',
          '#value' => $record['table'],
        );
        $form[$record_id . '-' . $field_id . '-field'] = array(
          '#type' => 'hidden',
          '#value' => $field['field'],
        );
        $form[$record_id . '-' . $field_id . '-type'] = array(
          '#type' => 'hidden',
          '#value' => $field['type'],
        );
      }

    }
  }
  $form['template'] = array(
    '#type' => 'hidden',
    '#value' => serialize($node->template->template_array)
  );

  $form['indexes'] = array(
    '#type' => 'hidden',
    '#value' => serialize($indexes),
  );

  $form['save'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
  );

  $form['cancel'] = array(
    '#type' => 'link',
    '#title' => 'Cancel',
    '#href' => 'node/' . $node->nid
  );

  return $form;
}