Browse Source

Fixed bugs after renaming paths

Stephen Ficklin 9 years ago
parent
commit
575129c0b4

+ 0 - 50
tripal_entities/api/tripal_entities.api.inc

@@ -1,55 +1,5 @@
 <?php
 
-/**
- * Menu argument loader; Load a tripal data type by string.
- *
- * @param $type
- *   The machine-readable name of a tripal data type to load.
- * @return
- *   A tripal data type array or FALSE if $type does not exist.
- */
-
-function tripal_data_type_load($bundle_type, $reset = FALSE) {
-
-  // Get the type of entity by the ID.
-  $bundle_types = db_select('tripal_data_type', 'tdt')
-    ->fields('tdt', array('id', 'type'))
-    ->condition('bundle', $bundle_type)
-    ->execute()
-    ->fetchObject();
-
-  // Load the entity.
-  $entity = entity_load($bundle_types->type, array($bundle_types->id), array(), $reset);
-  return reset($entity);
-}
-
-/**
- * Fetch a tripal_data object. Make sure that the wildcard you choose
- * in the tripal_data entity definition fits the function name here.
- *
- * @param $id
- *   Integer specifying the tripal_data id.
- * @param $reset
- *   A boolean indicating that the internal cache should be reset.
- * @return
- *   A fully-loaded $tripal_data object or FALSE if it cannot be loaded.
- *
- * @see tripal_data_load_multiple()
- */
-function tripal_data_load($id, $reset = FALSE) {
-
-  // Get the type of entity by the ID.
-  $entity_type = db_select('tripal_data', 'td')
-    ->fields('td', array('type'))
-    ->condition('id', $id)
-    ->execute()
-    ->fetchField();
-
-  // Load the entity.
-  $entity =  entity_load($entity_type, array($id), array(), $reset);
-  return reset($entity);
-}
-
 
 /**
  * Deletes a tripal_data.

+ 33 - 4
tripal_entities/includes/TripalDataTypeUIController.inc

@@ -38,7 +38,6 @@ class TripalDataTypeUIController extends EntityDefaultUIController {
     unset($items[$this->path . '/add']);
     unset($items[$this->path . '/import']);
 
-
     $items[$this->path . '/publish'] = array(
       'title' => 'Add new biological data type',
       'description' => 'Publish Data',
@@ -50,9 +49,39 @@ class TripalDataTypeUIController extends EntityDefaultUIController {
       'type' => MENU_LOCAL_ACTION,
       'weight' => 2
     );
-
     return $items;
   }
+
+  /**
+   * Allows us to change the forms created by the parent class.
+   */
+  function hook_forms() {
+    $forms = parent::hook_forms();
+
+    // The edit form for the entity type by default expects a function,
+    // named after the entity type but we can't dynamically create these
+    // functions. We'll use a single form for all entity types.
+    $forms[$this->entityType . '_form'] = array(
+      'callback' => 'tripal_entities_tripal_data_type_form',
+      'callback arguments' => array($this->entityType)
+    );
+
+    return $forms;
+  }
+}
+/**
+ *
+ * @param $form
+ * @param $form_state
+ * @param $entity
+ */
+function tripal_entities_tripal_data_type_form($form, &$form_state, $entityDataType) {
+  $form = array();
+  $form['message'] = array(
+    '#type' => 'item',
+    '#markup' => 'Edit the function "tripal_entities_tripal_data_type_form()" to add a form each type. Put access controls here?',
+  );
+  return $form;
 }
 /**
  * Access callback for the entity API.
@@ -89,13 +118,13 @@ function tripal_data_type_form($form, &$form_state, $tripal_data_type, $op = 'ed
 function tripal_data_type_form_submit(&$form, &$form_state) {
   $tripal_data_type = entity_ui_form_submit_build_entity($form, $form_state);
   $tripal_data_type->save();
-  $form_state['redirect'] = 'admin/structure/bio_data_types';
+  $form_state['redirect'] = $this->path;
 }
 
 /**
  * Form API submit callback for the delete button.
  */
 function tripal_data_type_form_submit_delete(&$form, &$form_state) {
-  $form_state['redirect'] = 'admin/structure/bio_data_types/manage/' . $form_state['tripal_data_type']->type . '/delete';
+  $form_state['redirect'] = $this->path;
 }
 

+ 1 - 1
tripal_entities/includes/tripal_entities.admin.inc

@@ -368,7 +368,7 @@ function tripal_entities_admin_publish_form_submit($form, &$form_state) {
         'data' => serialize(array()),
         'module' => 'tripal_entities'
       );
