|
@@ -18,7 +18,7 @@ class TripalBundleUIController extends EntityDefaultUIController {
|
|
*/
|
|
*/
|
|
public function hook_menu() {
|
|
public function hook_menu() {
|
|
$items = parent::hook_menu();
|
|
$items = parent::hook_menu();
|
|
-
|
|
|
|
|
|
+
|
|
// Alter the Admin > Structure > Tripal Content Types menu item.
|
|
// Alter the Admin > Structure > Tripal Content Types menu item.
|
|
$items[$this->path]['description'] = 'Manage biological content types that are
|
|
$items[$this->path]['description'] = 'Manage biological content types that are
|
|
added using Tripal.';
|
|
added using Tripal.';
|
|
@@ -38,7 +38,7 @@ class TripalBundleUIController extends EntityDefaultUIController {
|
|
'type' => MENU_LOCAL_ACTION,
|
|
'type' => MENU_LOCAL_ACTION,
|
|
'weight' => 2
|
|
'weight' => 2
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+
|
|
return $items;
|
|
return $items;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -58,7 +58,7 @@ class TripalBundleUIController extends EntityDefaultUIController {
|
|
|
|
|
|
return $forms;
|
|
return $forms;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -74,43 +74,67 @@ class TripalBundleUIController extends EntityDefaultUIController {
|
|
function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType) {
|
|
function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType) {
|
|
|
|
|
|
$entity_type = $form_state['build_info']['args'][0];
|
|
$entity_type = $form_state['build_info']['args'][0];
|
|
- $chado_basetable = $entity_type->label;
|
|
|
|
- $cvterm = chado_generate_var('cvterm', array('name' => $entity_type->label));
|
|
|
|
-
|
|
|
|
|
|
+ if (preg_match('/bio-data_(\d+)/', $entity_type->term_id, $matches)) {
|
|
|
|
+ $term = entity_load('TripalTerm', array('id' => $entity_type->term_id));
|
|
|
|
+ $term = reset($term);
|
|
|
|
+ $vocab = entity_load('TripalVocab', array('id' => $term->vocab_id));
|
|
|
|
+ $vocab = reset($vocab);
|
|
|
|
+ }
|
|
|
|
+
|
|
// Add a validate and submit handler to save the data in this form.
|
|
// Add a validate and submit handler to save the data in this form.
|
|
$form['#validate'] = array('tripal_entities_tripal_bundle_form_validate');
|
|
$form['#validate'] = array('tripal_entities_tripal_bundle_form_validate');
|
|
$form['#submit'] = array('tripal_entities_tripal_bundle_form_submit');
|
|
$form['#submit'] = array('tripal_entities_tripal_bundle_form_submit');
|
|
-
|
|
|
|
|
|
+
|
|
// @TODO: Move this into a css file.
|
|
// @TODO: Move this into a css file.
|
|
$form['#attached']['css'] = array(
|
|
$form['#attached']['css'] = array(
|
|
array(
|
|
array(
|
|
- 'data' => '.form-item select, .form-item input { width:40%; }',
|
|
|
|
|
|
+ 'data' => '
|
|
|
|
+ .form-item select, .form-item input { width:40%; }
|
|
|
|
+ th.side-header { width: 220px; }',
|
|
'type' => 'inline',
|
|
'type' => 'inline',
|
|
),
|
|
),
|
|
);
|
|
);
|
|
-
|
|
|
|
- $form['vocab'] = array(
|
|
|
|
- '#type' => 'select',
|
|
|
|
- '#title' => t('Vocabulary'),
|
|
|
|
- '#options' => array($cvterm->cv_id->name),
|
|
|
|
- '#description' => t('The vocabulary the following term is part of.'),
|
|
|
|
- '#default_value' => $cvterm->cv_id->name,
|
|
|
|
- '#disabled' => TRUE
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- $form['term'] = array(
|
|
|
|
|
|
+
|
|
|
|
+ if ($term) {
|
|
|
|
+ $form['term'] = array(
|
|
|
|
+ '#type' => 'markup',
|
|
|
|
+ '#markup' => theme('table', array(
|
|
|
|
+ 'header' => array(),
|
|
|
|
+ 'rows' => array(
|
|
|
|
+ array(array('header' => TRUE, 'data' => 'Vocabulary', 'class' => array('side-header')), $vocab->namespace),
|
|
|
|
+ array(array('header' => TRUE, 'data' => 'Term', 'class' => array('side-header')), $term->name),
|
|
|
|
+ )
|
|
|
|
+ ))
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $form['label'] = array(
|
|
'#type' => 'textfield',
|
|
'#type' => 'textfield',
|
|
- '#title' => t('Term'),
|
|
|
|
- '#description' => t('The term the content type is based on.'),
|
|
|
|
- '#default_value' => $cvterm->name,
|
|
|
|
- '#disabled' => TRUE
|
|
|
|
|
|
+ '#title' => t('Name'),
|
|
|
|
+ '#required' => TRUE,
|
|
|
|
+ '#description' => t('The human-readable name of this content type. This text will be
|
|
|
|
+ displayed as part of the list on the <em>Add new content page</em>. It is recommended that
|
|
|
|
+ this name begin with a capital letter and contain only letters, numbers, and spaces.
|
|
|
|
+ This name must be unique.'),
|
|
|
|
+ '#default_value' => $entity_type->label,
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ $form['description'] = array(
|
|
|
|
+ '#type' => 'textarea',
|
|
|
|
+ '#title' => t('Description'),
|
|
|
|
+ '#required' => TRUE,
|
|
|
|
+ '#description' => t('Describe this content type. The text will be displayed on the <em>Add new content page</em>.'),
|
|
|
|
+ '#default_value' => tripal_get_bundle_variable('description', $entity_type->id, $term->definition),
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+ if (!$form['description']['#default_value']) {
|
|
|
|
+ //$form['description']['#default_value'] = $cvterm->definition;
|
|
|
|
+ }
|
|
|
|
+
|
|
$form['additional_settings'] = array(
|
|
$form['additional_settings'] = array(
|
|
'#type' => 'vertical_tabs',
|
|
'#type' => 'vertical_tabs',
|
|
'#weight' => 99,
|
|
'#weight' => 99,
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+
|
|
// Set Title Format.
|
|
// Set Title Format.
|
|
//-------------------------
|
|
//-------------------------
|
|
$title_format = tripal_get_title_format($entity_type);
|
|
$title_format = tripal_get_title_format($entity_type);
|
|
@@ -123,12 +147,12 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
|
|
'#tree' => TRUE,
|
|
'#tree' => TRUE,
|
|
'#group' => 'additional_settings',
|
|
'#group' => 'additional_settings',
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+
|
|
$form['set_titles']['explanation'] = array(
|
|
$form['set_titles']['explanation'] = array(
|
|
'#type' => 'item',
|
|
'#type' => 'item',
|
|
- '#markup' => t('<p>The format below is used to determine the title displayed on content
|
|
|
|
- pages. This ensures all content of this type is consistent while still allowing you
|
|
|
|
- to indicate which data you want represented in the title (ie: which data would most
|
|
|
|
|
|
+ '#markup' => t('<p>The format below is used to determine the title displayed on content
|
|
|
|
+ pages. This ensures all content of this type is consistent while still allowing you
|
|
|
|
+ to indicate which data you want represented in the title (ie: which data would most
|
|
identify your content).</p>
|
|
identify your content).</p>
|
|
<p>Keep in mind that it might be confusing to users if more than
|
|
<p>Keep in mind that it might be confusing to users if more than
|
|
one page has the same title. We recommend you <strong>choose a combination of tokens that
|
|
one page has the same title. We recommend you <strong>choose a combination of tokens that
|
|
@@ -141,6 +165,7 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
|
|
'#description' => t('You may rearrange elements in this text box to customize the page
|
|
'#description' => t('You may rearrange elements in this text box to customize the page
|
|
titles. The available tokens are listed below. You can separate or include any text
|
|
titles. The available tokens are listed below. You can separate or include any text
|
|
between the tokens.'),
|
|
between the tokens.'),
|
|
|
|
+ '#required' => TRUE,
|
|
'#default_value' => $title_format,
|
|
'#default_value' => $title_format,
|
|
'#rows' => 1
|
|
'#rows' => 1
|
|
);
|
|
);
|
|
@@ -153,30 +178,26 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
|
|
'#collapsed' => TRUE
|
|
'#collapsed' => TRUE
|
|
);
|
|
);
|
|
|
|
|
|
- $tokens = array();
|
|
|
|
- if (empty($tokens)) {
|
|
|
|
- $tokens = chado_node_generate_tokens($chado_basetable);
|
|
|
|
- }
|
|
|
|
|
|
+ $tokens = tripal_get_tokens($entity_type);
|
|
$form['set_titles']['tokens'] = array(
|
|
$form['set_titles']['tokens'] = array(
|
|
'#type' => 'hidden',
|
|
'#type' => 'hidden',
|
|
'#value' => serialize($tokens)
|
|
'#value' => serialize($tokens)
|
|
);
|
|
);
|
|
-
|
|
|
|
- $token_list = chado_node_format_tokens($tokens);
|
|
|
|
|
|
+
|
|
$form['set_titles']['token_display']['content'] = array(
|
|
$form['set_titles']['token_display']['content'] = array(
|
|
'#type' => 'item',
|
|
'#type' => 'item',
|
|
- '#markup' => $token_list
|
|
|
|
|
|
+ '#markup' => theme_token_list($tokens)
|
|
);
|
|
);
|
|
|
|
|
|
// Submit Buttons
|
|
// Submit Buttons
|
|
//-------------------------
|
|
//-------------------------
|
|
-
|
|
|
|
|
|
+
|
|
$form['save'] = array(
|
|
$form['save'] = array(
|
|
'#type' => 'submit',
|
|
'#type' => 'submit',
|
|
'#value' => t('Save Content Type'),
|
|
'#value' => t('Save Content Type'),
|
|
'#weight' => 100
|
|
'#weight' => 100
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+
|
|
$form['delete'] = array(
|
|
$form['delete'] = array(
|
|
'#type' => 'submit',
|
|
'#type' => 'submit',
|
|
'#value' => t('Delete Content Type'),
|
|
'#value' => t('Delete Content Type'),
|
|
@@ -192,19 +213,19 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
|
|
function tripal_entities_tripal_bundle_form_validate($form, $form_state) {
|
|
function tripal_entities_tripal_bundle_form_validate($form, $form_state) {
|
|
|
|
|
|
$tokens_available = unserialize($form_state['values']['set_titles']['tokens']);
|
|
$tokens_available = unserialize($form_state['values']['set_titles']['tokens']);
|
|
- if (preg_match_all('/(\[\w+\.\w+\])/', $form_state['values']['set_titles']['title_format'], $matches)) {
|
|
|
|
-
|
|
|
|
|
|
+ if (preg_match_all('/(\[\w+\])/', $form_state['values']['set_titles']['title_format'], $matches)) {
|
|
|
|
+
|
|
// The matches of the first and only pattern will be our tokens.
|
|
// The matches of the first and only pattern will be our tokens.
|
|
$tokens_used = $matches[1];
|
|
$tokens_used = $matches[1];
|
|
// Determine if any of the tokens used were not in the original list of available tokens.
|
|
// Determine if any of the tokens used were not in the original list of available tokens.
|
|
$tokens_missing = array_diff($tokens_used, array_keys($tokens_available));
|
|
$tokens_missing = array_diff($tokens_used, array_keys($tokens_available));
|
|
-
|
|
|
|
|
|
+
|
|
if ($tokens_missing) {
|
|
if ($tokens_missing) {
|
|
$msg = t('You must only use tokens listed under available tokens. You used the following incorrect tokens: %tokens',
|
|
$msg = t('You must only use tokens listed under available tokens. You used the following incorrect tokens: %tokens',
|
|
array('%tokens' => implode(', ', $tokens_missing)));
|
|
array('%tokens' => implode(', ', $tokens_missing)));
|
|
form_set_error('set_titles][title_format', $msg);
|
|
form_set_error('set_titles][title_format', $msg);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
$msg = t('You should use at least one token in your title format or the title for all %type pages will be the same.',
|
|
$msg = t('You should use at least one token in your title format or the title for all %type pages will be the same.',
|
|
@@ -217,14 +238,23 @@ function tripal_entities_tripal_bundle_form_validate($form, $form_state) {
|
|
* Submit: Tripal content type edit form.
|
|
* Submit: Tripal content type edit form.
|
|
*/
|
|
*/
|
|
function tripal_entities_tripal_bundle_form_submit($form, &$form_state) {
|
|
function tripal_entities_tripal_bundle_form_submit($form, &$form_state) {
|
|
-
|
|
|
|
|
|
+
|
|
if ($form_state['triggering_element']['#value'] == 'Save Content Type') {
|
|
if ($form_state['triggering_element']['#value'] == 'Save Content Type') {
|
|
|
|
+ $bundle_entity = $form_state['build_info']['args'][0];
|
|
|
|
+
|
|
|
|
+ // Save the label.
|
|
|
|
+ $bundle_entity->label = $form_state['values']['label'];
|
|
|
|
+ $bundle_entity->save();
|
|
|
|
+
|
|
|
|
+ // Save the description.
|
|
|
|
+ tripal_bundle_save_variable('description', $bundle_entity->id, $form_state['values']['description']);
|
|
|
|
+
|
|
// Save the page title format.
|
|
// Save the page title format.
|
|
tripal_save_title_format(
|
|
tripal_save_title_format(
|
|
- $form_state['build_info']['args'][0],
|
|
|
|
|
|
+ $bundle_entity,
|
|
$form_state['values']['set_titles']['title_format']
|
|
$form_state['values']['set_titles']['title_format']
|
|
);
|
|
);
|
|
-
|
|
|
|
|
|
+
|
|
$form_state['redirect'] = 'admin/structure/bio-data';
|
|
$form_state['redirect'] = 'admin/structure/bio-data';
|
|
drupal_set_message(t('Successfully saved %type content type.', array('%type' => $form_state['build_info']['args'][0]->label)));
|
|
drupal_set_message(t('Successfully saved %type content type.', array('%type' => $form_state['build_info']['args'][0]->label)));
|
|
}
|
|
}
|