TripalBundleUIController.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. // The 'bundle of' property is usually set in the hook_entity_info()
  11. // function for the "entity type" entity. This allows the Entity API
  12. // to provide the user interface for managing fields attached to the
  13. // bundle. But, we are using the same controller classes for
  14. // all entity types and we do not want new links for every
  15. // entity type (vocabulary) on the Administration >> Structure menu.
  16. // We just want one menu item. So to support one menu item that
  17. // can handle all of the Tripal entity types, we have to set the
  18. // 'bundle of' property here rather than in the hook_entity_info() function.
  19. $bundle_of = $entity_type;
  20. $bundle_of = preg_replace('/_bundle/', '', $bundle_of);
  21. $entity_info['bundle of'] = $bundle_of;
  22. parent::__construct($entity_type, $entity_info);
  23. }
  24. /**
  25. * Overrides hook_menu() defaults.
  26. */
  27. public function hook_menu() {
  28. $items = parent::hook_menu();
  29. $items[$this->path]['description'] = 'Manage Tripal data types, including adding
  30. and removing fields and the display of fields.';
  31. // We don't want to let the user add new Tripal data types. They
  32. // are added automatically.
  33. unset($items[$this->path . '/add']);
  34. unset($items[$this->path . '/import']);
  35. $items[$this->path . '/publish'] = array(
  36. 'title' => 'Add new biological data',
  37. 'description' => 'Publish Data',
  38. 'page callback' => 'drupal_get_form',
  39. 'page arguments' => array('tripal_entities_admin_publish_form'),
  40. 'access arguments' => array('administer tripal data types'),
  41. 'file' => 'includes/tripal_entities.admin.inc',
  42. 'file path' => drupal_get_path('module', 'tripal_entities'),
  43. 'type' => MENU_LOCAL_ACTION,
  44. 'weight' => 2
  45. );
  46. return $items;
  47. }
  48. /**
  49. * Allows us to change the forms created by the parent class.
  50. */
  51. function hook_forms() {
  52. $forms = parent::hook_forms();
  53. // The edit form for the entity type by default expects a function,
  54. // named after the entity type but we can't dynamically create these
  55. // functions. We'll use a single form for all entity types.
  56. $forms[$this->entityType . '_form'] = array(
  57. 'callback' => 'tripal_entities_tripal_bundle_form',
  58. 'callback arguments' => array($this->entityType)
  59. );
  60. return $forms;
  61. }
  62. }
  63. /**
  64. *
  65. * @param $form
  66. * @param $form_state
  67. * @param $entity
  68. */
  69. function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType) {
  70. $form = array();
  71. $form['message'] = array(
  72. '#type' => 'item',
  73. '#markup' => 'Edit the function "tripal_entities_tripal_bundle_form()" to add a form each type. Put access controls here?',
  74. );
  75. return $form;
  76. }
  77. /**
  78. * Access callback for the entity API.
  79. */
  80. function tripal_bundle_access($op, $type = NULL, $account = NULL) {
  81. return user_access('administer tripal data types', $account);
  82. }
  83. /**
  84. * Generates the tripal data type editing form.
  85. */
  86. function tripal_bundle_form($form, &$form_state, $tripal_bundle, $op = 'edit') {
  87. if ($op == 'clone') {
  88. $tripal_bundle->label .= ' (cloned)';
  89. $tripal_bundle->type = '';
  90. }
  91. $form['label'] = array(
  92. '#title' => t('Label'),
  93. '#type' => 'textfield',
  94. '#default_value' => $tripal_bundle->label,
  95. '#description' => t('The human-readable name of this tripal data type.'),
  96. '#required' => TRUE,
  97. '#size' => 30,
  98. );
  99. return $form;
  100. }
  101. /**
  102. * Form API submit callback for the type form.
  103. */
  104. function tripal_bundle_form_submit(&$form, &$form_state) {
  105. $tripal_bundle = entity_ui_form_submit_build_entity($form, $form_state);
  106. $tripal_bundle->save();
  107. $form_state['redirect'] = $this->path;
  108. }
  109. /**
  110. * Form API submit callback for the delete button.
  111. */
  112. function tripal_bundle_form_submit_delete(&$form, &$form_state) {
  113. $form_state['redirect'] = $this->path;
  114. }