TripalBundleUIController.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * @file
  4. */
  5. /**
  6. * UI controller.
  7. */
  8. class TripalBundleUIController extends EntityDefaultUIController {
  9. public function __construct($entity_type, $entity_info) {
  10. parent::__construct($entity_type, $entity_info);
  11. }
  12. /**
  13. * Overrides hook_menu() defaults.
  14. */
  15. public function hook_menu() {
  16. $items = parent::hook_menu();
  17. // Alter the Admin > Structure > Tripal Content Types menu item.
  18. $items[$this->path]['description'] = 'Manage biological content types that are
  19. added using Tripal.';
  20. // We don't want to let the user import new Tripal data types.
  21. unset($items[$this->path . '/import']);
  22. // Add an action link to Admin > Structure > Tripal Content Types for adding types.
  23. $items[$this->path . '/add'] = array(
  24. 'title' => 'Add Tripal Content Type',
  25. 'description' => 'Add new biological content',
  26. 'page callback' => 'drupal_get_form',
  27. 'page arguments' => array('tripal_entities_admin_add_type_form'),
  28. 'access arguments' => array('administer tripal data types'),
  29. 'file' => 'includes/tripal_entities.admin.inc',
  30. 'file path' => drupal_get_path('module', 'tripal_entities'),
  31. 'type' => MENU_LOCAL_ACTION,
  32. 'weight' => 2
  33. );
  34. return $items;
  35. }
  36. /**
  37. * Allows us to change the forms created by the parent class.
  38. */
  39. function hook_forms() {
  40. $forms = parent::hook_forms();
  41. // The edit form for the entity type by default expects a function,
  42. // named after the entity type but we can't dynamically create these
  43. // functions. We'll use a single form for all entity types.
  44. $forms[$this->entityType . '_form'] = array(
  45. 'callback' => 'tripal_entities_tripal_bundle_form',
  46. 'callback arguments' => array($this->entityType)
  47. );
  48. return $forms;
  49. }
  50. }
  51. /**
  52. *
  53. * @param $form
  54. * @param $form_state
  55. * @param $entity
  56. */
  57. function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType) {
  58. $form = array();
  59. $form['message'] = array(
  60. '#type' => 'item',
  61. '#markup' => 'Edit the function "tripal_entities_tripal_bundle_form()" ' .
  62. 'to add a form each type. Put access controls here?',
  63. );
  64. return $form;
  65. }
  66. /**
  67. * Access callback for the entity API.
  68. */
  69. function tripal_bundle_access($op, $type = NULL, $account = NULL) {
  70. return user_access('administer tripal data types', $account);
  71. }
  72. /**
  73. * Generates the tripal data type editing form.
  74. */
  75. function tripal_bundle_form($form, &$form_state, $tripal_bundle, $op = 'edit') {
  76. if ($op == 'clone') {
  77. $tripal_bundle->label .= ' (cloned)';
  78. $tripal_bundle->type = '';
  79. }
  80. $form['label'] = array(
  81. '#title' => t('Label'),
  82. '#type' => 'textfield',
  83. '#default_value' => $tripal_bundle->label,
  84. '#description' => t('The human-readable name of this tripal data type.'),
  85. '#required' => TRUE,
  86. '#size' => 30,
  87. );
  88. return $form;
  89. }
  90. /**
  91. * Form API submit callback for the type form.
  92. */
  93. function tripal_bundle_form_submit(&$form, &$form_state) {
  94. $tripal_bundle = entity_ui_form_submit_build_entity($form, $form_state);
  95. $tripal_bundle->save();
  96. $form_state['redirect'] = $this->path;
  97. }
  98. /**
  99. * Form API submit callback for the delete button.
  100. */
  101. function tripal_bundle_form_submit_delete(&$form, &$form_state) {
  102. $form_state['redirect'] = $this->path;
  103. }