Browse Source

Entity content finder and structure changer are working

Stephen Ficklin 9 years ago
parent
commit
cc77f29700

+ 5 - 27
tripal_entities/api/tripal_entities.api.inc

@@ -9,42 +9,20 @@
  *   A tripal data type array or FALSE if $type does not exist.
  */
 
-function tripal_data_type_load($type) {
+function tripal_data_type_load($bundle_type, $reset = FALSE) {
 
   // 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'))
+  $bundle_types = db_select('tripal_data_type', 'tdt')
+    ->fields('tdt', array('id', 'type'))
     ->condition('bundle', $bundle_type)
     ->execute()
-    ->fetchField();
+    ->fetchObject();
 
   // Load the entity.
-  $entity =  entity_load($entity_type, array($id), array(), $reset);
+  $entity = entity_load($bundle_types->type, array($bundle_types->id), array(), $reset);
   return reset($entity);
 }
 
-/**
- * Gets an array of all tripal_data types, keyed by the type name.
- *
- * @param $type_name
- *   If set, the type with the given name is returned.
- * @return TripalDataType[]
- *   Depending whether $type isset, an array of tripal_data types or a single one.
- */
-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;
-}
-
 /**
  * Fetch a tripal_data object. Make sure that the wildcard you choose
  * in the tripal_data entity definition fits the function name here.

+ 2 - 4
tripal_entities/includes/TripalDataType.inc

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

+ 14 - 0
tripal_entities/includes/TripalDataTypeController.inc

@@ -5,6 +5,20 @@
 class TripalDataTypeController extends EntityAPIControllerExportable {
   public function __construct($entityType) {
     parent::__construct($entityType);
+    // The 'bundle of' property is usually set in the hook_entity_info()
+    // function for the "entity type" entity.  This allows the Entity API
+    // to provide the user interface for managing fields attached to the
+    // bundle.  But, we are using the same controller classes for
+    // all entity types and we do not want new links for every
+    // entity type (vocabulary) on the Administration >> Structure menu.
+    // We just want one menu item.  So to support one menu item that
+    // can handle all of the Tripal entity types, we have to set the
+    // 'bundle of' property here rather than in the hook_entity_info() function.
+    $bundle_of = $entityType;
+    $bundle_of = preg_replace('/_type/', '', $bundle_of);
+    $info = entity_get_info($bundle_of);
+    $this->bundleKey = $info['bundle keys']['bundle'];
+    $this->entityInfo['bundle of'] = $bundle_of;
   }
 
   /**

+ 33 - 5
tripal_entities/includes/TripalDataTypeUIController.inc

@@ -9,6 +9,22 @@
  */
 class TripalDataTypeUIController extends EntityDefaultUIController {
 
+  public function __construct($entity_type, $entity_info) {
+    // The 'bundle of' property is usually set in the hook_entity_info()
+    // function for the "entity type" entity.  This allows the Entity API
+    // to provide the user interface for managing fields attached to the
+    // bundle.  But, we are using the same controller classes for
+    // all entity types and we do not want new links for every
+    // entity type (vocabulary) on the Administration >> Structure menu.
+    // We just want one menu item.  So to support one menu item that
+    // can handle all of the Tripal entity types, we have to set the
+    // 'bundle of' property here rather than in the hook_entity_info() function.
+    $bundle_of = $entity_type;
+    $bundle_of = preg_replace('/_type/', '', $bundle_of);
+    $entity_info['bundle of'] = $bundle_of;
+    parent::__construct($entity_type, $entity_info);
+  }
+
   /**
    * Overrides hook_menu() defaults.
    */
@@ -19,10 +35,22 @@ 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']);
+
+
+    $items[$this->path . '/publish'] = array(
+      'title' => 'Add new biological data type',
+      'description' => 'Publish Data',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('tripal_entities_admin_publish_form'),
+      'access arguments' => array('administer tripal data types'),
+      'file' =>  'includes/tripal_entities.admin.inc',
+      'file path' => drupal_get_path('module', 'tripal_entities'),
+      'type' => MENU_LOCAL_ACTION,
+      'weight' => 2
+    );
 
-    drupal_debug($items);
     return $items;
   }
 }
