Browse Source

Manage fields now working

Stephen Ficklin 9 years ago
parent
commit
966a41c773

+ 18 - 15
tripal_entities/api/tripal_entities.api.inc

@@ -1,4 +1,19 @@
 <?php
+
+/**
+ * Menu argument loader; Load a chado data type by string.
+ *
+ * @param $type
+ *   The machine-readable name of a chado data type to load.
+ * @return
+ *   A chado data type array or FALSE if $type does not exist.
+ */
+
+function chado_data_type_load($type) {
+  $entity = chado_data_get_types($type);
+  return $entity;
+}
+
 /**
  * Gets an array of all chado_data types, keyed by the type name.
  *
@@ -14,20 +29,6 @@ function chado_data_get_types($type_name = NULL) {
   return isset($type_name) ? reset($types) : $types;
 }
 
-
-/**
- * Menu argument loader; Load a chado_data type by string.
- *
- * @param $type
- *   The machine-readable name of a chado_data type to load.
- * @return
- *   A chado_data type array or FALSE if $type does not exist.
- */
-function chado_data_type_load($type) {
-  return chado_data_get_types($type);
-}
-
-
 /**
  * Fetch a chado_data object. Make sure that the wildcard you choose
  * in the chado_data entity definition fits the function name here.
@@ -92,7 +93,9 @@ function chado_data_delete_multiple(array $entity_ids) {
 function chado_data_create($values = array()) {
   return entity_get_controller('chado_data')->create($values);
 }
-
+function chado_data_type_create($values = array()) {
+  return entity_get_controller('chado_data_type')->create($values);
+}
 
 /**
  * Saves a chado_data to the database.

+ 1 - 1
tripal_entities/includes/ChadoData.inc

@@ -1,6 +1,6 @@
 <?php
 /**
- * The class used for chado data entities.
+ * A class the controller will use for instantiating the ChadoData entity.
  */
 class ChadoData extends Entity {
   public function __construct($values = array()) {

+ 2 - 38
tripal_entities/includes/ChadoDataTypeUIController.inc

@@ -19,8 +19,8 @@ class ChadoDataTypeUIController extends EntityDefaultUIController {
 
     // We don't want to let the user add new Chado 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']);
 
     return $items;
   }
@@ -50,43 +50,7 @@ function chado_data_type_form($form, &$form_state, $chado_data_type, $op = 'edit
     '#required' => TRUE,
     '#size' => 30,
   );
-  // Machine-readable type name.
-  $form['type'] = array(
-    '#type' => 'machine_name',
-    '#default_value' => isset($chado_data_type->type) ? $chado_data_type->type : '',
-    '#maxlength' => 32,
-    //    '#disabled' => $chado_data_type->isLocked() && $op != 'clone',
-    '#machine_name' => array(
-      'exists' => 'chado_data_get_types',
-      'source' => array('label'),
-    ),
-    '#description' => t('A unique machine-readable name for this chado data type. It must only contain lowercase letters, numbers, and underscores.'),
-  );
-
-  $form['data']['#tree'] = TRUE;
-  $form['data']['sample_data'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('An interesting chado data switch'),
-    '#default_value' => !empty($chado_data_type->data['sample_data']),
-  );
 
-  $form['actions'] = array('#type' => 'actions');
-  $form['actions']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save chado data type'),
-    '#weight' => 40,
-  );
-
-  //Locking not supported yet
-  /*if (!$chado_data_type->isLocked() && $op != 'add') {
-  $form['actions']['delete'] = array(
-  '#type' => 'submit',
-  '#value' => t('Delete chado data type'),
-  '#weight' => 45,
-  '#limit_validation_errors' => array(),
-  '#submit' => array('chado_data_type_form_submit_delete')
-  );
-  }*/
   return $form;
 }
 

+ 18 - 17
tripal_entities/includes/ChadoDataUIController.inc

