|
@@ -30,8 +30,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
|
|
|
$items['bio-data/add'] = array(
|
|
|
'title' => 'Add Tripal Content',
|
|
|
'page callback' => 'tripal_entities_add_page',
|
|
|
- 'file' => 'includes/tripal_entities.entity_form.inc',
|
|
|
- 'file path' => drupal_get_path('module', 'tripal_entities'),
|
|
|
'access arguments' => array('administer tripal data'),
|
|
|
);
|
|
|
|
|
@@ -52,8 +50,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
|
|
|
'page arguments' => array('tripal_entities_entity_form', 2),
|
|
|
'access callback' => 'tripal_entities_entity_access',
|
|
|
'access arguments' => array('edit'),
|
|
|
- 'file' => 'includes/tripal_entities.entity_form.inc',
|
|
|
- 'file path' => drupal_get_path('module', 'tripal_entities'),
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -87,8 +83,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
|
|
|
'page arguments' => array('tripal_entities_entity_form', NULL, 1),
|
|
|
'access callback' => 'tripal_entities_entity_access',
|
|
|
'access arguments' => array('edit', 1),
|
|
|
- 'file' => 'includes/tripal_entities.entity_form.inc',
|
|
|
- 'file path' => drupal_get_path('module', 'tripal_entities'),
|
|
|
'type' => MENU_LOCAL_TASK,
|
|
|
'weight' => -8,
|
|
|
);
|
|
@@ -100,8 +94,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
|
|
|
'page arguments' => array('tripal_entities_entity_delete_form', 1),
|
|
|
'access callback' => 'tripal_entities_entity_access',
|
|
|
'access arguments' => array('edit', 1),
|
|
|
- 'file' => 'includes/tripal_entities.entity_form.inc',
|
|
|
- 'file path' => drupal_get_path('module', 'tripal_entities'),
|
|
|
'type' => MENU_CALLBACK,
|
|
|
'weight' => 10,
|
|
|
);
|
|
@@ -114,7 +106,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
|
|
|
* @param unknown $entity
|
|
|
*/
|
|
|
function tripal_entity_manage_fields($entity) {
|
|
|
- drupal_goto('admin/structure/bio-data/manage/' . $entity->bundle . '/fields');
|
|
|
+ drupal_goto('admin/structure/bio-data/manage/' . $entity->name . '/fields');
|
|
|
return '';
|
|
|
}
|
|
|
|
|
@@ -237,3 +229,192 @@ function tripal_entities_view_entity($entity, $view_mode = 'full') {
|
|
|
|
|
|
return $form;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ function tripal_entities_entity_form($form, &$form_state, $term_id = '', $entity = NULL) {
|
|
|
+
|
|
|
+ $bundle_name = 'bio-data_' . $term_id;
|
|
|
+
|
|
|
+ // Add a vertical tabs element
|
|
|
+ $form['entity_form_vtabs'] = array(
|
|
|
+ '#type' => 'vertical_tabs',
|
|
|
+ '#weight' => 999,
|
|
|
+ );
|
|
|
+
|
|
|
+ // If the entity doesn't exist then create one.
|
|
|
+ if (!$entity) {
|
|
|
+ $entity = entity_get_controller('TripalEntity')->create(array('bundle' => $bundle_name, 'term_id' => $term_id));
|
|
|
+ field_attach_form('TripalEntity', $entity, $form, $form_state);
|
|
|
+
|
|
|
+ $form['add_button'] = array(
|
|
|
+ '#type' => 'submit',
|
|
|
+ '#value' => t('Save'),
|
|
|
+ '#name' => 'add_data',
|
|
|
+ '#weight' => 1000
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ field_attach_form('TripalEntity', $entity, $form, $form_state);
|
|
|
+ $form['update_button'] = array(
|
|
|
+ '#type' => 'submit',
|
|
|
+ '#value' => t('Update'),
|
|
|
+ '#name' => 'update_data',
|
|
|
+ '#weight' => 1000
|
|
|
+ );
|
|
|
+ $form['delete_button'] = array(
|
|
|
+ '#type' => 'submit',
|
|
|
+ '#value' => t('Delete'),
|
|
|
+ '#name' => 'delete_data',
|
|
|
+ '#weight' => 1001
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // The entity object must be added to the $form_state in order for
|
|
|
+ // the Entity API to work. It must have a key of the entity name.
|
|
|
+ $form_state['TripalEntity'] = $entity;
|
|
|
+
|
|
|
+ $form['#prefix'] = "<div id='$bundle_name-entity-form'>";
|
|
|
+ $form['#suffix'] = "</div>";
|
|
|
+ return $form;
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * An Ajax callback for the tripal_entities_entity_form.
|
|
|
+ */
|
|
|
+ function tripal_entities_entity_form_ajax_callback($form, $form_state) {
|
|
|
+ // return the form so Drupal can update the content on the page
|
|
|
+ return $form;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Implements hook_validate() for the tripal_entities_entity_form.
|
|
|
+ */
|
|
|
+ function tripal_entities_entity_form_validate($form, &$form_state) {
|
|
|
+
|
|
|
+ if (array_key_exists('clicked_button', $form_state) and
|
|
|
+ $form_state['clicked_button']['#name'] =='add_data') {
|
|
|
+ $entity = $form_state['TripalEntity'];
|
|
|
+ field_attach_form_validate('TripalEntity', $entity, $form, $form_state);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Implements hook_submit() for the tripal_entities_entity_form.
|
|
|
+ */
|
|
|
+ function tripal_entities_entity_form_submit($form, &$form_state) {
|
|
|
+ $entity = $form_state['TripalEntity'];
|
|
|
+
|
|
|
+ if ($form_state['clicked_button']['#name'] =='cancel') {
|
|
|
+ $form_state['redirect'] = "bio-data/" . $entity->id;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($form_state['clicked_button']['#name'] =='update_data' or
|
|
|
+ $form_state['clicked_button']['#name'] =='add_data') {
|
|
|
+
|
|
|
+ $entityform = entity_ui_controller('TripalEntity')->entityFormSubmitBuildEntity($form, $form_state);
|
|
|
+ if ($entityform->save()) {
|
|
|
+ $form_state['redirect'] = "bio-data/" . $entity->id;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ drupal_set_message('Cannot save entity', 'error');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($form_state['clicked_button']['#name'] =='delete_data') {
|
|
|
+ $form_state['redirect'] = 'bio-data/' . $entity->id .'/delete';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Provides a list of TripalEntity types (bundles) for the user to add.
|
|
|
+ *
|
|
|
+ * This function is a callback in a menu item which is set in the
|
|
|
+ * TripalEntityUIController class.
|
|
|
+ */
|
|
|
+ function tripal_entities_add_page() {
|
|
|
+ $item = menu_get_item();
|
|
|
+
|
|
|
+ $content = system_admin_menu_block($item);
|
|
|
+
|
|
|
+ // Bypass the node/add listing if only one content type is available.
|
|
|
+ if (count($content) == 1) {
|
|
|
+ $item = array_shift($content);
|
|
|
+ drupal_goto($item['href']);
|
|
|
+ }
|
|
|
+ return theme('tripal_entities_add_list', array('content' => $content));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns HTML for a list of available node types for node creation.
|
|
|
+ *
|
|
|
+ * @param $variables
|
|
|
+ * An associative array containing:
|
|
|
+ * - content: An array of content types.
|
|
|
+ *
|
|
|
+ * @ingroup themeable
|
|
|
+ */
|
|
|
+ function theme_tripal_entities_add_list($variables) {
|
|
|
+ $content = $variables['content'];
|
|
|
+ $output = '';
|
|
|
+
|
|
|
+ if ($content) {
|
|
|
+ $output = '<dl class="node-type-list">';
|
|
|
+ foreach ($content as $item) {
|
|
|
+ $output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
|
|
|
+ $output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
|
|
|
+ }
|
|
|
+ $output .= '</dl>';
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $output = tripal_set_message(
|
|
|
+ t('This page is for adding Tripal content to your site. However, before you can add data you have to specify what types of data your site will support. For example, if you want to add genes to be displayed to users, you must first create a data type "gene".'),
|
|
|
+ TRIPAL_INFO,
|
|
|
+ array('return_html' => TRUE)
|
|
|
+ );
|
|
|
+ $output .= '<p>' . t('You have not created any biological data types yet. ' .
|
|
|
+ 'Go to the <a href="@create-content">data type creation page</a> to ' .
|
|
|
+ 'add a new biological data type.',
|
|
|
+ array('@create-content' => url('admin/structure/bio-data/add'))) . '</p>';
|
|
|
+ }
|
|
|
+ return $output;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Form callback: confirmation form for deleting a tripal_entity.
|
|
|
+ *
|
|
|
+ * @param $tripal_entity The
|
|
|
+ * tripal_entity to delete
|
|
|
+ *
|
|
|
+ * @see confirm_form()
|
|
|
+ */
|
|
|
+ function tripal_entities_entity_delete_form($form, &$form_state, $entity) {
|
|
|
+ $form_state['entity'] = $entity;
|
|
|
+ $form['#submit'][] = 'tripal_entities_entity_delete_form_submit';
|
|
|
+
|
|
|
+ $form = confirm_form($form,
|
|
|
+ t('Click the delete button below to confirm deletion of the record titled: %title',
|
|
|
+ array('%title' => $entity->title)), 'admin/content/tripal_entity',
|
|
|
+ '<p>' .t('This action cannot be undone.') .'</p>', t('Delete'), t('Cancel'), 'confirm');
|
|
|
+
|
|
|
+ return $form;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Submit callback for tripal_entity_delete_form
|
|
|
+ */
|
|
|
+ function tripal_entities_entity_delete_form_submit($form, &$form_state) {
|
|
|
+ $entity = $form_state['entity'];
|
|
|
+
|
|
|
+ $entity_controller = new TripalEntityController($entity->type);
|
|
|
+ if ($entity_controller->delete($entity)) {
|
|
|
+ drupal_set_message(t('The record title "%name" has been deleted.', array('%name' => $entity->title)));
|
|
|
+ $form_state['redirect'] = 'admin/content/tripal_entitys';
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ drupal_set_message(t('The tripal_entity %name was not deleted.', array('%name' => $entity->title)), "error");
|
|
|
+ }
|
|
|
+ }
|