Browse Source

Working on fixing Entity UI API classes

Stephen Ficklin 9 years ago
parent
commit
52e8272b52

+ 19 - 4
tripal_entities/api/tripal_entities.api.inc

@@ -11,8 +11,23 @@
 
 function tripal_data_type_load($type) {
 
-  $entity = tripal_data_get_types($type);
-  return $entity;
+  // Get the type of entity by the ID.
+  $bundle_type = db_select('tripal_data_type', 'tdt')
+    ->fields('tdt', array('type'))
+    ->condition('id', $id)
+    ->execute()
+    ->fetchField();
+
+  // Get the type of entity by the ID.
+  $entity_type = db_select('tripal_data', 'td')
+    ->fields('td', array('type'))
+    ->condition('bundle', $bundle_type)
+    ->execute()
+    ->fetchField();
+
+  // Load the entity.
+  $entity =  entity_load($entity_type, array($id), array(), $reset);
+  return reset($entity);
 }
 
 /**
@@ -26,8 +41,8 @@ function tripal_data_type_load($type) {
 function tripal_data_get_types($type_name = NULL) {
   // entity_load will get the Entity controller for our tripal_data entity and call the load
   // function of that object - we are loading entities by name here.
-  $types = entity_load_multiple_by_name('tripal_data_type', isset($type_name) ? array($type_name) : FALSE);
-  return isset($type_name) ? reset($types) : $types;
+//   $types = entity_load_multiple_by_name('tripal_data_type', isset($type_name) ? array($type_name) : FALSE);
+//   return isset($type_name) ? reset($types) : $types;
 }
 
 /**

+ 2 - 2
tripal_entities/includes/TripalDataType.inc

@@ -7,7 +7,7 @@ class TripalDataType extends Entity {
   public $type;
   public $label;
 
-  public function __construct($values = array()) {
-    parent::__construct($values, 'tripal_data_type');
+  public function __construct($values = array(), $entity_type) {
+    parent::__construct($values, $entity_type .'_type');
   }
 }

+ 3 - 2
tripal_entities/includes/TripalDataTypeUIController.inc

@@ -19,9 +19,10 @@ class TripalDataTypeUIController extends EntityDefaultUIController {
 
     // We don't want to let the user add new Tripal data types. They
     // are added automatically.
-     unset($items[$this->path . '/add']);
-     unset($items[$this->path . '/import']);
+    //unset($items[$this->path . '/add']);
+    //unset($items[$this->path . '/import']);
 
+    drupal_debug($items);
     return $items;
   }
 }

+ 84 - 2
tripal_entities/includes/TripalDataUIController.inc

@@ -14,8 +14,90 @@ class TripalDataUIController extends EntityDefaultUIController {
     // Set this on the object so classes that extend hook_menu() can use it.
     $this->id_count = count(explode('/', $this->path));
     $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
+    $id_count = count(explode('/', $this->path));
+
+    $items[$this->path] = array(
+      'title' => 'Biological Content',
+      'description' => 'Add edit and update models.',
+      'page callback' => 'system_admin_menu_block_page',
+      'access arguments' => array('access administration pages'),
+      'file path' => drupal_get_path('module', 'system'),
+      'file' => 'system.admin.inc',
+    );
+
+    // Change the overview menu type for the list of models.
+    $items[$this->path]['type'] = MENU_LOCAL_TASK;
+
+    // Change the add page menu to multiple types of entities
+    $items[$this->path . '/add'] = array(
+      'title' => 'Add new biological data',
+      'description' => 'Add new biological data',
+      'page callback'  => 'drupal_get_form',
+      'page arguments' => array('tripal_data_form'),
+      'access callback'  => 'tripal_data_access',
+      'access arguments' => array('edit'),
+      'type' => MENU_LOCAL_ACTION,
+      'weight' => 20,
+    );
 
-    // Set a custom page for adding new tripal data entities.
+    // Add menu items to add each different type of entity.
+//     foreach (tripal_data_get_types() as $type) {
+//       $items[$this->path . '/add/' . $type->type] = array(
+//         'title' => 'Add ' . $type->label,
+//         'page callback' => 'model_form_wrapper',
+//         'page arguments' => array(model_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'])
+//       );
+//     }
+
+    // Loading and editing model entities
+    $items[$this->path . '/model/' . $wildcard] = array(
+      'page callback' => 'model_form_wrapper',
+      'page arguments' => array($id_count + 1),
+      'access callback' => 'model_access',
+      'access arguments' => array('edit', $id_count + 1),
+      'weight' => 0,
+      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
+      'file' => 'model.admin.inc',
+      'file path' => drupal_get_path('module', $this->entityInfo['module'])
+    );
+    $items[$this->path . '/model/' . $wildcard . '/edit'] = array(
+      'title' => 'Edit',
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+      'weight' => -10,
+      'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
+    );
+
+    $items[$this->path . '/model/' . $wildcard . '/delete'] = array(
+      'title' => 'Delete',
+      'page callback' => 'model_delete_form_wrapper',
+      'page arguments' => array($id_count + 1),
+      'access callback' => 'model_access',
+      'access arguments' => array('edit', $id_count + 1),
+      'type' => MENU_LOCAL_TASK,
+      'context' => MENU_CONTEXT_INLINE,
+      'weight' => 10,
+      'file' => 'model.admin.inc',
+      'file path' => drupal_get_path('module', $this->entityInfo['module'])
+    );
+
+    // Menu item for viewing models
+    $items['model/' . $wildcard] = array(
+      //'title' => 'Title',
+      'title callback' => 'model_page_title',
+      'title arguments' => array(1),
+      'page callback' => 'model_page_view',
+      'page arguments' => array(1),
+      'access callback' => 'model_access',
+      'access arguments' => array('view', 1),
+      'type' => MENU_CALLBACK,
+    );
+    return $items;
+
+/*     // Set a custom page for adding new tripal data entities.
     $items['data/add'] = array(
       'title' => 'Add Tripal data',
       'description' => 'Add a new tripal data record',
@@ -71,7 +153,7 @@ class TripalDataUIController extends EntityDefaultUIController {
       'type' => MENU_CALLBACK,
 
       'weight' => 10,
-    );
+    ); */
     return $items;
   }
 

