Browse Source

Altered publish form to simplify it

Stephen Ficklin 9 years ago
parent
commit
095a77fe29

+ 32 - 11
tripal_cv/api/tripal_cv.api.inc

@@ -872,18 +872,39 @@ function tripal_insert_obo($name, $path) {
  * @ingroup tripal_cv_api
  */
 function tripal_autocomplete_cvterm($cv_id, $string = '') {
-  $sql = "
-    SELECT cvterm_id, name
-    FROM {cvterm}
-    WHERE cv_id = :cv_id and lower(name) like lower(:name)
-    ORDER by name
-    LIMIT 25 OFFSET 0
-  ";
-  $results = chado_query($sql, array(':cv_id' => $cv_id, ':name' => $string . '%'));
-  $items = array();
-  foreach ($results as $term) {
-     $items[$term->name] = $term->name;
+  if ($cv_id) {
+    $sql = "
+      SELECT cvterm_id, name
+      FROM {cvterm}
+      WHERE cv_id = :cv_id and lower(name) like lower(:name)
+      ORDER by name
+      LIMIT 25 OFFSET 0
+    ";
+    $results = chado_query($sql, array(':cv_id' => $cv_id, ':name' => $string . '%'));
+    $items = array();
+    foreach ($results as $term) {
+      $items[$term->name] = $term->name;
+    }
   }
+  // If a CV wasn't provided then search all of them, and include the cv
+  // in the results.
+  else {
+    $sql = "
+      SELECT cvterm_id, CVT.name, CV.name as cvname, CVT.cv_id
+      FROM {cvterm} CVT
+          INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
+      WHERE lower(CVT.name) like lower(:name)
+      ORDER by CVT.name
+      LIMIT 25 OFFSET 0
+    ";
+    $results = chado_query($sql, array(':name' => $string . '%'));
+    $items = array();
+    foreach ($results as $term) {
+      $items[$term->name] = '(' . $term->cvname .') ' . $term->name;
+    }
+  }
+
+
   drupal_json_output($items);
 }
 

+ 21 - 316
tripal_entities/includes/TripalEntityUIController.inc

@@ -31,9 +31,11 @@ class TripalEntityUIController extends EntityDefaultUIController {
       'title' => 'Add new biological data',
       'description' => 'Add new biological data',
       'page callback'  => 'drupal_get_form',
-      'page arguments' => array('tripal_entity_form'),
-      'access callback'  => 'tripal_entity_access',
+      'page arguments' => array('tripal_entities_entity_form'),
+      'access callback'  => 'tripal_entities_entity_access',
       'access arguments' => array('administer tripal data'),
+      'file' =>  'includes/tripal_entities.entity_form.inc',
+      'file path' => drupal_get_path('module', 'tripal_entities'),
       'type' => MENU_LOCAL_ACTION,
       'weight' => 20,
     );
@@ -43,20 +45,22 @@ class TripalEntityUIController extends EntityDefaultUIController {
       'title' => 'Add Tripal data',
       'description' => 'Add a new tripal data record',
       'page callback'  => 'drupal_get_form',
-      'page arguments' => array('tripal_entity_form'),
-      'access callback'  => 'tripal_entity_access',
+      'page arguments' => array('tripal_entities_entity_form'),
+      'access callback'  => 'tripal_entities_entity_access',
       'access arguments' => array('edit'),
+      'file' =>  'includes/tripal_entities.entity_form.inc',
+      'file path' => drupal_get_path('module', 'tripal_entities'),
       'type' => MENU_NORMAL_ITEM,
       'weight' => 20,
     );
 
     // Link for viewing a tripal data type.
     $items['data/' . $wildcard] = array(
-      'title callback' => 'tripal_entity_title',
+      'title callback' => 'tripal_entities_entity_title',
       'title arguments' => array(1),
-      'page callback' => 'tripal_entity_view',
+      'page callback' => 'tripal_entities_view_entity',
       'page arguments' => array(1),
-      'access callback' => 'tripal_entity_access',
+      'access callback' => 'tripal_entities_entity_access',
       'access arguments' => array('view', 1),
       'type' => MENU_CALLBACK,
     );
@@ -64,9 +68,9 @@ class TripalEntityUIController extends EntityDefaultUIController {
     // 'View' tab for an individual entity page.
     $items['data/' . $wildcard . '/view'] = array(
       'title' => 'View',
-      'page callback' => 'tripal_entity_view',
+      'page callback' => 'tripal_entities_view_entity',
       'page arguments' => array(1),
-      'access callback' => 'tripal_entity_access',
+      'access callback' => 'tripal_entities_entity_access',
       'access arguments' => array('view', 1),
       'type' => MENU_DEFAULT_LOCAL_TASK,
       'weight' => -10,
@@ -77,325 +81,26 @@ class TripalEntityUIController extends EntityDefaultUIController {
     $items['data/' . $wildcard . '/edit'] = array(
       'title' => 'Edit',
       'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_entity_form', 1),
-      'access callback' => 'tripal_entity_access',
+      'page arguments' => array('tripal_entities_entity_form', 1),
+      'access callback' => 'tripal_entities_entity_access',
       'access arguments' => array('edit', 1),
+      'file' =>  'includes/tripal_entities.entity_form.inc',
+      'file path' => drupal_get_path('module', 'tripal_entities'),
       'type' => MENU_LOCAL_TASK,
-
     );
 
     // Menu item for deleting tripal data entities.
     $items['data/' . $wildcard . '/delete'] = array(
       'title'  => 'Delete',
       'page callback' => 'drupal_get_form',
-      'page arguments' => array('tripal_entity_delete_form', 1),
-      'access callback' => 'tripal_entity_access',
+      'page arguments' => array('tripal_entities_entity_delete_form', 1),
+      'access callback' => 'tripal_entities_entity_access',
       'access arguments' => array('edit', 1),
+      'file' =>  'includes/tripal_entities.entity_form.inc',
+      'file path' => drupal_get_path('module', 'tripal_entities'),
       'type' => MENU_CALLBACK,
       'weight' => 10,
     );
     return $items;
   }
-
-}
-/**
- * Determines whether the given user has access to a tripal data entity.
- *
- * @param $op
- *   The operation being performed. One of 'view', 'update', 'create', 'delete'
- *   or just 'edit' (being the same as 'create' or 'update').
- * @param $entity
- *   Optionally a tripal data entity or a tripal data type to check access for.
- *   If nothing is given, access for all types is determined.
- * @param $account
- *   The user to check for. Leave it to NULL to check for the global user.
- * @return boolean
- *   Whether access is allowed or not.
- */
-function tripal_entity_access($op, $entity = NULL, $account = NULL) {
-  if (user_access('administer tripal data', $account)) {
-    return TRUE;
-  }
-  if (isset($entity) && $type_name = $entity->type) {
-    $op = ($op == 'view') ? 'view' : 'edit';
-    if (user_access("$op any $type_name data", $account)) {
-      return TRUE;
-    }
-  }
-  return FALSE;
-}
-/**
- *
- */
-function tripal_entity_form($form, &$form_state, $entity = NULL) {
-
-  // Set the defaults.
-  $cv_id = NULL;
-  $term_name = NULL;
-  $cvterm = NULL;
-
-  // Set defaults if an entity was provided.
-  if ($entity) {
-    drupal_set_title('Edit ' . $entity->title);
-    $id = $entity->id;
-    $values = array('cvterm_id' => $entity->cvterm_id);
-    $cvterm = chado_generate_var('cvterm', $values);
-    $cv_id = $cvterm->cv_id->cv_id;
-    $term_name = $cvterm->name;
-  }
-
-  // Set defaults using the form state.
-  if (array_key_exists('values', $form_state)) {
-    $cv_id = array_key_exists('cv_id', $form_state['values']) ? $form_state['values']['cv_id'] : NULL;
-    $term_name = array_key_exists('term_name', $form_state['values']) ? $form_state['values']['term_name'] : NULL;
-    // Get the cvterm that matches
-    $values = array(
-      'cv_id' => $cv_id,
-      'name' => $term_name
-    );
-    $cvterm = chado_generate_var('cvterm', $values);
-  }
-
-  // Let the user select the vocabulary          defaut and tripal_entity but only if they haven't
-  // already selected a tripal_entity.
-  $cvs = tripal_entities_get_published_vocabularies_as_select_options();
-  if (!$term_name) {
-    $form['cv_id'] = array(
-      '#type' => 'select',
-      '#title' => t('Published vocabulary'),
-      '#options' => $cvs,
-      '#required' => TRUE,
-      '#description' => t('Select a vocabulary that contains the term for the type of data you want to add.'),
-      '#default_value' => $cv_id,
-      '#ajax' => array(
-        'callback' => "tripal_entity_form_ajax_callback",
-        'wrapper' => 'tripal_entity_form',
-        'effect' => 'fade',
-        'method' => 'replace'
-      )
-    );
-  }
-
-  // If we have a CV ID then we want to provide an autocomplete field
-  if ($cv_id and !$term_name) {
-    $cvterms = tripal_entities_get_published_terms_as_select_options ($cv_id);
-    $form['cvterm_select']['term_name'] = array(
-      '#title'       => t('Published term'),
-      '#type'        => 'select',
-      '#options' => $cvterms,
-      '#description' => t("Enter the name of a term within the selected vocabulary for the record type you want to enter."),
-      '#required'    => TRUE,
-    );
-
-    $form['cvterm_select']['select_button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Use this term'),
-      '#name' => 'select_cvterm',
-    );
-  }
-
-  // Once the CV term is selected then provide the other fields.
-  if ($cvterm) {
-    $bundle_id = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
-
-    $form['cv_id'] = array(
-      '#type'  => 'hidden',
-      '#value' => $cv_id,
-    );
-    $form['type'] = array(
-      '#type'  => 'hidden',
-      '#value' => $cvterm->dbxref_id->db_id->name,
-    );
-    $form['term_name'] = array(
-      '#type'  => 'hidden',
-      '#value' => $term_name,
-    );
-    $form['cvterm_id'] = array(
-      '#type'  => 'hidden',
-      '#value' => $cvterm->cvterm_id,
-    );
-    $form['bundle'] = array(
-      '#type'  => 'hidden',
-      '#value' => $bundle_id,
-    );
-    $form['details'] = array(
-      '#type' => 'fieldset',
-      '#title' => 'Record Type',
-      '#collapsable' => FALSE,
-      '#weight' => -100,
-    );
-    $form['details']['cv_name_shown'] = array(
-      '#type' => 'item',
-      '#title' => 'Vocabulary',
-      '#markup' => $cvterm->cv_id->name,
-    );
-    $form['details']['term_name_shown'] = array(
-      '#type' => 'item',
-      '#title' => 'Term',
-      '#markup' => $cvterm->name,
-    );
-
-    // If the entity doesn't exist then create one.
-    if (!$entity) {
-      $entity = entity_get_controller($cvterm->dbxref_id->db_id->name)->create(array('bundle' => $bundle_id));
-      field_attach_form($cvterm->dbxref_id->db_id->name, $entity, $form, $form_state);
-
-      $form['add_button'] = array(
-        '#type' => 'submit',
-        '#value' => t('Add a new ' . $cvterm->name),
-        '#name' => 'add_data',
-        '#weight' => 1000
-      );
-    }
-    else {
-      field_attach_form($cvterm->dbxref_id->db_id->name, $entity, $form, $form_state);
-      $form['entity_id'] = array(
-        '#type'  => 'hidden',
-        '#value' => $entity->id,
-      );
-      $form['update_button'] = array(
-        '#type' => 'submit',
-        '#value' => t('Update'),
-        '#name' => 'update_data',
-        '#weight' => 1000
-      );
-      $form['delete_button'] = array(
-        '#type' => 'submit',
-        '#value' => t('Delete'),
-        '#name' => 'delete_data',
-        '#weight' => 1001,
-      );
-    }
-
-    // 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[$cvterm->dbxref_id->db_id->name] = $entity;
-  }
-  $form['#prefix'] = '<div id="tripal_entity_form">';
-  $form['#suffix'] = '</div>';
-  return $form;
-}
-
-/**
- * An Ajax callback for the tripal_entity_form.
- */
-function tripal_entity_form_ajax_callback($form, $form_state) {
-  // return the form so Drupal can update the content on the page
-  return $form;
-
-}
-/**
- * Implements hook_validate() for the tripal_entity_form.
- */
-function tripal_entity_form_validate($form, &$form_state) {
-
-  if (array_key_exists('clicked_button', $form_state) and
-      $form_state['clicked_button']['#name'] == 'add_data') {
-    $tripal_entity = (object) $form_state['values'];
-    $entity_type = $form_state['values']['type'];
-    field_attach_form_validate($entity_type, $tripal_entity, $form, $form_state);
-  }
-}
-
-/**
- * Implements hook_submit() for the tripal_entity_form.
- *
- */
-function tripal_entity_form_submit($form, &$form_state) {
-  if ($form_state['clicked_button']['#name'] == 'cancel') {
-    if (array_key_exists('id', $form_state['values'])){
-      $entity_id = $form_state['values']['entity_id'];
-      $form_state['redirect'] = "data/$entity_id";
-    }
-    else {
-      $form_state['redirect'] = "admin/structure/tripal_entity";
-    }
-    return;
-  }
-  if ($form_state['clicked_button']['#name'] == 'select_cvterm') {
-    // don't do anything, we just need to know what the term name is.
-    $form_state['rebuild'] = TRUE;
-  }
-  if ($form_state['clicked_button']['#name'] == 'update_data' or
-      $form_state['clicked_button']['#name'] == 'add_data') {
-    // Use the Entity API to get the entity from the form state, then
-    // attach the fields and save.
-    $entity_type = $form_state['values']['type'];
-    $entity = entity_ui_controller($entity_type)->entityFormSubmitBuildEntity($form, $form_state);
-    $entity->save();
-    $form_state['redirect'] = "data/$entity->id";
-  }
-  if ($form_state['clicked_button']['#name'] == 'delete_data') {
-    $entity_id = $form_state['values']['entity_id'];
-    $form_state['redirect'] = 'data/' . $entity_id . '/delete';
-  }
-}
-
-
-/**
- * Form callback: confirmation form for deleting a tripal_entity.
- *
- * @param $tripal_entity
- *   The tripal_entity to delete
- *
- * @see confirm_form()
- */
-function tripal_entity_delete_form($form, &$form_state, $entity) {
-  $form_state['entity'] = $entity;
-  $form['#submit'][] = 'tripal_entity_delete_form_submit';
-
-  $form = confirm_form($form,
-    t('Click the delete button below to confirm deletion of the record titled: %title', array('%title' => $entity->title)),
-    'admin/content/tripal_entity',
-    '<p>' . t('This action cannot be undone.') . '</p>',
-    t('Delete'),
-    t('Cancel'),
-    'confirm'
-  );
-
-  return $form;
-}
-
-/**
- * Submit callback for tripal_entity_delete_form
- */
-function tripal_entity_delete_form_submit($form, &$form_state) {
-  $entity = $form_state['entity'];
-
-  $entity_controller = new TripalEntityController($entity->type);
-  if($entity_controller->delete($entity)) {
-    drupal_set_message(t('The record title "%name" has been deleted.', array('%name' => $entity->title)));
-    $form_state['redirect'] = 'admin/content/tripal_entitys';
-  }
-  else {
-    drupal_set_message(t('The tripal_entity %name was not deleted.', array('%name' => $entity->title)), "error");
-  }
-}
-
-/**
- * Menu callback to display an entity.
- *
- * As we load the entity for display, we're responsible for invoking a number
- * of hooks in their proper order.
- *
- * @see hook_entity_prepare_view()
- * @see hook_entity_view()
- * @see hook_entity_view_alter()
- */
-function tripal_entity_view($entity, $view_mode = 'full') {
-  if ($entity) {
-    $controller = entity_get_controller($entity->type);
-    $content = $controller->view(array($entity->id => $entity));
-    drupal_set_title($entity->title);
-    return $content;
-  }
-}
-
-/**
- * Menu title callback for showing individual entities
- */
-function tripal_entity_title($entity){
-  if ($entity) {
-    return $entity->title;
-  }
 }

+ 26 - 193
tripal_entities/includes/tripal_entities.admin.inc

@@ -63,6 +63,19 @@ function tripal_entities_content_view() {
 
 }
 
+function tripal_entities_publish() {
+  $form = drupal_get_form('tripal_entities_entity_form');
+  $output = drupal_render($form);
+
+  // set the breadcrumb
+  $breadcrumb = array();
+  $breadcrumb[] = l('Home', '<front>');
+  $breadcrumb[] = l('Administration', 'admin');
+  drupal_set_breadcrumb($breadcrumb);
+
+  return $output;
+}
+
 /**
  *
  * @param unknown $form
@@ -208,17 +221,19 @@ function tripal_entities_admin_publish_form($form, &$form_state) {
 
   // Let the user select the vocabulary and tripal_entity but only if they haven't
   // already selected a tripal_entity.
-  $sql = "
-    SELECT CV.cv_id, CV.name
-    FROM {tripal_vocabulary} TET
-      INNER JOIN {cv} CV on CV.cv_id = TET.cv_id
-    ORDER BY CV.name
-  ";
-  $vocabs = chado_query($sql);
-  $cvs = array();
-  while ($vocab = $vocabs->fetchObject()) {
-    $cvs[$vocab->cv_id] = $vocab->name;
-  }
+//   $sql = "
+//     SELECT CV.cv_id, CV.name
+//     FROM {tripal_vocabulary} TET
+//       INNER JOIN {cv} CV on CV.cv_id = TET.cv_id
+//     ORDER BY CV.name
+//   ";
+
+//   $vocabs = chado_query($sql);
+//   $cvs = array();
+//   while ($vocab = $vocabs->fetchObject()) {
+//     $cvs[$vocab->cv_id] = $vocab->name;
+//   }
+  $cvs = tripal_get_cv_select_options();
   $form['cv_id'] = array(
     '#type' => 'select',
     '#title' => t('Vocabulary'),
@@ -371,188 +386,6 @@ function tripal_entities_admin_publish_form_submit($form, &$form_state) {
     watchdog_exception('trp_entities', $e);
   }
 }
-/**
- *
- * @param $table
- * @param $entity_type
- * @param $bundle_name
- */
-function tripal_entities_add_bundle_fields($entity_type_name, $bundle_name, $cvterm) {
-
-  // Get the list of tables where this cvterm is used.
-  $match = array('cvterm_id' => $cvterm->cvterm_id);
-  $term = chado_select_record('tripal_term', array('*'), $match);
-  $values = array('term_id' => $term[0]->term_id);
-  $tables = chado_select_record('tripal_term_usage', array('*'), $values);
-
-  // Iterate through the tables.
-  foreach ($tables as $table) {
-    $tablename = $table->data_table;
-    $type_table = $table->type_table;
-    $type_field = $table->field;
-
-    // We only want to look at base tables.
-    if ($tablename == 'cvterm_dbxref' || $tablename == 'cvterm_relationship' ||
-        $tablename == 'cvtermpath' || $tablename == 'cvtermprop' || $tablename == 'chadoprop' ||
-        $tablename == 'cvtermsynonym' || preg_match('/_relationship$/', $tablename) ||
-        preg_match('/_cvterm$/', $tablename)) {
-      continue;
-    }
-
-    // Iterate through the columns of the table and see if fields have been
-    // created for each one. If not, then create them.
-    $schema = chado_get_schema($tablename);
-    $columns = $schema['fields'];
-    foreach ($columns as $column_name => $details) {
-      $field_name = $tablename . '__' . $column_name;
-      $field = field_info_field($field_name);
-
-      // Skip the primary key field.
-      if ($column_name == $schema['primary key'][0]) {
-        continue;
-      }
-
-      // Skip the type field.
-      if ($tablename == $type_table and $column_name == $type_field) {
-        continue;
-      }
-
-      // Determine if the field is required.
-      $is_required = 0;
-      if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
-        $is_required = array_key_exists('default', $details) ? 0 : 1;
-      }
-
-      // Determine what type of field this should be.
-      // Drupal data types are: https://www.drupal.org/node/159605.
-      // Field types are here:  https://www.drupal.org/node/1879542
-
-      // Create an array with information about this field.
-      $field_info = array(
-        'field_type' => '',
-        'widget_type' => '',
-        'field_settings' => array(),
-        'widget_settings' => array('display_label' => 1),
-        'description' => '',
-        'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
-        'chado_table' => $tablename,
-        'chado_column' => $column_name
-      );
-
-      // Alter the field info array dependiing on the column details.
-      switch($details['type']) {
-        case 'char':
-          $field_info['field_type'] = 'text';
-          $field_info['widget_type'] = 'text_textfield';
-          $field_info['field_settings']['max_length'] = $details['length'];
-          break;
-        case 'varchar':
-          $field_info['field_type'] = 'text';
-          $field_info['widget_type'] = 'text_textfield';
-          $field_info['field_settings']['max_length'] = $details['length'];
-          break;
-        case 'text':
-          $field_info['field_type'] = 'text';
-          $field_info['widget_type'] = 'text_textarea';
-          $field_info['field_settings']['max_length'] = 17179869184;
-          break;
-        case 'blob':
-          // not sure how to support a blob field.
-          continue;
-          break;
-        case 'int':
-          $field_info['field_type'] = 'number_integer';
-          $field_info['widget_type'] = 'number';
-          break;
-        case 'float':
-          $field_info['field_type'] = 'number_float';
-          $field_info['widget_type'] = 'number';
-          $field_info['field_settings']['precision'] = 10;
-          $field_info['field_settings']['scale'] = 2;
-          $field_info['field_settings']['decimal_separator'] = '.';
-          break;
-        case 'numeric':
-          $field_info['field_type'] = 'number_decimal';
-          $field_info['widget_type'] = 'number';
-          break;
-        case 'serial':
-          // Serial fields are most likely not needed as a field.
-          break;
-        case 'boolean':
-          $field_info['field_type'] = 'list_boolean';
-          $field_info['widget_type'] = 'options_onoff';
-          $field_info['field_settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
-          break;
-        case 'datetime':
-          // Use the Drupal Date and Date API to create the field/widget
-          $field_info['field_type'] = 'datetime';
-          $field_info['widget_type'] = 'date_select';
-          $field_info['widget_settings']['increment'] = 1;
-          $field_info['widget_settings']['tz_handling'] = 'none';
-
-          // TODO: Add settings so that the minutes increment by 1.
-          // And turn off the timezone, as the Chado field doesn't support it.
-          break;
-      }
-
-      // If we don't have a field type then we don't need to create a field.
-      if (!$field_info['field_type']) {
-        // If we don't have a field type but it is required and doesn't have
-        // a default value then we are in trouble.
-        if ($is_required and !array_key_exists('default', $details)) {
-          throw new Exception(t('The %table.%field type, %type, is not yet supported for Entity fields, but it is required,',
-            array('%table' => $tablename, '%field' => $column_name, '%type' => $details['type'])));
-        }
-        continue;
-      }
-
-      // If this field is a foreign key field then we will have a special custom
-      // field provided by Tripal.
-      $is_fk = FALSE;
-      if (array_key_exists('foreign keys', $schema)) {
-        foreach ($schema['foreign keys'] as $remote_table => $fk_details) {
-          if (array_key_exists($column_name, $fk_details['columns'])) {
-            $is_fk = TRUE;
-          }
-        }
-      }
-
-      // Allow other modules to alter the field information array.
-      drupal_alter('chado_field', $field_info);
-
-      // If the field doesn't exist then create it.
-      if (!$field) {
-        $field = array(
-          'field_name' => $field_name,
-          'type' => $field_info['field_type'],
-          'cardinality' => 1,
-          'locked' => FALSE,
-          'storage' => array(
-            'type' => 'field_chado_storage'
-          ),
-          'settings' => $field_info['field_settings'],
-        );
-        field_create_field($field);
-      }
-
-      // Attach the field to the bundle.
-      $field_instance = array(
-        'field_name' => $field_name,
-        'label' => $field_info['label'],
-        'description' => $field_info['description'],
-        'widget' => array(
-          'type' => $field_info['widget_type'],
-          'settings' => $field_info['widget_settings'],
-        ),
-        'entity_type' => $entity_type_name,
-        'required' => $is_required,
-        'settings' => $field_info['field_settings'],
-        'bundle' => $bundle_name,
-      );
-      field_create_instance($field_instance);
-    }
-  }
-}
 
 /**
  * Implements hook_chado_field_alter.

+ 54 - 0
tripal_entities/includes/tripal_entities.chado_entity.inc

@@ -130,3 +130,57 @@ function tripal_entities_chado_field_alter(&$field) {
     $field['description'] = 'Please provide an IUPAC compatible residues for this feature. Spaces and new lines are allowed.';
   }
 }
+
+/**
+ * Determines whether the given user has access to a tripal data entity.
+ *
+ * @param $op
+ *   The operation being performed. One of 'view', 'update', 'create', 'delete'
+ *   or just 'edit' (being the same as 'create' or 'update').
+ * @param $entity
+ *   Optionally a tripal data entity or a tripal data type to check access for.
+ *   If nothing is given, access for all types is determined.
+ * @param $account
+ *   The user to check for. Leave it to NULL to check for the global user.
+ * @return boolean
+ *   Whether access is allowed or not.
+ */
+function tripal_entities_entity_access($op, $entity = NULL, $account = NULL) {
+  if (user_access('administer tripal data', $account)) {
+    return TRUE;
+  }
+  if (isset($entity) && $type_name = $entity->type) {
+    $op = ($op == 'view') ? 'view' : 'edit';
+    if (user_access("$op any $type_name data", $account)) {
+      return TRUE;
+    }
+  }
+  return FALSE;
+}
+
+/**
+ * Menu callback to display an entity.
+ *
+ * As we load the entity for display, we're responsible for invoking a number
+ * of hooks in their proper order.
+ *
+ * @see hook_entity_prepare_view()
+ * @see hook_entity_view()
+ * @see hook_entity_view_alter()
+ */
+function tripal_entities_view_entity($entity, $view_mode = 'full') {
+  $content = '';
+  $controller = entity_get_controller($entity->type);
+  $content = $controller->view(array($entity->id => $entity));
+  drupal_set_title($entity->title);
+  return $content;
+}
+
+/**
+ * Menu title callback for showing individual entities
+ */
+function tripal_entities_entity_title($entity){
+  if ($entity) {
+    return $entity->title;
+  }
+}

+ 2 - 2
tripal_entities/tripal_entities.module

@@ -2,6 +2,7 @@
 
 require_once "api/tripal_entities.api.inc";
 require_once "includes/tripal_entities.chado_entity.inc";
+require_once "includes/tripal_entities.entity_form.inc";
 require_once "includes/tripal_entities.tables.inc";
 require_once "includes/TripalEntity.inc";
 require_once "includes/TripalEntityController.inc";
@@ -46,8 +47,7 @@ function tripal_entities_menu() {
   $items['admin/tripal/bio_data/publish'] = array(
     'title' => 'Publish',
     'description' => 'Publish Data',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_entities_admin_publish_form'),
+    'page callback' => 'tripal_entities_publish',
     'access arguments' => array('administer tripal data types'),
     'file' =>  'includes/tripal_entities.admin.inc',
     'type' => MENU_LOCAL_TASK,

+ 10 - 10
tripal_fields/includes/tripal_fields.field_storage.inc

@@ -2,7 +2,7 @@
 /**
  * Implements hook_field_storage_info().
  */
-function tripal_entities_field_storage_info() {
+function tripal_fields_field_storage_info() {
   return array(
     'field_chado_storage' => array(
       'label' => t('Chado storage'),
@@ -17,16 +17,16 @@ function tripal_entities_field_storage_info() {
  *
  * @param $query
  */
-function tripal_entities_field_storage_query($query) {
+function tripal_fields_field_storage_query($query) {
   // TODO: figure out what this function does.
 }
 /**
  * Implements hook_field_storage_write().
  */
-function tripal_entities_field_storage_write($entity_type, $entity, $op, $fields) {
+function tripal_fields_field_storage_write($entity_type, $entity, $op, $fields) {
 
   // Convert the fields into a key/value list of fields and their values.
-  $field_vals = tripal_entities_field_storage_unnest_fields($fields, $entity_type, $entity);
+  $field_vals = tripal_fields_field_storage_unnest_fields($fields, $entity_type, $entity);
 
   switch ($op) {
     case FIELD_STORAGE_INSERT:
@@ -43,7 +43,7 @@ function tripal_entities_field_storage_write($entity_type, $entity, $op, $fields
         $data_table = $usage->data_table;
         //$type_table = $usage->type_table;
         $type_field = $usage->field;
-        tripal_entities_field_storage_write_recursive($entity_type, $entity,
+        tripal_fields_field_storage_write_recursive($entity_type, $entity,
           $op, $field_vals, $data_table, $type_field);
       }
       break;
@@ -60,7 +60,7 @@ function tripal_entities_field_storage_write($entity_type, $entity, $op, $fields
       $type_field = $details->field;
       $record_id = $details->record_id;
 
-      tripal_entities_field_storage_write_recursive($entity_type, $entity,
+      tripal_fields_field_storage_write_recursive($entity_type, $entity,
         $op, $field_vals, $tablename, $type_field, $record_id);
       if (!$details) {
         // TODO: what to do if record is missing!
@@ -72,7 +72,7 @@ function tripal_entities_field_storage_write($entity_type, $entity, $op, $fields
 /**
  * Implements hook_field_storage_write_recursive().
  */
-function tripal_entities_field_storage_write_recursive($entity_type, $entity,
+function tripal_fields_field_storage_write_recursive($entity_type, $entity,
    $op, $field_vals, $tablename, $type_field = NULL, $record_id = NULL, $depth = 0) {
 
   // Intialize the values array and $record_id;
@@ -113,7 +113,7 @@ function tripal_entities_field_storage_write_recursive($entity_type, $entity,
       }
       // Recurse on the FK field.  Pass in the ID for the FK field if one
       // exists in the $field_vals;
-      $fk_val = tripal_entities_field_storage_write_recursive($entity_type,
+      $fk_val = tripal_fields_field_storage_write_recursive($entity_type,
         $entity, $op, $field_vals, $fk_table, NULL, $fk_val, $depth + 1);
       if (isset($fk_val) and $fk_val != '' and $fk_val != 0) {
         $values[$local_id] = $fk_val;
@@ -207,7 +207,7 @@ function tripal_entities_field_storage_write_recursive($entity_type, $entity,
  * Responsible for loading the fields from the Chado database and adding
  * their values to the entity.
  */
-function tripal_entities_field_storage_load($entity_type, $entities, $age, $fields, $options) {
+function tripal_fields_field_storage_load($entity_type, $entities, $age, $fields, $options) {
   $load_current = $age == FIELD_LOAD_CURRENT;
   global $language;
   $langcode = $language->language;
@@ -273,7 +273,7 @@ function tripal_entities_field_storage_load($entity_type, $entities, $age, $fiel
  *
  * @param $fields
  */
-function tripal_entities_field_storage_unnest_fields($fields, $entity_type, $entity) {
+function tripal_fields_field_storage_unnest_fields($fields, $entity_type, $entity) {
   $new_fields = array();
   foreach ($fields as $field_id => $ids) {
     $field = field_info_field_by_id($field_id);