123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056 |
- <?php
- /**
- * @file
- * The Tripal Core module
- */
- // Import the full Tripal API into scope.
- tripal_import_api();
- require_once "includes/TripalVocab.inc";
- require_once "includes/TripalVocabController.inc";
- require_once "includes/TripalVocabViewsController.inc";
- require_once "includes/TripalTerm.inc";
- require_once "includes/TripalTermController.inc";
- require_once "includes/TripalTermViewsController.inc";
- require_once "includes/TripalEntity.inc";
- require_once "includes/TripalEntityController.inc";
- require_once "includes/TripalEntityUIController.inc";
- require_once "includes/TripalEntityViewsController.inc";
- require_once "includes/TripalBundle.inc";
- require_once "includes/TripalBundleController.inc";
- require_once "includes/TripalBundleUIController.inc";
- /**
- * @defgroup tripal Tripal Core Module
- * @ingroup tripal_modules
- * @{
- * Functionality useful for all other Tripal modules including the Tripal jobs, files,
- * materialized views and custom table functions.
- * @}
- */
- /**
- * Implements hook_views_api().
- */
- function tripal_views_api() {
- return array(
- 'api' => 3,
- );
- }
- /**
- * Implements hook_init().
- * Used to set the search_path, create default content and set default variables.
- *
- * @ingroup tripal
- */
- function tripal_init() {
- global $base_url;
- // add some variables for all javasript to use for building URLs
- $clean_urls = variable_get('clean_url', 0);
- drupal_add_js(
- "var baseurl = '$base_url';" .
- "var isClean = $clean_urls;",
- 'inline', 'header');
- // make sure the date time settings are the way Tripal will insert them
- // otherwise PostgreSQL version that may have a different datestyle setting
- // will fail when inserting or updating a date column in a table.
- db_query("SET DATESTYLE TO :style", array(':style' => 'MDY'));
- }
- /**
- * Implements hook_menu().
- * Defines all menu items needed by Tripal Core
- *
- * @ingroup tripal
- */
- function tripal_menu() {
- $items = array();
- // Tripal setting groups
- $items['admin/tripal'] = array(
- 'title' => 'Tripal',
- 'description' => t("Manage the behavior or Tripal and its various modules."),
- 'weight' => -8,
- 'page callback' => 'system_admin_menu_block_page',
- 'access arguments' => array('administer tripal'),
- 'file' => 'system.admin.inc',
- 'file path' => drupal_get_path('module', 'system'),
- );
- $items['admin/tripal/tripal_jobs'] = array(
- 'title' => 'Jobs',
- 'description' => t('Provides tools for managing jobs submitted to Tripal. In some
- cases, long-running tasks are too slow to complete within a single
- browser session. The Tripal jobs system allows long-running tasks
- to be submitted to a queue that can be executed manually by the
- site admin or automatically using a module such as the ') .
- l('Tripal Daemon', 'https://www.drupal.org/project/tripal_daemon', array('attributes' => array('target' => '_blank'))) .
- ' extension module.',
- 'page callback' => 'tripal_jobs_admin_view',
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_NORMAL_ITEM,
- 'weight' => 0,
- 'file' => 'includes/tripal.jobs.inc',
- 'file path' => drupal_get_path('module', 'tripal'),
- );
- $items['admin/tripal/storage'] = array(
- 'title' => 'Storage Backend',
- 'description' => t("Tripal is designed to access biological
- data in any data storage back-end. A storage back-end must have a
- module that can be installed that interfaces with Tripal. By default
- the base Tripal package provides The Tripal Chado module for storing
- data in the GMOD Chado database schema. All available storage backends
- and their administrative tools are found here."),
- 'weight' => 8,
- 'access arguments' => array('administer tripal'),
- );
- $items['admin/tripal/terms'] = array(
- 'title' => 'Vocabularies',
- 'description' => t("Vocabulary terms are essential to creating content
- in Tripal. This allows data to be shared more easily with others
- using technologies such as the semantic web and web services.
- Before creating content you must have loaded vocabularies and their
- terms."),
- 'weight' => 8,
- 'access arguments' => array('administer tripal'),
- );
- $items['admin/tripal/terms/import'] = array(
- 'title' => 'Import Vocabulary',
- 'description' => t("Import vocabularies and terms in OBO format."),
- 'access arguments' => array('administer tripal'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_vocabulary_import_form'),
- 'file' => 'includes/tripal.admin.inc',
- 'file path' => drupal_get_path('module', 'tripal'),
- 'type' => MENU_NORMAL_ITEM,
- );
- // Menu items for facilitating import of extension modules.
- $items['admin/tripal/extension'] = array(
- 'title' => 'Extensions',
- 'description' => t('Look for extensions to add new functionality to this
- site. Tripal can be extended with new functionality developed
- by other Tripal site developers. These include modules with new or
- different functionality, bulk loading templates, or materialized
- views. Anyone can create new extensions and share those for
- others to use. Once shared they will appear in this list.'),
- 'access arguments' => array('administer tripal'),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_extensions_form'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'includes/tripal.extensions.inc',
- 'file path' => drupal_get_path('module', 'tripal'),
- 'weight' => 100
- );
- $items['admin/tripal/extension/import'] = array(
- 'title' => 'Import Extensions',
- 'description' => 'Provides a list of the available extensions that are registered at the tripal.info site. From this page you can easily import or install extensions to your site.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_extensions_form'),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'includes/tripal.extensions.inc',
- 'file path' => drupal_get_path('module', 'tripal'),
- 'weight' => -100,
- );
- /*
- $items['admin/tripal/setup/customize'] = array(
- 'title' => 'Customize Tripal',
- 'description' => t('Information on how to customize tripal'),
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_customize'),
- 'access arguments' => array('administer tripal'),
- 'weight' => 10
- );
- */
- // Jobs Management
- $items['admin/tripal/tripal_jobs/help'] = array(
- 'title' => 'Help',
- 'description' => t('Help for the tripal job management system'),
- 'page callback' => 'theme',
- 'page arguments' => array('tripal_job_help'),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 10
- );
- $items['admin/tripal/tripal_jobs/cancel/%'] = array(
- 'title' => 'Jobs',
- 'description' => t('Cancel a pending job'),
- 'page callback' => 'tripal_cancel_job',
- 'page arguments' => array(4),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/tripal_jobs/rerun/%'] = array(
- 'title' => 'Jobs',
- 'description' => t('Re-run an existing job.'),
- 'page callback' => 'tripal_rerun_job',
- 'page arguments' => array(4),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/tripal_jobs/view/%'] = array(
- 'title' => 'Jobs Details',
- 'description' => t('View job details.'),
- 'page callback' => 'tripal_jobs_view',
- 'page arguments' => array(4),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/tripal/tripal_jobs/views/jobs/enable'] = array(
- 'title' => 'Enable Jobs Administrative View',
- 'page callback' => 'tripal_enable_view',
- 'page arguments' => array('tripal_admin_jobs', 'admin/tripal/tripal_jobs'),
- 'access arguments' => array('administer tripal'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- /**
- * Implements hook_permission().
- */
- function tripal_permission() {
- return array(
- 'administer tripal' => array(
- 'title' => t('Administer Tripal'),
- 'description' => t('Allow the user to access administrative pages of Tripal.')
- ),
- 'view dev helps' => array(
- 'title' => t('View Developer Hints'),
- 'description' => t('Tripal will provide blue shaded boxes that provide
- instructions for how to customize or setup specific pages on a
- site. This permission should be enabled for developers. But can
- be disabled once developers are accustomed to these hints.'),
- 'restrict access' => TRUE,
- ),
- 'administer tripal data types' => array(
- 'title' => t('Administer Tripal data types'),
- 'description' => t('Create and delete fields for Tripal data types, and set their permissions.'),
- ),
- 'administer tripal data' => array(
- 'title' => t('Administer Tripal data'),
- 'description' => t('Edit and delete all tripal data'),
- ),
- 'administer controlled vocabularies' => array(
- 'title' => t('Administer controlled vocabularies (CVs).'),
- 'description' => t('Allow a user to add, edit and delete controlled vocabularies as well as add and edit terms.')
- ),
- );
- }
- /**
- * Checks access permissions for a given entity.
- */
- function tripal_entity_access($entity) {
- // TODO: need to implement this function.
- return TRUE;
- }
- /**
- * Implements hook_theme().
- * Registers template files/functions used by this module.
- *
- * @ingroup tripal
- */
- function tripal_theme($existing, $type, $theme, $path) {
- return array(
- 'tripal_customize' => array(
- 'arguments' => array('job_id' => NULL),
- 'template' => 'tripal_customize',
- 'path' => "$path/theme/templates"
- ),
- 'theme_file_upload_combo' => array(
- 'render element' => 'element',
- ),
- 'theme_sequence_combo' => array(
- 'render element' => 'element',
- ),
- 'tripal_jobs_help' => array(
- 'template' => 'tripal_jobs_help',
- 'variables' => array(NULL),
- 'path' => "$path/theme/templates"
- ),
- 'tripal_customtables_help' => array(
- 'template' => 'tripal_customtables_help',
- 'variables' => array(NULL),
- 'path' => "$path/theme/templates"
- ),
- // Admin messages theme
- 'tripal_admin_message' => array(
- 'function' => 'theme_tripal_admin_message',
- 'variables' => array('message' => NULL),
- ),
- 'tripal_entity' => array(
- 'render element' => 'elements',
- 'template' => 'tripal_entity',
- 'path' => "$path/theme/templates"
- ),
- 'tripal_add_list' => array(
- 'variables' => array('content' => NULL),
- ),
- );
- }
- /**
- * Implements hook_coder_ignore().
- * Defines the path to the file (tripal.coder_ignores.txt) where ignore rules for coder are stored
- */
- function tripal_coder_ignore() {
- return array(
- 'path' => drupal_get_path('module', 'tripal'),
- 'line prefix' => drupal_get_path('module', 'tripal'),
- );
- }
- /**
- * Implements hook_libraries_info().
- */
- function tripal_libraries_info() {
- $libraries = array();
- $libraries['d3'] = array(
- 'name' => 'D3.js',
- 'vendor url' => 'http://d3js.org/',
- 'download url' => 'https://github.com/mbostock/d3',
- 'version arguments' => array(
- 'file' => 'd3.js',
- 'pattern' => '/\s*version: "(\d+\.\d+\.\d+)"/',
- ),
- 'files' => array(
- 'js' => array(
- 'd3.min.js',
- ),
- ),
- );
- return $libraries;
- }
- /**
- * Implements hook_admin_paths().
- * Define administrative paths.
- */
- function tripal_admin_paths() {
- if (variable_get('node_admin_theme')) {
- $paths = array(
- 'bio-data/*/edit' => TRUE,
- 'bio-data/*/delete' => TRUE,
- 'bio-data/add' => TRUE,
- 'bio-data/add/*' => TRUE,
- );
- return $paths;
- }
- }
- /**
- * Implements hook_menu_local_tasks_alter().
- *
- * Used to add action links to pages.
- */
- function tripal_menu_local_tasks_alter(&$data, $router_item, $root_path) {
- // Add an "Add Tripal Content" action link to the Admin >> Content >>
- // Biological Content page.
- if ($root_path == 'admin/content/bio-data') {
- $item = menu_get_item('bio-data/add');
- if ($item['access']) {
- $data['actions']['output'][] = array(
- '#theme' => 'menu_local_action',
- '#link' => $item,
- );
- }
- }
- }
- /**
- * Implements hook_shortcut_default_set().
- * Modify the shortcut menu to include Biological content links.
- *
- * @param object $account
- * The user account whose default shortcut set will be returned. If not provided, the
- * function will return the currently logged-in user's default shortcut set.
- *
- * @return
- * An object representing the default shortcut set.
- */
- function tripal_shortcut_default_set($account) {
- $sets = shortcut_sets();
- $found = FALSE;
- foreach ($sets as $set) {
- if ($set->title == 'TripalDefault') {
- $found = TRUE;
- }
- }
- if (!$found) {
- $t = get_t();
- // Create an initial default shortcut set.
- $shortcut_set = new stdClass();
- $shortcut_set->title = $t('TripalDefault');
- $shortcut_set->links = array(
- array(
- 'link_path' => 'node/add',
- 'link_title' => $t('Add content'),
- 'weight' => -35,
- ),
- array(
- 'link_path' => 'bio-data/add',
- 'link_title' => 'Add Tripal Content',
- 'weight' => -30,
- ),
- array(
- 'link_path' => 'admin/content',
- 'link_title' => $t('Find content'),
- 'weight' => -25,
- ),
- array(
- 'link_path' => 'admin/content/bio-data',
- 'link_title' => 'Find Tripal Content',
- 'weight' => -20,
- ),
- );
- shortcut_set_save($shortcut_set);
- }
- $sets = shortcut_sets();
- foreach ($sets as $set) {
- if ($set->title == 'TripalDefault') {
- return $set->set_name;
- }
- }
- }
- // 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_entity_info() {
- $entities = array();
- //return $entities;
- //
- // The TripalVocab entity is meant to house vocabularies. It is these
- // vocabs that are used by the TripalTerm entities. The storage backend
- // is responsible for setting the values of this entity.
- //
- $entities['TripalVocab'] = array(
- // A human readable label to identify our entity.
- 'label' => 'Controlled Vocabulary',
- 'plural label' => 'Controlled Vocabularies',
- // The entity class and controller class extend the classes provided by the
- // Entity API.
- 'entity class' => 'TripalVocab',
- 'controller class' => 'TripalVocabController',
- // Adds Views integration for this entity.
- 'views controller class' => 'TripalVocabViewsController',
- // The table for this entity defined in hook_schema()
- 'base table' => 'tripal_vocab',
- // 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' => 'id',
- ),
- // Callback function for access to this entity.
- 'access callback' => 'tripal_entity_access',
- // FALSE disables caching. Caching functionality is handled by Drupal core.
- 'static cache' => FALSE,
- // This entity doesn't support bundles.
- 'bundles' => array (),
- 'view modes' => array (
- 'full' => array (
- 'label' => t ('Full content'),
- 'custom settings' => FALSE
- ),
- 'teaser' => array (
- 'label' => t ('Teaser'),
- 'custom settings' => TRUE
- ),
- ),
- );
- //
- // The TripalTerm entity is meant to house vocabulary terms. It is these
- // terms that are used by the TripalEntity entities. The storage backend
- // is responsible for setting the values of this entity.
- //
- $entities['TripalTerm'] = array(
- // A human readable label to identify our entity.
- 'label' => 'Controlled Vocabulary Term',
- 'plural label' => 'Controlled Vocabulary Terms',
- // The entity class and controller class extend the classes provided by the
- // Entity API.
- 'entity class' => 'TripalTerm',
- 'controller class' => 'TripalTermController',
- // Adds Views integration for this entity.
- 'views controller class' => 'TripalTermViewsController',
- // The table for this entity defined in hook_schema()
- 'base table' => 'tripal_term',
- // 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' => 'id',
- ),
- // Callback function for access to this entity.
- 'access callback' => 'tripal_entity_access',
- // FALSE disables caching. Caching functionality is handled by Drupal core.
- 'static cache' => FALSE,
- // This entity doesn't support bundles.
- 'bundles' => array (),
- 'view modes' => array (
- 'full' => array (
- 'label' => t ('Full content'),
- 'custom settings' => FALSE
- ),
- 'teaser' => array (
- 'label' => t ('Teaser'),
- 'custom settings' => TRUE
- ),
- ),
- );
- //
- // The TripalEntity is used for all data. It links data from a storage
- // back-end to a TripalTerm entity.
- //
- $entities['TripalEntity'] = array (
- // A human readable label to identify our entity.
- 'label' => 'Tripal Content',
- 'plural label' => 'Tripal Content',
- // The entity class and controller class extend the classes provided by the
- // Entity API.
- 'entity class' => 'TripalEntity',
- 'controller class' => 'TripalEntityController',
- // Adds Views integration for this entity.
- 'views controller class' => 'TripalEntityViewsController',
- // The table for this entity defined in hook_schema()
- 'base table' => 'tripal_entity',
- // Returns the uri elements of an entity.
- 'uri callback' => 'tripal_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' => 'id',
- 'bundle' => 'bundle'
- ),
- 'bundle keys' => array (
- 'bundle' => 'name'
- ),
- // Callback function for access to this entity.
- 'access callback' => 'tripal_entity_access',
- // FALSE disables caching. Caching functionality is handled by Drupal core.
- 'static cache' => FALSE,
- // Bundles are added dynamically below.
- 'bundles' => array (),
- 'label callback' => 'tripal_entity_label',
- // The information below is used by the TripalEntityUIController
- // (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/bio-data',
- 'controller class' => 'TripalEntityUIController',
- 'menu wildcard' => '%TripalEntity',
- 'file' => 'includes/TripalEntityUIController.inc'
- ),
- 'view modes' => array (
- 'full' => array (
- 'label' => t ('Full content'),
- 'custom settings' => FALSE
- ),
- 'teaser' => array (
- 'label' => t ('Teaser'),
- 'custom settings' => TRUE
- )
- )
- );
- //
- // The TripalBundle entity is used manage the bundle types. The 'bundle of'
- // attribute links this to the TripalEntity and allows the UI provided
- // by the entity module to work for each TripalEntity bundle.
- //
- $entities['TripalBundle'] = array (
- 'label' => 'Tripal Content Type',
- 'entity class' => 'TripalBundle',
- 'controller class' => 'TripalBundleController',
- 'base table' => 'tripal_bundle',
- 'fieldable' => FALSE,
- 'bundle of' => 'TripalEntity',
- 'exportable' => FALSE,
- 'entity keys' => array (
- 'id' => 'id',
- 'name' => 'name',
- 'label' => 'label'
- ),
- 'access callback' => 'tripal_bundle_access',
- 'module' => 'tripal',
- // Enable the entity API's admin UI.
- 'admin ui' => array (
- 'path' => 'admin/structure/bio-data',
- 'controller class' => 'TripalBundleUIController',
- 'file' => 'includes/TripalBundleUIController.inc',
- 'menu wildcard' => '%TripalBundle',
- )
- );
- return $entities;
- }
- /**
- * Implements hook_entities_info_alter().
- *
- * Add in the bundles (entity types) to the TripalEntity entity.
- */
- function tripal_entity_info_alter(&$entity_info){
- if (array_key_exists('TripalEntity', $entity_info)) {
- // Dynamically add in the bundles. Bundles are alternative groups of fields
- // or configuration associated with an entity type .We want to dynamically
- // add the bundles to the entity.
- $bundles = db_select('tripal_bundle', 'tb')
- ->fields('tb')
- ->execute();
- while ($bundle = $bundles->fetchObject()) {
- $bundle_name = $bundle->name;
- $term_id = $bundle->term_id;
- $term = entity_load('TripalTerm', array('id' => $term_id));
- $term = reset($term);
- $label = preg_replace('/_/', ' ', ucwords($term->name));
- $entity_info['TripalEntity']['bundles'][$bundle_name] = array (
- 'label' => $label,
- 'admin' => array (
- 'path' => 'admin/structure/bio-data/manage/%TripalBundle',
- 'real path' => 'admin/structure/bio-data/manage/' . $bundle_name,
- 'bundle argument' => 4,
- 'access arguments' => array (
- 'administer tripal data types'
- )
- )
- );
- }
- }
- }
- /**
- * Menu argument loader; Load a tripal data type by string.
- *
- * This function is not meant to be used as an API function. It is only meant
- * for use in the menu to resolve the %tripal_bundle wildcard.
- *
- * @param $type
- * The machine-readable name of a tripal data type to load.
- * @return
- * A tripal data type array or FALSE if $type does not exist.
- */
- function TripalBundle_load($bundle_type, $reset = FALSE) {
- // Get the type of entity by the ID.
- $bundle = db_select('tripal_bundle', 'tdt')
- ->fields('tdt')
- ->condition('name', $bundle_type)
- ->execute()
- ->fetchObject();
- if ($bundle) {
- $entity = entity_load('TripalBundle', array($bundle->id), array(), $reset);
- return reset($entity);
- }
- return FALSE;
- }
- /**
- * Allows the menu system to use a wildcard to fetch the entity.
- *
- * Make sure that the wildcard you choose in the tripal_entity entity
- * definition fits the function name here.
- *
- * This function is not meant to be used as an API function. It is only meant
- * for use in the menu to resolve the %tripal_entity wildcard.
- *
- * @param $id
- * Integer specifying the tripal_entity id.
- * @param $reset
- * A boolean indicating that the internal cache should be reset.
- * @return
- * A fully-loaded $tripal_entity object or FALSE if it cannot be loaded.
- *
- * @see tripal_entity_load_multiple()
- */
- function TripalEntity_load($id, $reset = FALSE) {
- $entity = entity_load('TripalEntity', array($id), array(), $reset);
- return reset($entity);
- }
- /**
- *
- * Implements hook_form_FORM_ID_alter().
- *
- * The field_ui_field_edit_form is used for customizing the settings of
- * a field attached to an entity.
- *
- * This alter function disables some of the form widgets when the storage
- * backend indicates they are not appropriate.
- */
- function tripal_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
- // For entity fields added by Tripal Entities we don't want the
- // the end-user to change the cardinality and the required fields
- // such that record can't be saved in Chado.
- // TODO: this shouldn't be hardcoded here. These settings
- // should be part of the field and handled by the tripal_entity module.
- if ($form['#instance']['entity_type'] == 'TripalEntity') {
- $form['field']['cardinality']['#access'] = FALSE;
- $form['instance']['required']['#access'] = FALSE;
- }
- // TODO: don't the the maximum length be larger than the field size.
- }
- /**
- *
- * Implements hook_form_FORM_ID_alter().
- *
- * The field_ui_field_overview_form_ is used for adding and reordering the
- * fields attached to a bundle. It also includes edit and delete links and
- * links for editing field types and widgets.
- *
- * This alter function is used to add a new 'Supported By' column to
- * the table to let the user know where fields are storing their data.
- */
- function tripal_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
- // Add the 'Storage Location' to the table header.
- $form['fields']['#header'][] = 'Supported By * ';
- // Add the storage location as the final column for each field.
- $storage_info = module_invoke_all('field_storage_info');
- foreach (element_children($form['fields']) as $field_name) {
- $field = field_info_field($field_name);
- // For rows in the tables that aren't fields, just add an empty value
- // for the storage column.
- if (!$field) {
- $form['fields'][$field_name][] = array(
- '#markup' => '',
- );
- continue;
- }
- $storage_type = $field['storage']['type'];
- $storage_label = array_key_exists('label', $storage_info[$storage_type]) ? $storage_info[$storage_type]['label'] : '';
- if ($storage_type == 'field_sql_storage') {
- $storage_label = 'Drupal';
- }
- if (array_key_exists('logo_url', $storage_info[$storage_type])) {
- $logo_url = $storage_info[$storage_type]['logo_url'];
- $form['fields'][$field_name][] = array(
- '#markup' => '<img class="form-field-ui-field-overview-storage-logo" src="' . $logo_url . '">',
- );
- }
- else {
- $form['fields'][$field_name][] = array(
- '#markup' => $storage_label,
- );
- }
- }
- $form['note'] = array(
- '#markup' => '* Fields attached to this content type can use various
- storage backends. Please be sure when you add new fields that the
- storage backend is appropriate. For example, if you use Chado, and you
- want all biological content to be stored in Chado, be sure that the
- respective fields are "supported by" Chado.',
- );
- }
- /**
- * Implements hook_menu_alter().
- */
- function tripal_menu_alter(&$items) {
- // We don't want to allow deletion of fields added by the storage backend.
- // TODO: this shouldn't be hardcoded here. These settings
- // should be part of the field and handled by the tripal_entity module.
- $items['admin/structure/bio-data/manage/%TripalBundle/fields/%field_ui_menu/delete']['page callback'] = 'tripal_field_no_delete';
- $items['admin/structure/bio-data/manage/%TripalBundle/fields/%field_ui_menu/delete']['page arguments'] = array();
- }
- /**
- * Simple provides a message indicating that the field cannot be deleted.
- */
- function tripal_field_no_delete() {
- drupal_set_message('This field cannot be removed.', 'warning');
- return '';
- }
- /**
- * Imports all of the Tripal API into scope.
- *
- * Typically this function call is not necessary as all of the API is
- * automaticaly included by the tripal module. However this function can
- * be useful in the .install files during a site upgrade when the tripal
- * module is not enabld.
- *
- * Example usage:
- * @code
- * module_load_include('module', 'tripal', 'tripal');
- * tripal_import_api();
- * @endcode
- *
- */
- function tripal_import_api() {
- module_load_include('inc', 'tripal', 'api/tripal.d3js.api');
- module_load_include('inc', 'tripal', 'api/tripal.entities.api');
- module_load_include('inc', 'tripal', 'api/tripal.files.api');
- module_load_include('inc', 'tripal', 'api/tripal.jobs.api');
- module_load_include('inc', 'tripal', 'api/tripal.notice.api');
- module_load_include('inc', 'tripal', 'api/tripal.variables.api');
- }
- /**
- * Implements hook_field_storage_info().
- *
- * The Tripal module does not provide a storage back-end. But it does provide
- * a placeholder when no storage backend is needed but a field
- * is still desired. The 'tripal_no_storage' backend is used for the
- * content_type field which adds a type field to every entity.
- */
- function tripal_field_storage_info() {
- return array(
- 'tripal_no_storage' => array(
- 'label' => t('Tripal'),
- 'description' => t('The NULL storage is a placeholder for field values
- that are not stored in any storage backend (e.g. entity types).'),
- 'settings' => array(),
- ),
- );
- }
- /**
- * Implements hook_field_info().
- */
- function tripal_field_info() {
- $fields = array(
- 'content_type' => array(
- 'label' => t('Record Type'),
- 'description' => t('The content type.'),
- 'default_widget' => 'tripal_content_type_widget',
- 'default_formatter' => 'tripal_content_type_formatter',
- 'settings' => array(),
- 'storage' => array(
- 'type' => 'tripal_no_storage',
- 'module' => 'tripal',
- 'active' => TRUE
- ),
- ),
- );
- return $fields;
- }
- /**
- * Implements hook_field_widget_info();
- */
- function tripal_field_widget_info() {
- return array(
- 'tripal_content_type_widget' => array(
- 'label' => t('Record Type'),
- 'field types' => array('content_type')
- ),
- );
- }
- /**
- * Implements hook_field_formatter_info().
- */
- function tripal_field_formatter_info() {
- return array(
- 'tripal_content_type_formatter' => array(
- 'label' => t('Record Type'),
- 'field types' => array('content_type')
- ),
- );
- }
- /**
- * Implements hook_field_widget_form().
- */
- function tripal_field_widget_form(&$form, &$form_state, $field,
- $instance, $langcode, $items, $delta, $element) {
- $widget = $element;
- switch ($instance['widget']['type']) {
- case 'tripal_content_type_widget':
- // There is no widget for this type.
- break;
- }
- }
- /**
- * Implements hook_field_formatter_view().
- */
- function tripal_field_formatter_view($entity_type, $entity, $field,
- $instance, $langcode, $items, $display) {
- $element = array();
- switch ($display['type']) {
- case 'tripal_content_type_formatter':
- module_load_include('inc', 'tripal', 'includes/fields/content_type');
- tripal_content_type_formatter($element, $entity_type, $entity, $field,
- $instance, $langcode, $items, $display);
- break;
- }
- return $element;
- }
- /**
- * Implemenation of hook_add_bundle_fields().
- *
- * In this function we add the type field.
- */
- function tripal_add_bundle_fields($entity_type, $bundle, $term) {
- $field_name = 'content_type';
- $bundle_name = $bundle->name;
- // Create the field array.
- $field_info = array(
- 'field_type' => 'content_type',
- 'widget_type' => 'tripal_content_type_widget',
- 'widget_settings' => array('display_label' => 1),
- 'description' => '',
- 'label' => 'Record Type',
- 'is_required' => 0,
- 'storage' => 'tripal_no_storage',
- 'field_settings' => array(
- 'semantic_web' => array(
- // The type is the term from a vocabulary that desribes this field..
- 'type' => '',
- // The namepsace for the vocabulary (e.g. 'foaf').
- 'ns' => '',
- // The URL for the namespace. It must be that the type can be
- // appended to the URL.
- 'nsurl' => '',
- ),
- ),
- );
- tripal_add_bundle_field($field_name, $field_info, $entity_type, $bundle_name);
- }
- /**
- * Implements hook_field_storage_query().
- *
- * Used by EntityFieldQuery to find the entities having certain entity
- * and field conditions and sort them in the given field order.
- *
- * NOTE: This function needs to exist or errors are triggered but so far it doesn't
- * appear to actually need to do anything...
- */
- function tripal_field_storage_query($query) { }
- /**
- * Implements hook_field_storage_load().
- *
- * Responsible for loading the fields from the Chado database and adding
- * their values to the entity.
- */
- function tripal_field_storage_load($entity_type, $entities, $age,
- $fields, $options) {
- $load_current = $age == FIELD_LOAD_CURRENT;
- global $language;
- $langcode = $language->language;
- foreach ($entities as $id => $entity) {
- // Iterate through the entity's fields so we can get the column names
- // that need to be selected from each of the tables represented.
- $tables = array();
- foreach ($fields as $field_id => $ids) {
- // By the time this hook runs, the relevant field definitions have been
- // populated and cached in FieldInfo, so calling field_info_field_by_id()
- // on each field individually is more efficient than loading all fields in
- // memory upfront with field_info_field_by_ids().
- $field = field_info_field_by_id($field_id);
- $field_name = $field['field_name'];
- $field_type = $field['type'];
- $field_module = $field['module'];
- // Allow the creating module to alter the value if desired. The
- // module should do this if the field has any other form elements
- // that need populationg besides the default value.
- $load_function = $field_module . '_' . $field_type . '_field_load';
- module_load_include('inc', $field_module, 'includes/fields/' . $field_type);
- if (function_exists($load_function)) {
- $load_function($field, $entity);
- }
- } // end: foreach ($fields as $field_id => $ids) {
- } // end: foreach ($entities as $id => $entity) {
- }
- /**
- * Implements hook_field_is_empty().
- */
- function tripal_field_is_empty($item, $field) {
- // If there is no value field then the field is empty.
- if (!array_key_exists('value', $item)) {
- return TRUE;
- }
- // Iterate through all of the fields and if at least one has a value
- // the field is not empty.
- foreach ($item as $form_field_name => $value) {
- if (isset($value) and $value != NULL and $value != '') {
- return FALSE;
- }
- }
- // Otherwise, the field is empty.
- return TRUE;
- }
|