Browse Source

Fixed bugs in menu

Stephen Ficklin 9 years ago
parent
commit
065e35fa18

+ 0 - 15
tripal_entities/includes/ChadoDataType.inc

@@ -10,19 +10,4 @@ class ChadoDataType extends Entity {
   public function __construct($values = array()) {
     parent::__construct($values, 'chado_data_type');
   }
-}
-
-/**
- * Gets an array of all chado data types, keyed by the type name.
- *
- * @param $type_name
- *   If set, the type with the given name is returned.
- * @return ChadoDataType[]
- *   Depending whether $type isset, an array of chado data types or a single one.
- */
-function chado_data_get_types($type_name = NULL) {
-  // entity_load will get the Entity controller for our entity and call the load
-  // function of that object - we are loading entities by name here.
-  $types = entity_load_multiple_by_name('chado_data_type', isset($type_name) ? array($type_name) : FALSE);
-  return isset($type_name) ? reset($types) : $types;
 }

+ 0 - 11
tripal_entities/includes/ChadoDataTypeUIController.inc

@@ -106,14 +106,3 @@ function chado_data_type_form_submit_delete(&$form, &$form_state) {
   $form_state['redirect'] = 'admin/structure/chado_data_types/manage/' . $form_state['chado_data_type']->type . '/delete';
 }
 
-/**
- * Menu argument loader; Load a model type by string.
- *
- * @param $type
- *   The machine-readable name of a model type to load.
- * @return
- *   A model type array or FALSE if $type does not exist.
- */
-function chado_data_type_load($type) {
-  return chado_data_get_types($type);
-}

+ 24 - 61
tripal_entities/includes/ChadoDataUIController.inc

@@ -26,11 +26,17 @@ class ChadoDataUIController extends EntityDefaultUIController {
       'type' => MENU_LOCAL_TASK,
     );
 