@@ -61,13 +89,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/tripal_data_types';
+  $form_state['redirect'] = 'admin/structure/bio_data_types';
 }
 
 /**
  * Form API submit callback for the delete button.
  */
 function tripal_data_type_form_submit_delete(&$form, &$form_state) {
-  $form_state['redirect'] = 'admin/structure/tripal_data_types/manage/' . $form_state['tripal_data_type']->type . '/delete';
+  $form_state['redirect'] = 'admin/structure/bio_data_types/manage/' . $form_state['tripal_data_type']->type . '/delete';
 }
 

+ 10 - 69
tripal_entities/includes/TripalDataUIController.inc

@@ -16,18 +16,16 @@ class TripalDataUIController extends EntityDefaultUIController {
     $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
     $id_count = count(explode('/', $this->path));
 
+    // The content menu.
     $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',
+      'title' => 'Biological Data',
+      'page callback' => 'tripal_entities_content_view',
+      'file' =>  'includes/tripal_entities.admin.inc',
+      'file path' => drupal_get_path('module', 'tripal_entities'),
+      'access arguments' => array('administer tripal data'),
+      'type' => MENU_LOCAL_TASK,
     );
 
-    // 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',
@@ -35,69 +33,12 @@ class TripalDataUIController extends EntityDefaultUIController {
       'page callback'  => 'drupal_get_form',
       'page arguments' => array('tripal_data_form'),
       'access callback'  => 'tripal_data_access',
-      'access arguments' => array('edit'),
+      'access arguments' => array('administer tripal data'),
       'type' => MENU_LOCAL_ACTION,
       'weight' => 20,
     );
 
-    // 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.
+     // 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',
@@ -153,7 +94,7 @@ class TripalDataUIController extends EntityDefaultUIController {
       'type' => MENU_CALLBACK,
 
       'weight' => 10,
-    ); */
+    );
     return $items;
   }
 

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

