123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- <?php
- class TripalEntityUIController extends EntityDefaultUIController {
-
- public function hook_menu() {
- $items = array();
-
- $this->id_count = count(explode('/', $this->path));
- $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
- $id_count = count(explode('/', $this->path));
-
- $items[$this->path] = array(
- 'title' => 'Tripal Content',
- 'page callback' => 'tripal_entities_content_view',
- 'file' => 'includes/tripal_entities.admin.inc',
- 'file path' => drupal_get_path('module', 'tripal_entities'),
- 'access arguments' => array('administer tripal data'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => -9
- );
- $items['bio-data/add'] = array(
- 'title' => 'Add Tripal Content',
- 'page callback' => 'tripal_entities_add_page',
- 'access arguments' => array('administer tripal data'),
- );
-
- $bundles = array_keys($this->entityInfo['bundles']);
- foreach ($bundles as $bundle_name) {
- $matches = array();
- if (preg_match('/^bio-data_(.*?)$/', $bundle_name, $matches)) {
- $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
-
- $term = entity_load('TripalTerm', array('id' => $matches[1]));
- $term = reset($term);
-
- $items['bio-data/add/' . $term->id] = array(
- 'title' => ucfirst($bundle->label),
- 'description' => tripal_get_bundle_variable('description', $bundle->id, $term->definition),
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_entities_entity_form', 2),
- 'access callback' => 'tripal_entities_entity_access',
- 'access arguments' => array('edit'),
- );
- }
- }
-
- $items['bio-data/' . $wildcard] = array(
- 'title callback' => 'tripal_entities_entity_title',
- 'title arguments' => array(1),
- 'page callback' => 'tripal_entities_view_entity',
- 'page arguments' => array(1),
- 'access callback' => 'tripal_entities_entity_access',
- 'access arguments' => array('view', 1),
- 'type' => MENU_CALLBACK,
- );
-
- $items['bio-data/' . $wildcard . '/view'] = array(
- 'title' => 'View',
- 'page callback' => 'tripal_entities_view_entity',
- 'page arguments' => array(1),
- 'access callback' => 'tripal_entities_entity_access',
- 'access arguments' => array('view', 1),
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => -10,
- );
-
- $items['bio-data/' . $wildcard . '/edit'] = array(
- 'title' => 'Edit',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_entities_entity_form', NULL, 1),
- 'access callback' => 'tripal_entities_entity_access',
- 'access arguments' => array('edit', 1),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => -8,
- );
-
- $items['bio-data/' . $wildcard . '/delete'] = array(
- 'title' => 'Delete',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_entities_entity_delete_form', 1),
- 'access callback' => 'tripal_entities_entity_access',
- 'access arguments' => array('edit', 1),
- 'type' => MENU_CALLBACK,
- 'weight' => 10,
- );
- return $items;
- }
- }
- function tripal_entity_manage_fields($entity) {
- drupal_goto('admin/structure/bio-data/manage/' . $entity->name . '/fields');
- return '';
- }
- function tripal_entities_view_entity($entity, $view_mode = 'full') {
- $content = '';
- $controller = entity_get_controller($entity->type);
- $content = $controller->view(array($entity->id => $entity));
- drupal_set_title($entity->title);
- return $content;
- }
-
- function tripal_entities_content_view() {
-
- $form = drupal_get_form('tripal_entities_content_overview_form');
- $output = drupal_render($form);
-
- $breadcrumb = array();
- $breadcrumb[] = l('Home', '<front>');
- $breadcrumb[] = l('Administration', 'admin');
- drupal_set_breadcrumb($breadcrumb);
- return $output;
- }
-
- function tripal_entities_content_overview_form($form, &$form_state) {
-
- drupal_set_title('Tripal Content');
-
-
- $entities = db_select('tripal_entity', 'td')
- ->fields('td')
- ->orderBy('created', 'DESC')
- ->range(0,25)
- ->execute();
- $headers = array('Title', 'Vocabulary', 'Term', 'Author', 'Status', 'Updated', 'Operations');
- $rows = array();
-
- while ($entity = $entities->fetchObject()) {
-
- $term = entity_load('TripalTerm', array('id' => $entity->term_id));
- $term = reset($term);
- $vocab = entity_load('TripalVocab', array('id' => $term->vocab_id));
- $vocab = reset($vocab);
-
- $author = user_load($entity->uid);
-
- $rows[] = array(
- l($entity->title, 'bio-data/' . $entity->id),
- $vocab->namespace,
- $term->name,
- l($author->name, 'user/' . $entity->uid),
- $entity->status == 1 ? 'published' : 'unpublished',
- format_date($entity->changed, 'short'),
- l('edit', 'bio-data/' . $entity->id . '/edit') . ' ' .
- l('delete', 'bio-data/' . $entity->id . '/delete')
- );
- }
-
-
- if (empty($rows)) {
- $rows[] = array(
- array(
- 'data' => t('No Tripal content available.'),
- 'colspan' => 7
- )
- );
- }
-
- $table_vars = array(
- 'header' => $headers,
- 'rows' => $rows,
- 'attributes' => array(),
- 'sticky' => TRUE,
- 'caption' => '',
- 'colgroups' => array(),
- 'empty' => '',
- );
- $form['results'] = array(
- '#type' => 'markup',
- '#markup' => theme('table', $table_vars),
- );
- return $form;
- }
-
- function tripal_entities_entity_form($form, &$form_state, $term_id = '', $entity = NULL) {
- $bundle_name = 'bio-data_' . $term_id;
-
- $form['entity_form_vtabs'] = array(
- '#type' => 'vertical_tabs',
- '#weight' => 999,
- );
-
- 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
- );
- }
-
-
- $form_state['TripalEntity'] = $entity;
- $form['#prefix'] = "<div id='$bundle_name-entity-form'>";
- $form['#suffix'] = "</div>";
- return $form;
- }
-
- function tripal_entities_entity_form_ajax_callback($form, $form_state) {
-
- return $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);
- }
- }
-
- 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';
- }
- }
-
- function tripal_entities_add_page() {
- $item = menu_get_item();
- $content = system_admin_menu_block($item);
-
- if (count($content) == 1) {
- $item = array_shift($content);
- drupal_goto($item['href']);
- }
- return theme('tripal_entities_add_list', array('content' => $content));
- }
-
- 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;
- }
-
- 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;
- }
-
- function tripal_entities_entity_delete_form_submit($form, &$form_state) {
- $entity = $form_state['entity'];
- $entity_controller = new TripalEntityController($entity->type);
- if ($entity_controller->delete(array($entity->id))) {
- drupal_set_message(t('The record title "%name" has been deleted.', array('%name' => $entity->title)));
- $form_state['redirect'] = 'admin/content/bio-data';
- }
- else {
- drupal_set_message(t('The tripal_entity %name was not deleted.', array('%name' => $entity->title)), "error");
- }
- }
|