-    $items[$this->path . '/list'] = array(
-      'title' => 'Chado Data',
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-      'weight' => -10,
-    );
+    foreach (chado_data_get_types() as $type) {
+      $items[$this->path . '/add/' . $type->type] = array(
+        'title' => 'Add ' . $type->label,
+        'page callback' => 'model_form_wrapper',
+        'page arguments' => array(chado_data_create(array('type' => $type->type))),
+        'access callback' => 'model_access',
+        'access arguments' => array('edit', 'edit ' . $type->type),
+        'file' => 'model.admin.inc',
+        'file path' => drupal_get_path('module', $this->entityInfo['module'])
+      );
+    }
 
     // Add an action link to the admin page for adding new data.
     $items[$this->path . '/add'] = array(
@@ -56,9 +62,7 @@ class ChadoDataUIController extends EntityDefaultUIController {
       'weight' => 20,
     );
 
-    // The page to view our entities - needs to follow what
-    // is defined in basic_uri and will use load_basic to retrieve
-    // the necessary entity info.
+    // Link for viewing a chado data type.
     $items['data/' . $wildcard] = array(
       'title callback' => 'chado_data_title',
       'title arguments' => array(1),
@@ -72,8 +76,13 @@ class ChadoDataUIController extends EntityDefaultUIController {
     // 'View' tab for an individual entity page.
     $items['data/' . $wildcard . '/view'] = array(
       'title' => 'View',
+      'page callback' => 'chado_data_view',
+      'page arguments' => array(1),
+      'access callback' => 'chado_data_access',
+      'access arguments' => array('view', 1),
       'type' => MENU_DEFAULT_LOCAL_TASK,
       'weight' => -10,
+
     );
 
     // 'Edit' tab for an individual entity page.
@@ -84,17 +93,18 @@ class ChadoDataUIController extends EntityDefaultUIController {
       'access callback' => 'chado_data_access',
       'access arguments' => array('edit', 1),
       'type' => MENU_LOCAL_TASK,
+
     );
 
     // Menu item for deleting chado data entities.
     $items['data/' . $wildcard . '/delete'] = array(
-      'title' => 'Delete',
+      'title'  => 'Delete',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('chado_data_delete_form', 1),
       'access callback' => 'chado_data_access',
       'access arguments' => array('edit', 1),
-      'type' => MENU_LOCAL_TASK,
-      'context' => MENU_CONTEXT_INLINE,
+      'type' => MENU_CALLBACK,
+
       'weight' => 10,
     );
     return $items;
@@ -139,6 +149,7 @@ function chado_data_form($form, &$form_state, $entity = NULL) {
 
   // Set defaults if an entity was provided.
   if ($entity) {
+    drupal_set_title('Edit ' . $entity->title);
     $entity_id = $entity->entity_id;
     $values = array('cvterm_id' => $entity->cvterm_id);
     $cvterm = chado_generate_var('cvterm', $values);
@@ -326,12 +337,6 @@ function chado_data_form($form, &$form_state, $entity = NULL) {
     // the Entity API to work.  It must have a key of the entity name.
     $form_state['chado_data'] = $entity;
   }
-  $form['cancel'] = array(
-    '#type' => 'submit',
-    '#value' => t('Cancel'),
-    '#name' => 'cancel',
-    '#weight' => 1000
-  );
   $form['#prefix'] = '<div id="chado_data_form">';
   $form['#suffix'] = '</div>';
   return $form;
@@ -533,50 +538,8 @@ function chado_data_view($entity, $view_mode = 'full') {
 }
 
 /**
- *
- * @param unknown $entity
+ * Menu title callback for showing individual entities
  */
-function chado_data_title($entity) {
+function chado_data_title(ChadoData $entity){
   return $entity->title;
-}
-
-
-
-
-/**
- * Fetch an entity object. Make sure that the wildcard you choose
- * in the model entity definition fits the function name here.
- *
- * @param $entity_id
- *   Integer specifying the entity id.
- * @param $reset
- *   A boolean indicating that the internal cache should be reset.
- * @return
- *   A fully-loaded $model object or FALSE if it cannot be loaded.
- *
- * @see chado_data_load_multiple()
- */
-function chado_data_load($entity_id, $reset = FALSE) {
-  $entities = model_load_multiple(array($entity_id), array(), $reset);
-  return reset($entities);
-}
-
-
-/**
- * Load multiple entiies based on certain conditions.
- *
- * @param $entity_ids
- *   An array of entity IDs.
- * @param $conditions
- *   An array of conditions to match against the {chado_data} table.
- * @param $reset
- *   A boolean indicating that the internal cache should be reset.
- * @return
- *   An array of entity objects, indexed by entity_ids.
- *
- * @see entity_load()
- * @see chado_data_load()
- */
-function chado_data_load_multiple($entity_ids = array(), $conditions = array(), $reset = FALSE) {
-  return entity_load('chado_data', $entity_ids, $conditions, $reset);
 }

+ 4 - 1
tripal_entities/tripal_entities.module

@@ -1,5 +1,6 @@
 <?php
 
+require_once "api/tripal_entities.api.inc";
 require_once "includes/tripal_entities.field_storage.inc";
 require_once "includes/tripal_entities.fields.inc";
 require_once "includes/ChadoData.inc";
@@ -196,6 +197,9 @@ function tripal_entities_entity_info() {
     // Bundles are defined below.
     'bundles' => array(),
 
+    'label callback' => 'entity_class_label',
+    'creation callback' => 'chado_data_create',
+
     // The information below is used by the ChadoDataUIController
     // (which extends the EntityDefaultUIController).  The admin_ui
     // key here is mean to appear on the 'Find Content' page of the
@@ -251,7 +255,6 @@ function tripal_entities_entity_info() {
     // Enable the entity API's admin UI.
     'admin ui' => array(
       'path' => 'admin/structure/chado_data_types',
-      'file' => 'includes/tripal_entities.admin.inc',
       'controller class' => 'ChadoDataTypeUIController',
     ),
   );

+ 4 - 18
tripal_entities/tripal_entities.views.inc

@@ -6,25 +6,11 @@
  */
 
 /**
- * Implements hook_views_handlers().
- *
- * Purpose: Register all custom handlers with views
- *   where a handler describes either "the type of field",
- *   "how a field should be filtered", "how a field should be sorted"
- *
- * @return: An array of handler definitions
- *
- * @ingroup tripal_feature
+ * Implements hook_views_api().
  */
-function tripal_entities_views_handlers() {
+function tripal_entities_views_api() {
   return array(
-    'info' => array(
-      'path' => drupal_get_path('module', 'tripal_entities') . '/views_handlers',
-    ),
-    'handlers' => array(
-      'views_handler_field_residues' => array(
-        'parent' => 'views_handler_field',
-      ),
-    ),
+    'api' => 3,
+    'path' => drupal_get_path('module', 'tripal_entities') . '/views',
   );
 }