TripalBundleUIController.inc 3.1 KB

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