@@ -363,7 +363,7 @@ function tripal_entities_admin_publish_form_submit($form, &$form_state) {
       // Therefore, we need to add a new entity for each bundle "type".
        $vals = array(
         'label' => $bundle_name  . ' (' . $type->name . ')',
-        'type' => $bundle_name,
+        'type' => $entity_type_name,
         'bundle' => $bundle_name,
         'data' => serialize(array()),
         'module' => 'tripal_entities'

+ 0 - 1
tripal_entities/includes/tripal_entities.field_storage.inc

@@ -16,7 +16,6 @@ function tripal_entities_field_storage_info() {
  * Implements hook_field_storage_write().
  */
 function tripal_entities_field_storage_write($entity_type, $entity, $op, $fields) {
-  dpm($entity_type);
   drupal_debug($entity_type);
   // Get the IDs for this entity.
   list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);

+ 11 - 3
tripal_entities/tripal_entities.install

@@ -409,13 +409,21 @@ function tripal_entities_schema() {
         'description' => 'Primary Key: Unique Chado data type identifier.',
       ),
       'type' => array(
-        'description' => 'The machine-readable name of this tripal data type.',
+        'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).',
         'type' => 'varchar',
-        'length' => 255,
+        'length' => 64,
         'not null' => TRUE,
+        'default' => '',
+      ),
+      'bundle' => array(
+        'description' => 'The type of bundle. This should be an official vocabulary ID (e.g. SO, RO, GO) followed by an underscore and the term accession.',
+        'type' => 'varchar',
+        'length' => 1024,
+        'not null' => TRUE,
+        'default' => '',
       ),
       'label' => array(
-        'description' => 'The human-readable name of this tripal data type.',
+        'description' => 'The human-readable name of this bundle.',
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE,

+ 14 - 49
tripal_entities/tripal_entities.module

@@ -27,26 +27,8 @@ function tripal_entities_menu() {
 
   $items = array();
 
-/*   // The content menu.
-  $items['admin/content/tripal_data'] = array(
-    'title' => 'Biological Data',
-    'page callback' => 'tripal_entities_content_view',
-    'file' =>  'includes/tripal_entities.admin.inc',
-    'access arguments' => array('administer tripal data'),
-    'type' => MENU_LOCAL_TASK,
-  );
-
-  $items['admin/content/tripal_data/add'] = array(
-    'title' => 'Add Biological Data',
-    'page callback'  => 'drupal_get_form',
-    'page arguments' => array('tripal_data_form'),
-    'access arguments' => array('administer tripal data'),
-    'type' => MENU_LOCAL_ACTION,
-  ); */
-
-
   // The administative settings menu.
-  $items['admin/tripal/data_types'] = array(
+  $items['admin/tripal/bio_data'] = array(
     'title' => 'Biological Data',
     'description' => 'Tools for publishing, configurating and managing biological data.',
     'page callback' => 'tripal_entities_admin_view',
@@ -56,13 +38,13 @@ function tripal_entities_menu() {
   );
 
   // The default tab.
-  $items['admin/tripal/data_types/default'] = array(
+  $items['admin/tripal/bio_data/default'] = array(
     'title' => 'Biological Data',
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'weight' =>  1,
   );
 
-  $items['admin/tripal/data_types/publish'] = array(
+  $items['admin/tripal/bio_data/publish'] = array(
     'title' => 'Publish',
     'description' => 'Publish Data',
     'page callback' => 'drupal_get_form',
@@ -73,7 +55,7 @@ function tripal_entities_menu() {
     'weight' => 2
   );
 
-  $items['admin/tripal/data_types/access'] = array(
+  $items['admin/tripal/bio_data/access'] = array(
     'title' => 'Access',
     'description' => 'Set default access permissions for collections of data.',
     'page callback' => 'drupal_get_form',
@@ -103,19 +85,6 @@ function tripal_entities_permission() {
       'description' => t('Edit and delete all tripal data'),
     ),
   );
-
-  // Generate permissions per each data type.
-  foreach (tripal_data_get_types() as $type) {
-    $type_name = check_plain($type->type);
-    $permissions += array(
-      "edit any $type_name data" => array(
-        'title' => t('%type_name: Edit any', array('%type_name' => $type->label)),
-      ),
-      "view any $type_name data" => array(
-        'title' => t('%type_name: View any', array('%type_name' => $type->label)),
-      ),
-    );
-  }
   return $permissions;
 }
 
@@ -175,7 +144,7 @@ function tripal_entities_entity_info() {
   $published_vocs = chado_generate_var('tripal_vocabulary', array('publish' => 1), array('return_array' => 1));
 
   foreach ($published_vocs as $voc) {
-    $entities [$voc->db_id->name] = array (
+    $entities[$voc->db_id->name] = array (
       // A human readable label to identify our entity.
       'label' => $voc->db_id->name . ' (' . $voc->cv_id->name . ')',
       'plural label' => $voc->db_id->name . ' (' . $voc->cv_id->name . ')',
@@ -221,7 +190,7 @@ function tripal_entities_entity_info() {
       // key here is mean to appear on the 'Find Content' page of the
       // administrative menu.
       'admin ui' => array (
-        'path' => 'admin/content/data',
+        'path' => 'admin/content/bio_data',
         'controller class' => 'TripalDataUIController',
         'menu wildcard' => '%tripal_data',
         'file' => 'includes/TripalDataUIController.inc'
@@ -237,28 +206,24 @@ function tripal_entities_entity_info() {
         )
       )
     );
-
-    // The entity that holds information about the entity types
+    // The entity that holds information about the entity types.
     $entities [$voc->db_id->name . '_type'] = array (
-      'label' => t ($voc->db_id->name . ' (' . $voc->cv_id->name . ')' . ' Type' ),
+      'label' => $voc->db_id->name . ' (' . $voc->cv_id->name . ') Data Types',
       'entity class' => 'TripalDataType',
       'controller class' => 'TripalDataTypeController',
       'base table' => 'tripal_data_type',
       'fieldable' => FALSE,
-      // If this entity can be used as a bundle of another entity then
-      // that can be specified via the 'bundle of' key.
-      'bundle of' => $voc->db_id->name,
-      'exportable' => TRUE,
+      'exportable' => FALSE,
       'entity keys' => array (
         'id' => 'id',
-        'name' => 'type',
+        'name' => 'bundle',
         'label' => 'label'
       ),
       'access callback' => 'tripal_data_type_access',
       'module' => 'tripal_entities',
       // Enable the entity API's admin UI.
       'admin ui' => array (
-        'path' => 'admin/structure/data_types',
+        'path' => 'admin/structure/bio_data',
         'controller class' => 'TripalDataTypeUIController',
         'file' => 'includes/TripalDataTypeUIController.inc',
         'menu wildcard' => '%tripal_data_type',
@@ -278,7 +243,7 @@ function tripal_entities_entity_info_alter(&$entity_info) {
 
   // Get a list of published terms from 'tripal_term
   $published_terms = chado_generate_var('tripal_term', array('publish' => 1), array('return_array' => 1));
-  foreach ( $published_terms as $term ) {
+  foreach ($published_terms as $term) {
 
     // Bundles are alternative groups of fields or configuration
     // associated with a base entity type.
@@ -289,8 +254,8 @@ function tripal_entities_entity_info_alter(&$entity_info) {
     $entity_info[$cvterm->dbxref_id->db_id->name]['bundles'][$bundle_id] = array (
       'label' => $label,
       'admin' => array (
-        'path' => 'admin/structure/data_types/manage/%tripal_data_type',
-        'real path' => 'admin/structure/data_types/manage/' . $bundle_id,
+        'path' => 'admin/structure/bio_data/manage/%tripal_data_type',
+        'real path' => 'admin/structure/bio_data/manage/' . $bundle_id,
         'bundle argument' => 4,
         'access arguments' => array (
           'administer tripal data types'

+ 0 - 101
tripal_entities/tripal_entities.views_default.inc

@@ -1,103 +1,2 @@
 <?php
 
-function tripal_entities_views_default_views() {
-  $views = array();
-
-$view = new view();
-$view->name = 'tripal_data';
-$view->description = '';
-$view->tag = 'default';
-$view->base_table = 'tripal_data_type';
-$view->human_name = 'Tripal Data';
-$view->core = 7;
-$view->api_version = '3.0';
-$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
-
-/* Display: Master */
-$handler = $view->new_display('default', 'Master', 'default');
-$handler->display->display_options['title'] = 'Biological Data';
-$handler->display->display_options['use_more_always'] = FALSE;
-$handler->display->display_options['access']['type'] = 'perm';
-$handler->display->display_options['access']['perm'] = 'administer blocks';
-$handler->display->display_options['cache']['type'] = 'none';
-$handler->display->display_options['query']['type'] = 'views_query';
-$handler->display->display_options['exposed_form']['type'] = 'basic';
-$handler->display->display_options['pager']['type'] = 'full';
-$handler->display->display_options['style_plugin'] = 'table';
-$handler->display->display_options['style_options']['columns'] = array(
-  'id' => 'id',
-);
-$handler->display->display_options['style_options']['default'] = '-1';
-$handler->display->display_options['style_options']['info'] = array(
-  'id' => array(
-    'sortable' => 0,
-    'default_sort_order' => 'asc',
-    'align' => '',
-    'separator' => '',
-    'empty_column' => 0,
-  ),
-);
-/* No results behavior: Global: Text area */
-$handler->display->display_options['empty']['area']['id'] = 'area';
-$handler->display->display_options['empty']['area']['table'] = 'views';
-$handler->display->display_options['empty']['area']['field'] = 'area';
-$handler->display->display_options['empty']['area']['label'] = 'No Data';
-$handler->display->display_options['empty']['area']['empty'] = TRUE;
-$handler->display->display_options['empty']['area']['content'] = 'There is currently no data available.';
-$handler->display->display_options['empty']['area']['format'] = 'filtered_html';
-/* Field: Tripal Data Type: Internal, numeric tripal data type ID */
-$handler->display->display_options['fields']['id']['id'] = 'id';
-$handler->display->display_options['fields']['id']['table'] = 'tripal_data_type';
-$handler->display->display_options['fields']['id']['field'] = 'id';
-$handler->display->display_options['fields']['id']['label'] = 'Data ID';
-/* Field: Tripal Data Type: Label */
-$handler->display->display_options['fields']['label']['id'] = 'label';
-$handler->display->display_options['fields']['label']['table'] = 'tripal_data_type';
-$handler->display->display_options['fields']['label']['field'] = 'label';
-$handler->display->display_options['fields']['label']['label'] = 'Type ID';
-/* Field: Tripal Data Type: Machine-readable name */
-$handler->display->display_options['fields']['type']['id'] = 'type';
-$handler->display->display_options['fields']['type']['table'] = 'tripal_data_type';
-$handler->display->display_options['fields']['type']['field'] = 'type';
-$handler->display->display_options['fields']['type']['label'] = 'Type Name';
-/* Field: Tripal Data Type: Status */
-$handler->display->display_options['fields']['status']['id'] = 'status';
-$handler->display->display_options['fields']['status']['table'] = 'tripal_data_type';
-$handler->display->display_options['fields']['status']['field'] = 'status';
-/* Filter criterion: Tripal Data Type: Machine-readable name */
-$handler->display->display_options['filters']['type']['id'] = 'type';
-$handler->display->display_options['filters']['type']['table'] = 'tripal_data_type';
-$handler->display->display_options['filters']['type']['field'] = 'type';
-$handler->display->display_options['filters']['type']['exposed'] = TRUE;
-$handler->display->display_options['filters']['type']['expose']['operator_id'] = 'type_op';
-$handler->display->display_options['filters']['type']['expose']['label'] = 'Type';
-$handler->display->display_options['filters']['type']['expose']['operator'] = 'type_op';
-$handler->display->display_options['filters']['type']['expose']['identifier'] = 'type';
-$handler->display->display_options['filters']['type']['expose']['remember_roles'] = array(
-  2 => '2',
-  1 => 0,
-  3 => 0,
-);
-$handler->display->display_options['filters']['type']['group_info']['label'] = 'Machine-readable name';
-$handler->display->display_options['filters']['type']['group_info']['identifier'] = 'type';
-$handler->display->display_options['filters']['type']['group_info']['remember'] = FALSE;
-$handler->display->display_options['filters']['type']['group_info']['group_items'] = array(
-  1 => array(),
-  2 => array(),
-  3 => array(),
-);
-
-/* Display: Page */
-$handler = $view->new_display('page', 'Page', 'data_admin_page');
-$handler->display->display_options['path'] = 'admin/content/data/list';
-$handler->display->display_options['menu']['type'] = 'default tab';
-$handler->display->display_options['menu']['title'] = 'List';
-$handler->display->display_options['menu']['weight'] = '-10';
-$handler->display->display_options['menu']['context'] = 0;
-$handler->display->display_options['menu']['context_only_inline'] = 0;
-$handler->display->display_options['tab_options']['weight'] = '0';
-
-
-  $views[] = $view;
-  return $views;
-}