function tripal_feature_edit_ALL_relationships_form

1.x tripal_feature-relationships.inc tripal_feature_edit_ALL_relationships_form($form_state, $node)

Implements Hook_form() Handles adding of Properties & Synonyms to Stocks

Related topics

1 string reference to 'tripal_feature_edit_ALL_relationships_form'

File

tripal_feature/includes/tripal_feature-relationships.inc, line 229
@todo Add file header description

Code

function tripal_feature_edit_ALL_relationships_form($form_state, $node) {
  $form = array();

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

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

  $i = 0;

  $feature = $node->feature;
  $orelationships = tripal_feature_load_relationships($feature->feature_id, 'as_object');
  $srelationships = tripal_feature_load_relationships($feature->feature_id, 'as_subject');
  $relationships = array_merge($orelationships, $srelationships);

  if (sizeof($relationships) != 0) {
    foreach ($relationships as $r) {

      $i++;
      $form["num-$i"] = array(
        '#type' => 'fieldset',
        '#title' => t("Relationship %i", array('%i' => $i)),
      );

      $form["num-$i"]["id-$i"] = array(
        '#type' => 'hidden',
        '#value' => $r->stock_relationship_id
      );

      //Enter relationship specific fields
      if (!empty($r->subject_id)) {
        $default = $r->subject_uniquename;
        $description = l($r->subject_name, 'node/' . $r->subject_nid);
      }
      else {
        $default = $node->uniquename;
        $description = "Current Feature";
      }
      $description .= " (" . $r->subject_type . ")";
      $form["num-$i"]["subject_id-$i"] = array(
        '#type' => 'textfield',
        //'#title' => t('Subject'),
        '#required' => TRUE,
        '#size' => 30,
        '#default_value' => $default,
        '#description' => t('%description', array('%description' => $description)),
      );

      $cv = tripal_cv_get_cv_by_name('relationship');
      $type_options = tripal_cv_get_cvterm_options($cv->cv_id);
      ksort($type_options);
      $form["num-$i"]["type_id-$i"] = array(
        '#type' => 'select',
        //'#title' => t('Type of Relationship'),
        '#options' => $type_options,
        '#required' => TRUE,
        '#default_value' => $r->relationship_type_id
      );

      if (!empty($r->object_id)) {
        $default = $r->object_uniquename;
        $description = l($r->object_name, 'node/' . $r->object_nid);
      }
      else {
        $default = $node->uniquename;
        $description = 'Current Feature';
      }
      $description .= " (" . $r->object_type . ")";
      $form["num-$i"]["object_id-$i"] = array(
        '#type' => 'textfield',
        //'#title' => t('Object'),
        '#required' => TRUE,
        '#size' => 30,
        '#default_value' => $default,
        '#description' => $description
      );

      $form["num-$i"]["delete-$i"] = array(
        '#type' => 'submit',
        '#value' => t("Delete"),
        '#name' => "delete-$i",
      );

    } //end of foreach relationship
    $form['num_relationships'] = array(
      '#type' => 'hidden',
      '#value' => $i
    );

    $form["submit-edits"] = array(
      '#type' => 'submit',
      '#value' => t('Update All Relationships')
    );
  }
  else {
    $form["info"] = array(
      '#type' => 'markup',
      '#value' => t('No relationships currently exist for this feature.')
    );
  }

  return $form;
}