|
@@ -41,7 +41,7 @@ function tripal_entities_content_overview_form($form, &$form_state) {
|
|
|
// This will return the 25 most recently created entities.
|
|
|
$entities = db_select('tripal_entity', 'td')
|
|
|
->fields('td')
|
|
|
- ->orderBy('created', 'DESC')//ORDER BY created
|
|
|
+ ->orderBy('created', 'DESC')
|
|
|
->range(0,25)
|
|
|
->execute();
|
|
|
|
|
@@ -103,160 +103,72 @@ function tripal_entities_content_overview_form($form, &$form_state) {
|
|
|
* Form for creating tripal data types.
|
|
|
*
|
|
|
* This form is available on the menu at Admin >> Structure >> Biological Data
|
|
|
- * Types
|
|
|
+ * Types. It requires that a module implmennt the vocabulary storage. Tripal
|
|
|
+ * knows which vocabulary storage methods are available when a module
|
|
|
+ * implements the hook_vocab_storage_info() hook.
|
|
|
*
|
|
|
- * @param array $form
|
|
|
- * @param array $form_state
|
|
|
- *
|
|
|
- * @return
|
|
|
- * An array describing this form to the Form API.
|
|
|
*/
|
|
|
function tripal_entities_admin_add_type_form($form, &$form_state) {
|
|
|
- $term_name = '';
|
|
|
- $num_terms = 0;
|
|
|
- $cv_id = '';
|
|
|
|
|
|
- // Set defaults using the form state.
|
|
|
- if (array_key_exists('input', $form_state)) {
|
|
|
- if (array_key_exists('term_name', $form_state['input'])) {
|
|
|
- $term_name = $form_state['input']['term_name'];
|
|
|
- }
|
|
|
- if (array_key_exists('cv_id', $form_state['input'])) {
|
|
|
- $cv_id = $form_state['input']['cv_id'];
|
|
|
- }
|
|
|
-
|
|
|
- // If a term and cv_id are provided then we can look for the term using
|
|
|
- // both and we should find a unique term. If only ther term is provided
|
|
|
- // we can still look for a unique term but there must only be one.
|
|
|
- if ($term_name and !$cv_id) {
|
|
|
- $match = array(
|
|
|
- 'name' => $term_name,
|
|
|
- );
|
|
|
- }
|
|
|
- else {
|
|
|
- $match = array(
|
|
|
- 'name' => $term_name,
|
|
|
- 'cv_id' => $cv_id,
|
|
|
- );
|
|
|
+ // TODO: we need some sort of administrative interface that lets the user
|
|
|
+ // switch to the desired vocabulary type. For now, we'll just use the
|
|
|
+ // first one in the list.
|
|
|
+ $stores = module_invoke_all('vocab_storage_info');
|
|
|
+ if (is_array($stores) and count($stores) > 0) {
|
|
|
+ $keys = array_keys($stores);
|
|
|
+ $module = $stores[$keys[0]]['module'];
|
|
|
+ $function = $module . '_vocab_select_term_form';
|
|
|
+ if (function_exists($function)) {
|
|
|
+ $form = $function($form, $form_state);
|
|
|
}
|
|
|
-
|
|
|
- $terms = tripal_get_cvterm($match, array('return_array' => TRUE));
|
|
|
- $num_terms = count($terms);
|
|
|
- }
|
|
|
-
|
|
|
- // If no term has been selected yet then provide the auto complete field.
|
|
|
- if ($num_terms == 0) {
|
|
|
- $form['term_name'] = array(
|
|
|
- '#title' => t('Content Type'),
|
|
|
- '#type' => 'textfield',
|
|
|
- '#description' => t("The content type must be the name of a term in
|
|
|
- a controlled vocabulary and the controlled vocabulary should
|
|
|
- already be loaded into Tripal. For example, to create a content
|
|
|
- type for storing 'genes', use the 'gene' term from the
|
|
|
- Sequence Ontology (SO)."),
|
|
|
- '#required' => TRUE,
|
|
|
- '#default_value' => $term_name,
|
|
|
- '#autocomplete_path' => "admin/tripal/vocab/cvterm/auto_name/$cv_id",
|
|
|
- );
|
|
|
}
|
|
|
else {
|
|
|
- $form['term_name'] = array(
|
|
|
- '#type' => 'hidden',
|
|
|
- '#value' => $term_name,
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- // If the term belongs to more than one vocabulary then add additional fields
|
|
|
- // to let the user select the vocabulary.
|
|
|
- if ($num_terms > 1) {
|
|
|
- $cvs = array();
|
|
|
- foreach ($terms as $term) {
|
|
|
- $cvs[$term->cv_id->cv_id] = 'Vocabulary: <b>' . $term->cv_id->name . '</b> (' . $term->cv_id->definition . ')<br>' . $term->name . ': ' . $term->definition;
|
|
|
- }
|
|
|
- $form['cv_id'] = array(
|
|
|
- '#type' => 'radios',
|
|
|
- '#title' => t('Select the appropriate vocabulary'),
|
|
|
- '#options' => $cvs,
|
|
|
- );
|
|
|
+ tripal_set_message('A storage backend is not enabled for managing
|
|
|
+ the vocabulary terms used to create content. Please enable
|
|
|
+ a module that supports storage of vocabualary terms (e.g. tripal_chado)
|
|
|
+ and return to create new Tripal content types.', TRIPAL_NOTICE);
|
|
|
}
|
|
|
-
|
|
|
- // Add in the button for the cases of no terms or too many.
|
|
|
- $form['select_button'] = array(
|
|
|
- '#type' => 'submit',
|
|
|
- '#value' => t('Use this term'),
|
|
|
- '#name' => 'select_cvterm'
|
|
|
- );
|
|
|
-
|
|
|
return $form;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
- * Implements hook_validate() for the tripal_entities_admin_publish_form.
|
|
|
+ * Implements hook_validate() for the tripal_entities_admin_add_type_form.
|
|
|
*
|
|
|
*/
|
|
|
function tripal_entities_admin_add_type_form_validate($form, &$form_state) {
|
|
|
-
|
|
|
- if (array_key_exists('clicked_button', $form_state) and
|
|
|
- $form_state['clicked_button']['#name'] =='select_cvterm') {
|
|
|
-
|
|
|
- // First, make sure the term is unique. If not then we can't check it.
|
|
|
- $term_name = NULL;
|
|
|
- $cv_id = NULL;
|
|
|
- $cvterm = NULL;
|
|
|
- if (array_key_exists('term_name', $form_state['values'])) {
|
|
|
- $term_name = $form_state['input']['term_name'];
|
|
|
- }
|
|
|
- if (array_key_exists('cv_id', $form_state['input'])) {
|
|
|
- $cv_id = $form_state['input']['cv_id'];
|
|
|
- }
|
|
|
-
|
|
|
- // If a term and cv_id are provided then we can look for the term using
|
|
|
- // both and we should find a unique term. If only ther term is provided
|
|
|
- // we can still look for a unique term but there must only be one.
|
|
|
- if ($term_name and !$cv_id) {
|
|
|
- $match = array(
|
|
|
- 'name' => $term_name,
|
|
|
- );
|
|
|
- }
|
|
|
- else {
|
|
|
- $match = array(
|
|
|
- 'name' => $term_name,
|
|
|
- 'cv_id' => $cv_id,
|
|
|
- );
|
|
|
- }
|
|
|
- $terms = tripal_get_cvterm($match, array('return_array' => TRUE));
|
|
|
- $form_state['storage']['terms'] = $terms;
|
|
|
-
|
|
|
- // If we do not have any terms then the term provided by the user does not
|
|
|
- // exists and we need to provide an error message.
|
|
|
- if (count($terms) == 0) {
|
|
|
- form_set_error('term_name', t('The term does not exist in this database.'));
|
|
|
- }
|
|
|
- // If we have more than one term then we need to set an error so that the
|
|
|
- // form can provide a list of vocabularies to select from.
|
|
|
- if (count($terms) > 1) {
|
|
|
- form_set_error('term_name', t('The term is not unique. A list of vocabularies
|
|
|
- that contain this term. Please select the most appropriate vocabulary.'));
|
|
|
+ // TODO: we need some sort of administrative interface that lets the user
|
|
|
+ // switch to the desired vocabulary type. For now, we'll just use the
|
|
|
+ // first one in the list.
|
|
|
+ $stores = module_invoke_all('vocab_storage_info');
|
|
|
+ if (is_array($stores) and count($stores) > 0) {
|
|
|
+ $keys = array_keys($stores);
|
|
|
+ $module = $stores[$keys[0]]['module'];
|
|
|
+ $function = $module . '_vocab_select_term_form_validate';
|
|
|
+ if (function_exists($function)) {
|
|
|
+ $function($form, $form_state);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
- * Implements hook_submit() for the tripal_entities_admin_publish_form.
|
|
|
+ * Implements hook_submit() for the tripal_entities_admin_add_type_form.
|
|
|
+ *
|
|
|
+ * The storage backend must set the
|
|
|
*
|
|
|
*/
|
|
|
function tripal_entities_admin_add_type_form_submit($form, &$form_state) {
|
|
|
-
|
|
|
- if ($form_state['clicked_button']['#name'] =='select_cvterm') {
|
|
|
- $cvterm = $form_state['storage']['terms'][0];
|
|
|
-
|
|
|
- $bundle_id = 'bio-data_' . $cvterm->cvterm_id;
|
|
|
+ $namespace = '';
|
|
|
+ $term_id = '';
|
|
|
+ if (array_key_exists('storage', $form_state)) {
|
|
|
+ $storage = $form_state['storage'];
|
|
|
+ $namespace = array_key_exists('namespace', $storage) ? $storage['namespace'] : '';
|
|
|
+ $term_id = array_key_exists('term_id', $storage) ? $storage['term_id'] : '';
|
|
|
+ $term_name = array_key_exists('term_name', $storage) ? $storage['term_name'] : '';
|
|
|
|
|
|
// Before we try to add this type, check to see if it already exists
|
|
|
// as a bundle.
|
|
|
- $einfo = entity_get_info('TripalEntity');
|
|
|
- if (!in_array($bundle_id, array_keys($einfo['bundles']))) {
|
|
|
+ $term = tripal_load_term_entity($namespace, $term_id);
|
|
|
+ if (!$term) {
|
|
|
$error = '';
|
|
|
- $success = tripal_create_entity_type($cvterm, $error);
|
|
|
+ $success = tripal_create_bundle($namespace, $term_id, $term_name, $error);
|
|
|
if (!$success) {
|
|
|
drupal_set_message($error, 'error');
|
|
|
$form_state['redirect'] = "admin/structure/bio-data";
|