+ 11 - 0
tripal_entities/includes/tripal_entities.admin.inc

@@ -359,6 +359,17 @@ function tripal_entities_admin_publish_form_submit($form, &$form_state) {
       // Add in the bundle's fields.
       tripal_entities_add_bundle_fields($tablename, $entity_type_name, $bundle_name);
 
+      // The TripalDataType Entity manages the bundles we have available.
+      // Therefore, we need to add a new entity for each bundle "type".
+       $vals = array(
+        'label' => $bundle_name  . ' (' . $type->name . ')',
+        'type' => $bundle_name,
+        'bundle' => $bundle_name,
+        'data' => serialize(array()),
+        'module' => 'tripal_entities'
+      );
+      $tripal_data_type = new TripalDataType($vals, $entity_type_name);
+      $tripal_data_type->save();
     }
     drupal_set_message(t('Data type, %type, is now set as publishable.', array('%type' => $term_name)));
   }

+ 4 - 3
tripal_entities/tripal_entities.module

@@ -27,7 +27,7 @@ function tripal_entities_menu() {
 
   $items = array();
 
-  // The content menu.
+/*   // The content menu.
   $items['admin/content/tripal_data'] = array(
     'title' => 'Biological Data',
     'page callback' => 'tripal_entities_content_view',
@@ -42,7 +42,7 @@ function tripal_entities_menu() {
     'page arguments' => array('tripal_data_form'),
     'access arguments' => array('administer tripal data'),
     'type' => MENU_LOCAL_ACTION,
-  );
+  ); */
 
 
   // The administative settings menu.
@@ -260,7 +260,8 @@ function tripal_entities_entity_info() {
       'admin ui' => array (
         'path' => 'admin/structure/data_types',
         'controller class' => 'TripalDataTypeUIController',
-        'file' => 'includes/TripalDataTypeUIController.inc'
+        'file' => 'includes/TripalDataTypeUIController.inc',
+        'menu wildcard' => '%tripal_data_type',
       )
     );
   }