TripalEntityUIController.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_entities_content_view',
  20. 'file' => 'includes/tripal_entities.admin.inc',
  21. 'file path' => drupal_get_path('module', 'tripal_entities'),
  22. 'access arguments' => array('administer tripal data'),
  23. 'type' => MENU_LOCAL_TASK,
  24. 'weight' => -9
  25. );
  26. $items['bio-data/add'] = array(
  27. 'title' => 'Add Tripal Content',
  28. 'page callback' => 'tripal_entities_add_page',
  29. 'file' => 'includes/tripal_entities.entity_form.inc',
  30. 'file path' => drupal_get_path('module', 'tripal_entities'),
  31. 'access callback' => 'tripal_entities_entity_access',
  32. 'access arguments' => array('edit'),
  33. );
  34. // Add a menu item for creating each bundle
  35. $bundles = array_keys($this->entityInfo['bundles']);
  36. foreach ($bundles as $bundle) {
  37. $matches = array();
  38. preg_match('/^bio-data_(.*?)$/', $bundle, $matches);
  39. $cvterm_id = $matches[1];
  40. $cvterm = tripal_get_cvterm(array('cvterm_id' => $cvterm_id));
  41. // Set a custom page for adding new tripal data entities.
  42. $items['bio-data/add/' . $cvterm_id] = array(
  43. 'title' => ucfirst($cvterm->name),
  44. 'description' => 'A ' . $cvterm->name . ' record.',
  45. 'page callback' => 'drupal_get_form',
  46. 'page arguments' => array('tripal_entities_entity_form', 2),
  47. 'access callback' => 'tripal_entities_entity_access',
  48. 'access arguments' => array('edit'),
  49. 'file' => 'includes/tripal_entities.entity_form.inc',
  50. 'file path' => drupal_get_path('module', 'tripal_entities'),
  51. );
  52. }
  53. // Link for viewing a tripal data type.
  54. $items['bio-data/' . $wildcard] = array(
  55. 'title callback' => 'tripal_entities_entity_title',
  56. 'title arguments' => array(1),
  57. 'page callback' => 'tripal_entities_view_entity',
  58. 'page arguments' => array(1),
  59. 'access callback' => 'tripal_entities_entity_access',
  60. 'access arguments' => array('view', 1),
  61. 'type' => MENU_CALLBACK,
  62. );
  63. // 'View' tab for an individual entity page.
  64. $items['bio-data/' . $wildcard . '/view'] = array(
  65. 'title' => 'View',
  66. 'page callback' => 'tripal_entities_view_entity',
  67. 'page arguments' => array(1),
  68. 'access callback' => 'tripal_entities_entity_access',
  69. 'access arguments' => array('view', 1),
  70. 'type' => MENU_DEFAULT_LOCAL_TASK,
  71. 'weight' => -10,
  72. );
  73. // 'Edit' tab for an individual entity page.
  74. $items['bio-data/' . $wildcard . '/edit'] = array(
  75. 'title' => 'Edit',
  76. 'page callback' => 'drupal_get_form',
  77. 'page arguments' => array('tripal_entities_entity_form', NULL, 1),
  78. 'access callback' => 'tripal_entities_entity_access',
  79. 'access arguments' => array('edit', 1),
  80. 'file' => 'includes/tripal_entities.entity_form.inc',
  81. 'file path' => drupal_get_path('module', 'tripal_entities'),
  82. 'type' => MENU_LOCAL_TASK,
  83. 'weight' => -8,
  84. );
  85. // Menu item for deleting tripal data entities.
  86. $items['bio-data/' . $wildcard . '/delete'] = array(
  87. 'title' => 'Delete',
  88. 'page callback' => 'drupal_get_form',
  89. 'page arguments' => array('tripal_entities_entity_delete_form', 1),
  90. 'access callback' => 'tripal_entities_entity_access',
  91. 'access arguments' => array('edit', 1),
  92. 'file' => 'includes/tripal_entities.entity_form.inc',
  93. 'file path' => drupal_get_path('module', 'tripal_entities'),
  94. 'type' => MENU_CALLBACK,
  95. 'weight' => 10,
  96. );
  97. return $items;
  98. }
  99. }
  100. /**
  101. *
  102. * @param unknown $entity
  103. */
  104. function tripal_entity_manage_fields($entity) {
  105. drupal_goto('admin/structure/bio-data/manage/' . $entity->bundle . '/fields');
  106. return '';
  107. }