@@ -15,28 +15,18 @@ class ChadoDataUIController extends EntityDefaultUIController {
     $this->id_count = count(explode('/', $this->path));
     $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
 
-    // Create a new menu item on the Administer -> Find Content page.
+
     $items[$this->path] = array(
       'title' => 'Chado Data',
-      'description' => 'Add, edit and update chado data.',
-      'page callback' => 'drupal_get_form',
-      'page arguments' => array($this->entityType . '_overview_form', $this->entityType),
+      'description' => 'Add edit and update chado data.',
+      'page callback' => 'system_admin_menu_block_page',
       'access arguments' => array('access administration pages'),
-      'file' => 'includes/entity.ui.inc',
-      'type' => MENU_LOCAL_TASK,
+      'file path' => drupal_get_path('module', 'system'),
+      'file' => 'system.admin.inc',
     );
 
-    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'])
-      );
-    }
+    // Change the overview menu type for the list of models.
+    $items[$this->path]['type'] = MENU_LOCAL_TASK;
 
     // Add an action link to the admin page for adding new data.
     $items[$this->path . '/add'] = array(
@@ -243,7 +233,18 @@ function chado_data_form($form, &$form_state, $entity = NULL) {
       '#title' => 'Term',
       '#markup' => $cvterm->name,
     );
+
 /*
+
+    // Create the Chado data type entity.
+    $data_type_entity = chado_data_type_create(array(
+      'type' => $bundle_id,
+      'label' => $cvterm->name,
+      'module' => 'tripal_entities'
+    ));
+
+    $data_type_entity->save();
+
     // Drupal field types and settings:
     // https://www.drupal.org/node/1879542
     $field = array(

+ 43 - 122
tripal_entities/tripal_entities.module

@@ -10,67 +10,6 @@ require_once "includes/ChadoDataType.inc";
 require_once "includes/ChadoDataTypeController.inc";
 require_once "includes/ChadoDataTypeUIController.inc";
 
-/**
- * Implements hook_menu().
- */
-function tripal_entities_menu() {
-
-/*   // This provides a place for Field API to hang its own
-  // interface and has to be the same as what was defined
-  // in basic_entity_info() above.
-  $items['admin/structure/chado_data/manage'] = array(
-    'title' => 'Chado Data',
-    'description' => t('Manage chado records, including default status, fields, settings, etc.'),
-    'page callback' => 'tripal_entities_list_entities',
-    'access arguments' => array('administer chado_data'),
-  );
-  // Add entities.
-  $items['admin/structure/chado_data/manage/add'] = array(
-    'title' => 'Add Chado Data',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('chado_data_form'),
-    'access arguments' => array('create chado_data entities'),
-    'type' => MENU_LOCAL_ACTION,
-  );
-  // List of all chado_data entities.
-  $items['admin/structure/chado_data/manage/list'] = array(
-    'title' => 'List',
-    'type' => MENU_DEFAULT_LOCAL_TASK,
-  ); */
-  // 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.
-
-//   $items['chado_data/%chado_data'] = array(
-//     'title callback' => 'chado_data_title',
-//     'title arguments' => array(1),
-//     'page callback' => 'chado_data_view',
-//     'page arguments' => array(1),
-//     'access arguments' => array('view chado_data'),
-//     'type' => MENU_CALLBACK,
-//   );
-
-//   // 'View' tab for an individual entity page.
-//   $items['chado_data/%chado_data/view'] = array(
-//     'title' => 'View',
-//     'type' => MENU_DEFAULT_LOCAL_TASK,
-//     'weight' => -10,
-//   );
-
-//   // 'Edit' tab for an individual entity page.
-//   $items['chado_data/%chado_data/edit'] = array(
-//     'title' => 'Edit',
-//     'page callback' => 'drupal_get_form',
-//     'page arguments' => array('chado_data_form', 1),
-//     'access arguments' => array('edit any chado_data entity'),
-//     'type' => MENU_LOCAL_TASK,
-//   );
-
-
-  return $items;
-}
-
-
 
 /**
  * Implements hook_permission().
@@ -194,7 +133,7 @@ function tripal_entities_entity_info() {
     // FALSE disables caching. Caching functionality is handled by Drupal core.
     'static cache' => FALSE,
 
-    // Bundles are defined below.
+    // Bundles are added in the hook_entities_info_alter() function.
     'bundles' => array(),
 
     'label callback' => 'entity_class_label',
@@ -205,34 +144,20 @@ 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/chado_data',
-      'file' => 'includes/tripal_entities.admin.inc',
+      'path' => 'admin/content/data',
       'controller class' => 'ChadoDataUIController',
       'menu wildcard' => '%chado_data',
+      'file' => 'includes/ChadoDataUIController.inc',
     ),
-  );
-
-  // Bundles are alternative groups of fields or configuration
-  // associated with a base entity type.
-  // We want to dynamically add the bundles (or term types) to the entity.
-  $values = array(
-    'cv_id' => array(
-      'name' => 'sequence'
-    ),
-    'name' => 'gene',
-  );
-  $cvterm = chado_generate_var('cvterm', $values);
-  $label = preg_replace('/_/', ' ', ucwords($cvterm->name));
-  $bundle_id = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
-  $entities['trp_vocabulary_term']['bundles'][$bundle_id] = array(
-    'label' => $label,
-    'admin' => array(
-      'path' => 'admin/structure/chado_data/manage',
-      'access arguments' => array('administer chado_data entities'),
-    ),
-    'entity keys' => array(
-      'id' => 'entity_id',
-      'bundle' => 'bundle',
+    'view modes' => array(
+      'full' => array(
+        'label' => t('Full content'),
+        'custom settings' => FALSE,
+      ),
+      'teaser' => array(
+        'label' => t('Teaser'),
+        'custom settings' => TRUE,
+      ),
     ),
   );
 
@@ -243,6 +168,8 @@ function tripal_entities_entity_info() {
     'controller class' => 'ChadoDataTypeController',
     'base table' => 'chado_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' => 'chado_data',
     'exportable' => TRUE,
     'entity keys' => array(
@@ -254,47 +181,41 @@ function tripal_entities_entity_info() {
     'module' => 'tripal_entities',
     // Enable the entity API's admin UI.
     'admin ui' => array(
-      'path' => 'admin/structure/chado_data_types',
+      'path' => 'admin/structure/data_types',
       'controller class' => 'ChadoDataTypeUIController',
+      'file' => 'includes/ChadoDataTypeUIController.inc',
     ),
   );
   return $entities;
 }
-
 /**
- * Returns a render array with all chado_data entities.
+ * Implements hook_entity_info_alter().
+ *
+ * We are adding the info about the chado data types via a hook to avoid a
+ * recursion issue as loading the model types requires the entity info as well.
  *
- * @see pager_example.module
  */
-function tripal_entities_list_entities() {
-  $content = array();
-  // Load all of our entities.
-  $entities = chado_data_load_multiple();
-  if (!empty($entities)) {
-    foreach ($entities as $entity) {
-      // Create tabular rows for our entities.
-      $rows[] = array(
-        'data' => array(
-          'id' => $entity->entity_id,
-          'title' => l($entity->title, 'chado_data/' . $entity->entity_id),
-          'type' => $entity->type,
-        ),
-      );
-    }
-    // Put our entities into a themed table. See theme_table() for details.
-    $content['entity_table'] = array(
-      '#theme' => 'table',
-      '#rows' => $rows,
-      '#header' => array(t('ID'), t('Item Description'), t('Bundle')),
-    );
-  }
-  else {
-    // There were no entities. Tell the user.
-    $content[] = array(
-      '#type' => 'item',
-      '#markup' => t('No chado data entities currently exist.'),
-    );
-  }
-  return $content;
-}
+function tripal_entities_entity_info_alter(&$entity_info) {
 
+  // Bundles are alternative groups of fields or configuration
+  // associated with a base entity type.
+  // We want to dynamically add the bundles (or term types) to the entity.
+  $values = array(
+    'cv_id' => array(
+      'name' => 'sequence'
+    ),
+    'name' => 'gene',
+  );
+  $cvterm = chado_generate_var('cvterm', $values);
+  $label = preg_replace('/_/', ' ', ucwords($cvterm->name));
+  $type = $cvterm->dbxref_id->db_id->name . '_' . $cvterm->dbxref_id->accession;
+  $entity_info['chado_data']['bundles'][$type] = array(
+    'label' => $label,
+    'admin' => array(
+      'path' => 'admin/structure/data_types/manage/%chado_data_type',
+      'real path' => 'admin/structure/data_types/manage/' . $type,
+      'bundle argument' => 4,
+      'access arguments' => array('administer chado data types'),
+    ),
+  );
+}