3,
);
}
/**
* Implements hook_init().
*
* @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);
$tripal_path = url(drupal_get_path('module', 'tripal'));
drupal_add_js("
var baseurl = '$base_url';
var isClean = $clean_urls;
var tripal_path = '$tripal_path';",
'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'));
}
function tripal_menu_alter(&$items) {
//drupal_debug($items);
}
/**
* 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/storage'] = array(
'title' => 'Data Storage',
'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/extension'] = array(
'title' => 'Extensions',
'description' => t("Configuration and management pages for Tripal extension modules."),
'weight' => 8,
'access arguments' => array('administer tripal'),
);
// Menu items for facilitating import of extension modules.
$items['admin/tripal/extension/available'] = array(
'title' => 'Available 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,
// );
// Jobs Management
$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',
);
$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,
'file' => 'api/tripal.jobs.api.inc',
);
$items['admin/tripal/tripal_jobs/status/%'] = array(
'page callback' => 'tripal_jobs_status_view',
'page arguments' => array(4),
'access arguments' => array('administer tripal'),
'type' => MENU_CALLBACK,
'file' => 'includes/tripal.jobs.inc',
);
$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,
'file' => 'includes/tripal.jobs.inc',
);
$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,
'file' => 'includes/tripal.jobs.inc',
);
$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,
'file' => 'includes/tripal.jobs.inc',
);
$items['admin/tripal/tripal_jobs/execute/%'] = array(
'title' => 'Jobs',
'description' => t('Execute an existing job'),
'page callback' => 'tripal_execute_job',
'page arguments' => array(4),
'access arguments' => array('administer tripal'),
'type' => MENU_CALLBACK,
);
/*
* AJAX Callbacks.
*/
$items['bio_data/ajax/field_attach/%'] = array(
'page callback' => 'tripal_ajax_attach_field',
'page arguments' => array(3),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'includes/tripal.entity.inc',
'file path' => drupal_get_path('module', 'tripal'),
);
/*
* Dashboard Action Item callbacks.
*/
$items['admin/disable/notification/%'] = array(
'page callback' => 'tripal_disable_admin_notification',
'page arguments' => array(3),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'includes/tripal.admin_blocks.inc',
'file path' => drupal_get_path('module', 'tripal'),
);
$items['admin/import/field/%/%/%/%'] = array(
'page callback' => 'tripal_admin_notification_import_field',
'page arguments' => array(3, 4, 5, 6),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'includes/tripal.admin_blocks.inc',
'file path' => drupal_get_path('module', 'tripal'),
);
/*
* Term Lookup
*/
// TODO: finish this menu callback.
// $items['cv/lookup'] = array(
// 'title' => 'Vocabulary Lookup',
// 'description' => t("Provides a tool to discover controlled vocabularies and their terms used by this site."),
// 'access arguments' => array('access content'),
// 'page callback' => 'drupal_get_form',
// 'page arguments' => array('tripal_vocabulary_lookup_form'),
// 'file' => 'includes/tripal.term_lookup.inc',
// 'file path' => drupal_get_path('module', 'tripal'),
// 'type' => MENU_NORMAL_ITEM,
// );
$items['cv/lookup/%'] = array(
'title' => 'Vocabulary Lookup',
'description' => t("Provides a tool to discover controlled vocabularies"),
'access arguments' => array('access content'),
'page callback' => 'tripal_vocabulary_lookup_page',
'page arguments' => array(2),
'file' => 'includes/tripal.term_lookup.inc',
'file path' => drupal_get_path('module', 'tripal'),
'type' => MENU_CALLBACK,
);
$items['cv/lookup/%/%'] = array(
'title' => 'Vocabulary Term Lookup',
'description' => t("Provides a tool to discover controlled vocabularies terms used by this site."),
'access arguments' => array('access content'),
'page callback' => 'tripal_vocabulary_lookup_term_page',
'page arguments' => array(2, 3),
'file' => 'includes/tripal.term_lookup.inc',
'file path' => drupal_get_path('module', 'tripal'),
'type' => MENU_CALLBACK,
);
// Adds a +Check for new fields link on the 'Tripal Content Types' page.
$items['admin/structure/bio_data/manage/%/fields/check'] = array(
'title' => 'Check for new fields',
'description' => t('Check if new fields should be added to this content type.'),
'page callback' => 'tripal_check_new_fields',
'page arguments' => array(4),
'access arguments' => array('administer tripal'),
'file' => 'api/tripal.entities.api.inc',
'file path' => drupal_get_path('module', 'tripal'),
'type' => MENU_LOCAL_ACTION,
);
$items['tripal/upload'] = array(
'page callback' => 'tripal_file_upload',
'access arguments' => array('upload files'),
'file' => '/includes/tripal.upload.inc',
'type' => MENU_CALLBACK,
);
// Add in the loaders
$importers = tripal_get_importers();
foreach ($importers as $class_name) {
tripal_load_include_importer_class($class_name);
if (class_exists($class_name)) {
$items['admin/tripal/loaders/' . $class_name::$machine_name] = array(
'title' => $class_name::$name,
'description' => $class_name::$description,
'page callback' => 'drupal_get_form',
'page arguments' => array('tripal_get_importer_form', $class_name),
'access arguments' => array('administer tripal'),
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/tripal.importer.inc',
'file path' => drupal_get_path('module', 'tripal'),
);
}
}
return $items;
}
/**
* Implements hook_permission().
*/
function tripal_permission() {
$permissions = array(
'administer tripal' => array(
'title' => t('Administer Tripal'),
'description' => t('Allow the user to access administrative pages of Tripal. This includes management of jobs, the storage systems, extensions and the controlled vocabularies.'),
'restrict access' => TRUE,
),
'access tripal content overview' => array(
'title' => t('Access the Tripal content overview page'),
'description' => t('Get an overview of all Tripal content'),
'restrict access' => TRUE,
),
'manage tripal content types' => array(
'title' => t('Manage Tripal content types'),
'description' => t('Allows the user to create, update and delete Tripal content types.'),
'restrict access' => TRUE,
),
'upload files' => array(
'title' => t('Upload Files'),
'description' => t('Allows the user to upload files using Tripal\'s HTML5 loader.'),
),
'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,
),
);
// Add permissions for each content type.
$bundles = tripal_get_content_types();
foreach ($bundles as $bundle) {
$permissions['view ' . $bundle->name] = array(
'title' => t('%label: View Content', array('%label' => $bundle->label)),
'description' => t('Allow the user to view %label content', array('%label' => $bundle->label)),
);
$permissions['create ' . $bundle->name] = array(
'title' => t('%label: Create Content', array('%label' => $bundle->label)),
'description' => t('Allow the user to create %label content', array('%label' => $bundle->label)),
'restrict access' => TRUE,
);
$permissions['edit ' . $bundle->name] = array(
'title' => t('%label: Edit Content', array('%label' => $bundle->label)),
'description' => t('Allow the user to edit %label content', array('%label' => $bundle->label)),
'restrict access' => TRUE,
);
$permissions['delete ' . $bundle->name] = array(
'title' => t('%label: Delete Content', array('%label' => $bundle->label)),
'description' => t('Allow the user to delete %label content', array('%label' => $bundle->label)),
'restrict access' => TRUE,
);
}
return $permissions;
}
/**
* Implements hook_theme().
* Registers template files/functions used by this module.
*
* @ingroup tripal
*/
function tripal_theme($existing, $type, $theme, $path) {
$themes = array(
// 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),
),
// Themeing for all fields.
'tripal_field_default' => array(
'render element' => 'element',
'file' => 'includes/tripal.fields.inc',
),
);
return $themes;
}
/**
* 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;
}
}
}
/**
* 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);
$entity = tripal_load_entity('TripalEntity', array($id), $reset);
return reset($entity);
}
/**
* 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.fields.api');
module_load_include('inc', 'tripal', 'api/tripal.importer.api');
module_load_include('inc', 'tripal', 'api/tripal.terms.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');
module_load_include('inc', 'tripal', 'api/tripal.DEPRECATED.api');
}
/**
* Implements hook_form_alter().
*/
function tripal_form_alter(&$form, $form_state, $form_id) {
// If this is the field_ui_field_edit_form (i.e. the form that appears
// when editing a field that is attached to an entity). Then we want
// to add term settings for any field attached to a TripalEntity
// content type.
if ($form_id == 'field_ui_field_edit_form' and $form['#instance']['entity_type'] == 'TripalEntity') {
tripal_field_instance_settings_form_alter($form, $form_state);
}
}
function tripal_check_new_fields($bundle_name) {
$bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
$term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
$added = tripal_create_bundle_fields($bundle, $term);
if (count($added) == 0) {
drupal_set_message('No new fields were added');
}
foreach ($added as $field_name) {
drupal_set_message('Added field: ' . $field_name);
}
drupal_goto("admin/structure/bio_data/manage/$bundle_name/fields");
}
/**
* Implements hook_block_info().
*/
function tripal_block_info() {
$blocks = array();
$admin_theme = 'seven';
$blocks['notifications_block'] = array(
'info' => t('Dashboard Notifications'),
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => 'admin/dashboard',
'status' => TRUE,
'theme' => $admin_theme,
'region' => 'dashboard_main',
'properties' => array(
'administrative' => TRUE,
),
);
$blocks['content_type_barchart'] = array(
'info' => t('Published Tripal Content'),
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => 'admin/dashboard',
'status' => TRUE,
'theme' => $admin_theme,
'region' => 'dashboard_main',
'properties' => array(
'administrative' => TRUE,
),
);
$blocks['powered_by_tripal'] = array(
'info' => t('Powered by Tripal'),
'cache' => DRUPAL_NO_CACHE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function tripal_block_view($delta = ''){
global $base_path;
$block = array();
// The $delta parameter tells us which block is being requested.
switch ($delta) {
case 'powered_by_tripal':
$size = variable_get('powered_by_tripal_size', 'small');
$type = variable_get('powered_by_tripal_type', 'bw');
$image = 'powered_by_tripal_bw_small.png';
if ($size == 'small' and $type == 'col') {
$image = 'powered_by_tripal_small.png';
}
if ($size == 'large' and $type == 'bw') {
$image = 'powered_by_tripal_bw.png';
}
if ($size == 'large' and $type == 'col') {
$image = 'powered_by_tripal.png';
}
$block['title'] = '';
$block['content'] = array(
'#markup' => '',
);
break;
case 'content_type_barchart':
// The number of content types
$entity_types = db_select('tripal_bundle', 'tb')
->fields('tb')
->execute()
->fetchAll();
$entity_count_listing = array();
// The number of entities per content type.
foreach($entity_types as $entity_types => $entity_type){
$result = db_select('chado_' . $entity_type->name, 'et')
->fields('et')
->execute();
$number_of_entities = $result->rowCount();
$entity_count_listing[$entity_types] = array(
'name' => $entity_type->label,
'count' => $number_of_entities,
);
}
tripal_add_d3js();
drupal_add_js(drupal_get_path ('module', 'tripal') . '/theme/js/tripal.dashboard.js');
drupal_add_css(drupal_get_path ('module', 'tripal') . '/theme/css/tripal.dashboard.css');
drupal_add_library('system', 'drupal.collapse');
drupal_add_js("var entityCountListing = " . json_encode($entity_count_listing) . ";", array('type' => 'inline'));
$output = "
A list of the published Tripal content types and the number of each.