TripalEntityUIController.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <?php
  2. /**
  3. * UI controller.
  4. */
  5. class TripalEntityUIController extends EntityDefaultUIController {
  6. /**
  7. * Overrides hook_menu() defaults. Main reason for doing this is that
  8. * parent class hook_menu() is optimized for entity type administration.
  9. */
  10. public function hook_menu() {
  11. $items = array();
  12. // Set this on the object so classes that extend hook_menu() can use it.
  13. $this->id_count = count(explode('/', $this->path));
  14. $wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
  15. $id_count = count(explode('/', $this->path));
  16. // The content menu.
  17. $items[$this->path] = array(
  18. 'title' => 'Tripal Content',
  19. 'page callback' => 'tripal_content_view',
  20. 'file' => 'includes/tripal.admin.inc',
  21. 'file path' => drupal_get_path('module', 'tripal'),
  22. 'access arguments' => array('access tripal content overview'),
  23. 'type' => MENU_LOCAL_TASK,
  24. 'weight' => -9
  25. );
  26. $items['bio_data/add'] = array(
  27. 'title' => 'Add Tripal Content',
  28. 'page callback' => 'tripal_add_page',
  29. 'access callback' => '_tripal_entity_add_access',
  30. );
  31. // Add a menu item for creating each bundle
  32. $bundles = array_keys($this->entityInfo['bundles']);
  33. foreach ($bundles as $bundle_name) {
  34. $matches = array();
  35. if (preg_match('/^bio_data_(.*?)$/', $bundle_name, $matches)) {
  36. $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
  37. if (!$bundle) {
  38. throw new Exception(t("Cannot find bundle that matches: %bundle_name",
  39. array('%bundle_name' => $bundle_name)));
  40. }
  41. $term_id = $matches[1];
  42. // Get the term for this bundle
  43. $term = entity_load('TripalTerm', array('id' => $term_id));
  44. $term = reset($term);
  45. $default_description = $term->definition ? $term->definition : '';
  46. // Set a custom page for adding new tripal data entities.
  47. $items['bio_data/add/' . $term->id] = array(
  48. 'title' => ucfirst($bundle->label),
  49. 'description' => tripal_get_bundle_variable('description', $bundle->id, $default_description),
  50. 'page callback' => 'drupal_get_form',
  51. 'page arguments' => array('tripal_entity_form', 2),
  52. 'access arguments' => array('create bio_data_' . $term->id),
  53. );
  54. }
  55. }
  56. // Link for viewing a tripal data type.
  57. $items['bio_data/' . $wildcard] = array(
  58. 'title callback' => 'tripal_entity_title',
  59. 'title arguments' => array(1),
  60. 'page callback' => 'tripal_view_entity',
  61. 'page arguments' => array(1),
  62. 'access callback' => 'tripal_entity_access',
  63. 'access arguments' => array('view', 1),
  64. 'type' => MENU_CALLBACK,
  65. );
  66. // 'View' tab for an individual entity page.
  67. $items['bio_data/' . $wildcard . '/view'] = array(
  68. 'title' => 'View',
  69. 'page callback' => 'tripal_view_entity',
  70. 'page arguments' => array(1),
  71. 'access callback' => 'tripal_entity_access',
  72. 'access arguments' => array('view', 1),
  73. 'type' => MENU_DEFAULT_LOCAL_TASK,
  74. 'weight' => -10,
  75. );
  76. // 'Edit' tab for an individual entity page.
  77. $items['bio_data/' . $wildcard . '/edit'] = array(
  78. 'title' => 'Edit',
  79. 'page callback' => 'drupal_get_form',
  80. 'page arguments' => array('tripal_entity_form', NULL, 1),
  81. 'access callback' => 'tripal_entity_access',
  82. 'access arguments' => array('edit', 1),
  83. 'type' => MENU_LOCAL_TASK,
  84. 'weight' => -8,
  85. );
  86. // Menu item for deleting tripal data entities.
  87. $items['bio_data/' . $wildcard . '/delete'] = array(
  88. 'title' => 'Delete',
  89. 'page callback' => 'drupal_get_form',
  90. 'page arguments' => array('tripal_entity_delete_form', 1),
  91. 'access callback' => 'tripal_entity_access',
  92. 'access arguments' => array('delete', 1),
  93. 'type' => MENU_CALLBACK,
  94. 'weight' => 10,
  95. );
  96. return $items;
  97. }
  98. }
  99. /**
  100. * Menu callback to display an entity.
  101. *
  102. * As we load the entity for display, we're responsible for invoking a number
  103. * of hooks in their proper order.
  104. *
  105. * @see hook_entity_prepare_view()
  106. * @see hook_entity_view()
  107. * @see hook_entity_view_alter()
  108. */
  109. function tripal_view_entity($entity, $view_mode = 'full') {
  110. $content = '';
  111. $controller = entity_get_controller($entity->type);
  112. $content = $controller->view(array($entity->id => $entity));
  113. drupal_set_title($entity->title);
  114. return $content;
  115. }
  116. /**
  117. * Provide a data listing for tripal entites (ie: biological data).
  118. *
  119. * This function is a callback in a menu item which is set in the
  120. * TripalEntityUIController class.
  121. */
  122. function tripal_content_view() {
  123. // Retrieve our data listing form and render it.
  124. $form = drupal_get_form('tripal_content_overview_form');
  125. $output = drupal_render($form);
  126. // Set the breadcrumb.
  127. $breadcrumb = array();
  128. $breadcrumb[] = l('Home', '<front>');
  129. $breadcrumb[] = l('Administration', 'admin');
  130. drupal_set_breadcrumb($breadcrumb);
  131. return $output;
  132. }
  133. /**
  134. * Display a listing of Tripal entities.
  135. *
  136. * @TODO Filters and bulk operations needed to be added to this form.
  137. *
  138. * @param array $form
  139. * @param array $form_state
  140. * @return
  141. * A form array describing this listing to the Form API.
  142. */
  143. function tripal_content_overview_form($form, &$form_state) {
  144. global $user;
  145. // Set form defaults. The $_SESSION contains the last known selection
  146. // by this user. That should be overridden if the $_GET variable contains
  147. // values.
  148. $etype = '';
  149. $status = '';
  150. if (array_key_exists('tripal_content_overview', $_SESSION)) {
  151. $etype = $_SESSION['tripal_content_overview']['type'];
  152. $status = $_SESSION['tripal_content_overview']['status'];
  153. }
  154. $etype = array_key_exists('type', $_GET) ? $_GET['type'] : $etype;
  155. $status = array_key_exists('status', $_GET) ? $_GET['status'] : $status;
  156. $headers = array(
  157. 'title' => array(
  158. 'data' => t('Title'),
  159. 'type' => 'property',
  160. 'specifier' => 'title'
  161. ),
  162. 'Type',
  163. 'Term',
  164. 'Author',
  165. 'status' => array(
  166. 'data' => t('Status'),
  167. 'type' => 'property',
  168. 'specifier' => 'status'
  169. ),
  170. 'changed' => array(
  171. 'data' => t('Updated'),
  172. 'type' => 'property',
  173. 'specifier' => 'changed',
  174. 'sort' => 'desc',
  175. ),
  176. 'Operations',
  177. );
  178. $rows = array();
  179. // Get the Options arrays used by the fields below. We need to build them
  180. // here because we will use them both for creating the item list below
  181. // and for the fields.
  182. $etypes = db_select('tripal_bundle', 'tb')
  183. ->fields('tb', array('name', 'label'))
  184. ->execute()
  185. ->fetchAllKeyed();
  186. $etypes = array('0' => 'any') + $etypes;
  187. $statuses = array(
  188. '0' => 'any',
  189. 'status-1' => 'published',
  190. 'status-0' => 'not published'
  191. );
  192. // Build the list of existing filters.
  193. $items = array();
  194. if ($etype) {
  195. $items[] = 'where <strong>type</strong> is <strong>' . $etypes[$etype] . '</strong>';
  196. }
  197. if ($status) {
  198. $items[] = 'where <strong>status</strong> is <strong>' . $statuses[$status] . '</strong>';
  199. }
  200. // Add 'and' to the beginning of every filter after the first
  201. if (count($items) > 1) {
  202. for ($i = 1; $i < count($items); $i++) {
  203. $items[$i] = 'and ' . $items[$i];
  204. }
  205. }
  206. $list = theme_item_list(array(
  207. 'items' => $items,
  208. 'title' => '',
  209. 'type' => 'ul',
  210. 'attributes' => array(),
  211. ));
  212. // Set the title to be informative (defaults to content for some reason).
  213. drupal_set_title('Tripal Content');
  214. $form['filter'] = array(
  215. '#type' => 'fieldset',
  216. '#title' => 'Show only items where',
  217. '#collapsible' => FALSE,
  218. '#collapsed' => FALSE,
  219. '#prefix' => '<div class="exposed-filters">',
  220. '#suffix' => '</div>',
  221. );
  222. if (count($items) > 0) {
  223. $form['filter']['filters'] = array(
  224. '#type' => 'item',
  225. '#markup' => $list,
  226. );
  227. }
  228. if (!$status) {
  229. $form['filter']['status'] = array(
  230. '#type' => 'select',
  231. '#title' => 'Status',
  232. '#options' => $statuses,
  233. );
  234. }
  235. else {
  236. $form['filter']['status'] = array(
  237. '#type' => 'value',
  238. '#value' => $status,
  239. );
  240. }
  241. if (!$etype) {
  242. $form['filter']['type'] = array(
  243. '#type' => 'select',
  244. '#title' => 'Content Type',
  245. '#options' => $etypes,
  246. );
  247. }
  248. else {
  249. $form['filter']['type'] = array(
  250. '#type' => 'value',
  251. '#value' => $etype,
  252. );
  253. }
  254. $form['filter']['buttons'] = array(
  255. '#type' => 'value',
  256. '#prefix' => '<div id="edit-actions" class="container-inline form-actions form-wrapper">',
  257. '#suffix' => '</div>',
  258. );
  259. if (count($items) > 0) {
  260. if (count($items) < 2) {
  261. $form['filter']['buttons']['refinebtn'] = array(
  262. '#type' => 'submit',
  263. '#value' => 'Refine',
  264. '#name' => 'refine',
  265. );
  266. }
  267. $form['filter']['buttons']['filterbtn'] = array(
  268. '#type' => 'submit',
  269. '#value' => 'Reset',
  270. '#name' => 'reset',
  271. );
  272. }
  273. else {
  274. $form['filter']['buttons']['filterbtn'] = array(
  275. '#type' => 'submit',
  276. '#value' => 'Filter',
  277. '#name' => 'filter',
  278. );
  279. }
  280. $query = new EntityFieldQuery();
  281. $query->entityCondition('entity_type', 'TripalEntity');
  282. if ($etype) {
  283. $query->entityCondition('bundle', $etype);
  284. }
  285. //$query->propertyOrderBy('created', 'DESC');
  286. // Find out the total number of records and determine what page we're on, and
  287. // initialize the pager.
  288. $cquery = clone $query;
  289. $cquery->count();
  290. $num_records = $cquery->execute();
  291. // Calculate the range and create a pager.
  292. $query->pager(25);
  293. $query->tableSort($headers);
  294. $results = $query->execute();
  295. $pager = theme('pager');
  296. // For each entity retrieved add a row to the data listing.
  297. //while ($entity = $entities->fetchObject()) {
  298. if (!isset($results['TripalEntity'])) $results['TripalEntity'] = array();
  299. foreach ($results['TripalEntity'] as $entity_id => $stub) {
  300. $vocabulary = '';
  301. $term_name = '';
  302. // We don't need all of the attached fields for an entity so, we'll
  303. // not use the entity_load() function. Instead just pull it from the
  304. // database table.
  305. $equery = db_select('tripal_entity', 'TE');
  306. $equery->join('tripal_bundle', 'TB', 'TE.bundle = TB.name');
  307. $equery->fields('TB', array('label'));
  308. $equery->fields('TE');
  309. $equery->condition('TE.id', $entity_id);
  310. $entity = $equery->execute()->fetchObject();
  311. if (!$entity) {
  312. continue;
  313. }
  314. // Get the term
  315. $term = entity_load('TripalTerm', array('id' => $entity->term_id));
  316. $term = reset($term);
  317. if ($term) {
  318. $term_name = $term->name;
  319. $vocab = entity_load('TripalVocab', array('id' => $term->vocab_id));
  320. $vocab = reset($vocab);
  321. $vocabulary = $vocab->vocabulary;
  322. }
  323. // Retrieve details about the user who created this data.
  324. $author = user_load($entity->uid);
  325. // Build the action links
  326. $links = '';
  327. if (entity_access('edit', 'TripalEntity', $entity, $user)) {
  328. $links .= '&nbsp;&nbsp;' . l('edit', 'bio_data/' . $entity->id . '/edit');
  329. }
  330. if (entity_access('delete', 'TripalEntity', $entity, $user)) {
  331. $links .= '&nbsp;&nbsp;' . l('delete', 'bio_data/' . $entity->id . '/delete');
  332. }
  333. // Add information to the table.
  334. $rows[] = array(
  335. l($entity->title, 'bio_data/' . $entity->id),
  336. $entity->label,
  337. $vocabulary . ':' . $term_name,
  338. l($author->name, 'user/' . $entity->uid),
  339. $entity->status == 1 ? 'published' : 'unpublished',
  340. format_date($entity->changed, 'short'),
  341. $links,
  342. );
  343. }
  344. // If there are no entites created yet then add a message to the table to
  345. // provide guidance to administrators.
  346. if (empty($rows)) {
  347. $rows[] = array(
  348. array(
  349. 'data' => t('No content can be found.'),
  350. 'colspan' => 7
  351. )
  352. );
  353. }
  354. // Render the data listing.
  355. $table_vars = array(
  356. 'header' => $headers,
  357. 'rows' => $rows,
  358. 'attributes' => array(),
  359. 'sticky' => TRUE,
  360. 'caption' => '',
  361. 'colgroups' => array(),
  362. 'empty' => '',
  363. );
  364. $output = "<div><strong>Found $num_records records</strong></div>" . $pager . theme('table', $table_vars) . $pager;
  365. $form['results'] = array(
  366. '#type' => 'markup',
  367. '#markup' => $output,
  368. );
  369. return $form;
  370. }
  371. /**
  372. *
  373. */
  374. function tripal_content_overview_form_validate($form, &$form_state) {
  375. }
  376. /**
  377. *
  378. */
  379. function tripal_content_overview_form_submit($form, &$form_state) {
  380. // Always just rebuild the form on submit. that will update the
  381. // result table using the filters provided.
  382. $form_state['rebuild'] = TRUE;
  383. // Save the current user filter settings.
  384. if ($form_state['clicked_button']['#name'] == 'filter' or
  385. $form_state['clicked_button']['#name'] == 'refine') {
  386. $_SESSION['tripal_content_overview']['type'] = array_key_exists('type', $form_state['values']) ? $form_state['values']['type'] : '';
  387. $_SESSION['tripal_content_overview']['status'] = array_key_exists('status', $form_state['values']) ? $form_state['values']['status'] : '';
  388. }
  389. if ($form_state['clicked_button']['#name'] == 'reset') {
  390. unset($_SESSION['tripal_content_overview']);
  391. }
  392. }
  393. /**
  394. *
  395. */
  396. function tripal_entity_form($form, &$form_state, $term_id = '', $entity = NULL) {
  397. global $user;
  398. $bundle_name = 'bio_data_' . $term_id;
  399. // Add a vertical tabs element
  400. $form['entity_form_vtabs'] = array(
  401. '#type' => 'vertical_tabs',
  402. '#weight' => 999,
  403. );
  404. // If the entity doesn't exist then create one.
  405. if (!$entity) {
  406. $entity = entity_get_controller('TripalEntity')->create(array(
  407. 'bundle' => $bundle_name,
  408. 'term_id' => $term_id
  409. ));
  410. field_attach_form('TripalEntity', $entity, $form, $form_state);
  411. $form['add_button'] = array(
  412. '#type' => 'submit',
  413. '#value' => t('Save'),
  414. '#name' => 'add_data',
  415. '#weight' => 1000
  416. );
  417. }
  418. else {
  419. field_attach_form('TripalEntity', $entity, $form, $form_state);
  420. $form['update_button'] = array(
  421. '#type' => 'submit',
  422. '#value' => t('Update'),
  423. '#name' => 'update_data',
  424. '#weight' => 1000
  425. );
  426. // Put the delete button on the far-right so that it's harder
  427. // to accidentally click it.
  428. if (entity_access('delete', 'TripalEntity', $entity, $user)) {
  429. $form['delete_button'] = array(
  430. '#type' => 'submit',
  431. '#value' => t('Delete'),
  432. '#name' => 'delete_data',
  433. '#weight' => 1002,
  434. '#attributes' => array('style' => 'float: right')
  435. );
  436. }
  437. }
  438. $form['cancel_button'] = array(
  439. '#type' => 'submit',
  440. '#value' => t('Cancel'),
  441. '#name' => 'cancel_data',
  442. '#weight' => 1001,
  443. '#limit_validation_errors' => array(array('')),
  444. );
  445. // The entity object must be added to the $form_state in order for
  446. // the Entity API to work. It must have a key of the entity name.
  447. $form_state['TripalEntity'] = $entity;
  448. $form['#prefix'] = "<div id='$bundle_name-entity-form'>";
  449. $form['#suffix'] = "</div>";
  450. $form['#submit'][] = 'tripal_entity_form_submit';
  451. return $form;
  452. }
  453. /**
  454. * An Ajax callback for the tripal_entity_form.
  455. */
  456. function tripal_entity_form_ajax_callback($form, $form_state) {
  457. // return the form so Drupal can update the content on the page
  458. return $form;
  459. }
  460. /**
  461. * Implements hook_validate() for the tripal_entity_form.
  462. */
  463. function tripal_entity_form_validate($form, &$form_state) {
  464. // If the user is cancelling or deleting the entity then don't validate.
  465. if (array_key_exists('clicked_button', $form_state) and
  466. ($form_state['clicked_button']['#name'] == 'cancel_data' or
  467. $form_state['clicked_button']['#name'] == 'delete_data')) {
  468. return;
  469. }
  470. // For adds and updates, perform validation.
  471. $entity = $form_state['TripalEntity'];
  472. field_attach_form_validate('TripalEntity', $entity, $form, $form_state);
  473. }
  474. /**
  475. * Implements hook_submit() for the tripal_entity_form.
  476. */
  477. function tripal_entity_form_submit($form, &$form_state) {
  478. $entity = $form_state['TripalEntity'];
  479. if ($form_state['clicked_button']['#name'] =='cancel_data') {
  480. if (property_exists($entity, 'id')) {
  481. $form_state['redirect'] = "bio_data/" . $entity->id;
  482. }
  483. else {
  484. $form_state['redirect'] = 'bio_data/add';
  485. }
  486. return;
  487. }
  488. if ($form_state['clicked_button']['#name'] =='delete_data') {
  489. $form_state['redirect'] = 'bio_data/' . $entity->id .'/delete';
  490. return;
  491. }
  492. // Allow the fields to perform actions prior to submit.
  493. $instances = field_info_instances('TripalEntity', $entity->bundle);
  494. $langcode = 'und';
  495. foreach ($instances as $field_name => $instance) {
  496. $entity_type = $instance['entity_type'];
  497. if($entity_type == 'TripalEntity') {
  498. foreach ($form[$field_name][$langcode] as $delta => $field_form) {
  499. if (!preg_match('/^\d+$/', $delta)) {
  500. continue;
  501. }
  502. $widget_type = $instance['widget']['type'];
  503. if (tripal_load_include_field_class($widget_type)) {
  504. $field = $field_form['#field'];
  505. $widget = new $widget_type($field, $instance);
  506. $widget->submit($form, $form_state, $entity_type, $entity, $langcode, $delta);
  507. }
  508. }
  509. }
  510. }
  511. $entityform = entity_ui_controller('TripalEntity')->entityFormSubmitBuildEntity($form, $form_state);
  512. if ($entityform->save()) {
  513. $form_state['redirect'] = "bio_data/" . $entity->id;
  514. }
  515. else {
  516. drupal_set_message('Cannot save entity', 'error');
  517. }
  518. }
  519. /**
  520. * Provides a list of TripalEntity types (bundles) for the user to add.
  521. *
  522. * This function is a callback in a menu item which is set in the
  523. * TripalEntityUIController class.
  524. */
  525. function tripal_add_page() {
  526. $item = menu_get_item();
  527. $content = system_admin_menu_block($item);
  528. // Bypass the node/add listing if only one content type is available.
  529. if (count($content) == 1) {
  530. $item = array_shift($content);
  531. drupal_goto($item['href']);
  532. }
  533. return theme('tripal_add_list', array('content' => $content));
  534. }
  535. /**
  536. * Returns HTML for a list of available node types for node creation.
  537. *
  538. * @param $variables
  539. * An associative array containing:
  540. * - content: An array of content types.
  541. *
  542. * @ingroup themeable
  543. */
  544. function theme_tripal_add_list($variables) {
  545. $content = $variables['content'];
  546. $output = '';
  547. if ($content) {
  548. $output = '<dl class="node-type-list">';
  549. foreach ($content as $item) {
  550. $output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
  551. $output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
  552. }
  553. $output .= '</dl>';
  554. }
  555. else {
  556. $output = tripal_set_message(
  557. 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".'),
  558. TRIPAL_INFO,
  559. array('return_html' => TRUE)
  560. );
  561. $output .= '<p>' . t('You have not created any biological data types yet. ' .
  562. 'Go to the <a href="@create-content">data type creation page</a> to ' .
  563. 'add a new data type.',
  564. array('@create-content' => url('admin/structure/bio_data/add'))) . '</p>';
  565. }
  566. return $output;
  567. }
  568. /**
  569. * Form callback: confirmation form for deleting a tripal_entity.
  570. *
  571. * @param $tripal_entity The
  572. * tripal_entity to delete
  573. *
  574. * @see confirm_form()
  575. */
  576. function tripal_entity_delete_form($form, &$form_state, $entity) {
  577. $form_state['entity'] = $entity;
  578. $form['#submit'][] = 'tripal_entity_delete_form_submit';
  579. $form = confirm_form($form,
  580. t('Click the delete button below to confirm deletion of the record titled: %title',
  581. array('%title' => $entity->title)), 'admin/content/tripal_entity',
  582. '<p>' .t('This action cannot be undone.') .'</p>', t('Delete'), t('Cancel'), 'confirm');
  583. return $form;
  584. }
  585. /**
  586. * Submit callback for tripal_entity_delete_form
  587. */
  588. function tripal_entity_delete_form_submit($form, &$form_state) {
  589. $entity = $form_state['entity'];
  590. if (!entity_access('delete', 'TripalEntity', $entity, $user)) {
  591. drupal_set_message(t('You do not have permission to delete this content.'), "error");
  592. $form_state['redirect'] = 'admin/content/bio_data';
  593. return;
  594. }
  595. $entity_controller = new TripalEntityController($entity->type);
  596. if ($entity_controller->delete(array($entity->id))) {
  597. drupal_set_message(t('The record title "%name" has been deleted.', array('%name' => $entity->title)));
  598. $form_state['redirect'] = 'admin/content/bio_data';
  599. }
  600. else {
  601. drupal_set_message(t('The tripal_entity %name was not deleted.', array('%name' => $entity->title)), "error");
  602. }
  603. }
  604. /**
  605. * A helper function for checking if a user can add Tripal Content.
  606. *
  607. * This function is a callback for the bio_data/add menu path.
  608. */
  609. function _tripal_entity_add_access() {
  610. global $user;
  611. $types = tripal_get_content_types();
  612. foreach ($types as $type) {
  613. if (user_access('create ' . $type->name, $user)) {
  614. return TRUE;
  615. }
  616. }
  617. return FALSE;
  618. }