Browse Source

Fix menu speed

Abdullah Almsaeed 6 years ago
parent
commit
db2b374ce5
2 changed files with 27 additions and 6 deletions
  1. 16 3
      tripal/includes/TripalEntityUIController.inc
  2. 11 3
      tripal/includes/tripal.entity.inc

+ 16 - 3
tripal/includes/TripalEntityUIController.inc

@@ -60,7 +60,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     }
 
     // Link for viewing a tripal data type.
-    $items['bio_data/' . $wildcard] = array(
+    $items['bio_data/%'] = array(
       'title callback' => 'tripal_entity_title',
       'title arguments' => array(1),
       'page callback' => 'tripal_view_entity',
@@ -71,7 +71,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
     );
 
     // 'View' tab for an individual entity page.
-    $items['bio_data/' . $wildcard . '/view'] = array(
+    $items['bio_data/%/view'] = array(
       'title' => 'View',
       'page callback' => 'tripal_view_entity',
       'page arguments' => array(1),
@@ -115,7 +115,20 @@ class TripalEntityUIController extends EntityDefaultUIController {
  * @see hook_entity_view_alter()
  */
 function tripal_view_entity($entity, $view_mode = 'full') {
-   $content = '';
+   if(!is_object($entity)) {
+     $id = intval($entity);
+     if($id === 0) {
+       return drupal_not_found();
+     }
+
+     $entities = tripal_load_entity('TripalEntity', [$id]);
+     if(empty($entities)) {
+       return drupal_not_found();
+     }
+
+     $entity = reset($entities);
+   }
+
    $controller = entity_get_controller($entity->type);
    $content = $controller->view(array($entity->id => $entity));
    drupal_set_title($entity->title);

+ 11 - 3
tripal/includes/tripal.entity.inc

@@ -433,9 +433,13 @@ function tripal_field_property_get($entity, array $options, $field_name, $entity
 function tripal_entity_access($op, $entity = NULL, $account = NULL, $entity_type = NULL) {
   global $user;
 
-  if ($entity) {
+  if (is_object($entity)) {
     $bundle_name = $entity->bundle;
   }
+  elseif (intval($entity) !== 0) {
+    $sql = 'SELECT {bundle} FROM tripal_entity WHERE id = :id';
+    $bundle_name = db_query($sql, [':id' => $entity])->fetchField();
+  }
   else {
     return FALSE;
   }
@@ -444,8 +448,12 @@ function tripal_entity_access($op, $entity = NULL, $account = NULL, $entity_type
     $account = $user;
   }
 
-  if (!$entity_type) {
-    $entity_type = $entity->type;
+  if(!$entity_type) {
+    if(is_object($entity)) {
+      $entity_type = $entity->type;
+    } else {
+      $entity_type = 'TripalEntity';
+    }
   }
 
   // See if other modules want to adust permissions.