123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- <?php
- require_once "includes/tripal_entities.field_storage.inc";
- require_once "includes/tripal_entities.fields.inc";
- require_once "includes/ChadoData.inc";
- require_once "includes/ChadoDataController.inc";
- require_once "includes/ChadoDataUIController.inc";
- 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().
- */
- function tripal_entities_permission() {
- // We set up permisssions to manage entity types, manage all entities and the
- // permissions for each individual entity
- $permissions = array(
- 'administer chado data types' => array(
- 'title' => t('Administer Chado data types'),
- 'description' => t('Create and delete fields for Chado data types, and set their permissions.'),
- ),
- 'administer chado data' => array(
- 'title' => t('Administer Chado data'),
- 'description' => t('Edit and delete all chado data'),
- ),
- );
- // Generate permissions per each data type.
- foreach (chado_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;
- }
- /**
- * Implements hook_theme().
- */
- function tripal_entities_theme($existing, $type, $theme, $path) {
- return array(
- 'chado_data_add_list' => array(
- 'variables' => array('content' => array()),
- ),
- 'chado_data' => array(
- 'render element' => 'elements',
- 'template' => 'chado_data',
- ),
- );
- }
- /**
- * https://api.drupal.org/api/drupal/modules!rdf!rdf.module/group/rdf/7
- */
- function tripal_entities_rdf_mapping() {
- return array();
- /* return array(
- 'type' => 'chado_data',
- 'bundle' => 'gene',
- 'mapping' => array(
- 'rdftype' => array('sioc:Item', 'foaf:Document'),
- 'title' => array(
- 'predicates' => array('dc:title'),
- ),
- 'uid' => array(
- 'predicates' => array('sioc:has_creator'),
- 'type' => 'rel',
- ),
- 'name' => array(
- 'predicates' => array('foaf:name'),
- ),
- 'uniquename' => array(
- 'predicates' => array('foaf:name'),
- ),
- 'organism_id' => array(
- 'predicates' => array('sioc:has_parent'),
- 'type' => 'rel'
- )
- ),
- ); */
- }
- // http://www.bluespark.com/blog/drupal-entities-part-3-programming-hello-drupal-entity
- // http://dikini.net/31.08.2010/entities_bundles_fields_and_field_instances
- /**
- * Implement hook_entity_info().
- */
- function tripal_entities_entity_info() {
- $entities = array();
- $entities['chado_data'] = array(
- // A human readable label to identify our entity.
- 'label' => t('Chado Data'),
- 'plural label' => t('Vocabulary Terms'),
- // The entity class and controller class extend the classes provided by the
- // Entity API.
- 'entity class' => 'ChadoData',
- 'controller class' => 'ChadoDataController',
- // The table for this entity defined in hook_schema()
- 'base table' => 'chado_data',
- // Returns the uri elements of an entity.
- 'uri callback' => 'tripal_entities_vocbulary_term_uri',
- // IF fieldable == FALSE, we can't attach fields.
- 'fieldable' => TRUE,
- // entity_keys tells the controller what database fields are used for key
- // functions. It is not required if we don't have bundles or revisions.
- // Here we do not support a revision, so that entity key is omitted.
- 'entity keys' => array(
- 'id' => 'entity_id',
- 'bundle' => 'type',
- ),
- 'bundle keys' => array(
- 'bundle' => 'type',
- ),
- // Callback function for access to this entity.
- 'access callback' => 'chado_data_access',
- // FALSE disables caching. Caching functionality is handled by Drupal core.
- 'static cache' => FALSE,
- // Bundles are defined below.
- 'bundles' => array(),
- // 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
- // administrative menu.
- 'admin ui' => array(
- 'path' => 'admin/content/chado_data',
- 'file' => 'includes/tripal_entities.admin.inc',
- 'controller class' => 'ChadoDataUIController',
- 'menu wildcard' => '%chado_data',
- ),
- );
- // 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',
- ),
- );
- // The entity that holds information about the entity types
- $entities['chado_data_type'] = array(
- 'label' => t('Chado Data Type'),
- 'entity class' => 'ChadoDataType',
- 'controller class' => 'ChadoDataTypeController',
- 'base table' => 'chado_data_type',
- 'fieldable' => FALSE,
- 'bundle of' => 'chado_data',
- 'exportable' => TRUE,
- 'entity keys' => array(
- 'id' => 'id',
- 'name' => 'type',
- 'label' => 'label',
- ),
- 'access callback' => 'chado_data_type_access',
- 'module' => 'tripal_entities',
- // 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',
- ),
- );
- return $entities;
- }
- /**
- * Returns a render array with all chado_data entities.
- *
- * @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;
- }
|