-      $tripal_data_type = new TripalDataType($vals, $entity_type_name);
+      $tripal_data_type = new TripalDataType($vals, $entity_type_name . '_type');
       $tripal_data_type->save();
     }
     drupal_set_message(t('Data type, %type, is now set as publishable.', array('%type' => $term_name)));

+ 1 - 1
tripal_entities/tripal_entities.install

@@ -446,7 +446,7 @@ function tripal_entities_schema() {
     ) + entity_exportable_schema_fields(),
     'primary key' => array('id'),
     'unique keys' => array(
-      'type' => array('type'),
+      'bundle' => array('bundle'),
     ),
   );
   return $schema;

+ 59 - 6
tripal_entities/tripal_entities.module

@@ -223,7 +223,7 @@ function tripal_entities_entity_info() {
       'module' => 'tripal_entities',
       // Enable the entity API's admin UI.
       'admin ui' => array (
-        'path' => 'admin/structure/bio_data',
+        'path' => 'admin/structure/bio_data/' . $voc->db_id->name,
         'controller class' => 'TripalDataTypeUIController',
         'file' => 'includes/TripalDataTypeUIController.inc',
         'menu wildcard' => '%tripal_data_type',
@@ -249,14 +249,17 @@ function tripal_entities_entity_info_alter(&$entity_info) {
     // associated with a base entity type.
     // We want to dynamically add the bundles (or term types) to the entity.
     $cvterm = $term->cvterm_id;
-    $bundle_id = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
+    $entity_type  = $cvterm->dbxref_id->db_id->name;
+    $accession = $cvterm->dbxref_id->accession;
+    $bundle_id = $entity_type . '_' . $accession;
+
     $label = preg_replace('/_/', ' ', ucwords($cvterm->name));
-    $entity_info[$cvterm->dbxref_id->db_id->name]['bundles'][$bundle_id] = array (
+    $entity_info[$entity_type]['bundles'][$bundle_id] = array (
       'label' => $label,
       'admin' => array (
-        'path' => 'admin/structure/bio_data/manage/%tripal_data_type',
-        'real path' => 'admin/structure/bio_data/manage/' . $bundle_id,
-        'bundle argument' => 4,
+        'path' => 'admin/structure/bio_data/' . $entity_type . '/manage/%tripal_data_type',
+        'real path' => 'admin/structure/bio_data/' . $entity_type . '/manage/' . $bundle_id,
+        'bundle argument' => 5,
         'access arguments' => array (
           'administer tripal data types'
         )
@@ -296,4 +299,54 @@ function tripal_entities_get_published_terms_as_select_options($cv_id = NULL) {
     }
   }
   return $options;
+}
+
+/**
+ * Menu argument loader; Load a tripal data type by string.
+ *
+ * @param $type
+ *   The machine-readable name of a tripal data type to load.
+ * @return
+ *   A tripal data type array or FALSE if $type does not exist.
+ */
+
+function tripal_data_type_load($bundle_type, $reset = FALSE) {
+  // Get the type of entity by the ID.
+  $bundle_types = db_select('tripal_data_type', 'tdt')
+    ->fields('tdt', array('id', 'type'))
+    ->condition('bundle', $bundle_type)
+    ->execute()
+    ->fetchObject();
+
+  // Load the tripal_data_type entity. These entities are always the same
+  // as an Tripal entity type but with a '_type' extension.
+  $entity = entity_load($bundle_types->type . '_type', array($bundle_types->id), array(), $reset);
+  return reset($entity);
+}
+
+/**
+ * Fetch a tripal_data object. Make sure that the wildcard you choose
+ * in the tripal_data entity definition fits the function name here.
+ *
+ * @param $id
+ *   Integer specifying the tripal_data id.
+ * @param $reset
+ *   A boolean indicating that the internal cache should be reset.
+ * @return
+ *   A fully-loaded $tripal_data object or FALSE if it cannot be loaded.
+ *
+ * @see tripal_data_load_multiple()
+ */
+function tripal_data_load($id, $reset = FALSE) {
+
+  // Get the type of entity by the ID.
+  $entity_type = db_select('tripal_data', 'td')
+    ->fields('td', array('type'))
+    ->condition('id', $id)
+    ->execute()
+    ->fetchField();
+
+  // Load the entity.
+  $entity =  entity_load($entity_type, array($id), array(), $reset);
+  return reset($entity);
 }