TripalDataTypeUIController.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @file
  4. */
  5. /**
  6. * UI controller.
  7. */
  8. class TripalDataTypeUIController 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('/_type/', '', $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 type',
  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. /**
  50. * Access callback for the entity API.
  51. */
  52. function tripal_data_type_access($op, $type = NULL, $account = NULL) {
  53. return user_access('administer tripal data types', $account);
  54. }
  55. /**
  56. * Generates the tripal data type editing form.
  57. */
  58. function tripal_data_type_form($form, &$form_state, $tripal_data_type, $op = 'edit') {
  59. if ($op == 'clone') {
  60. $tripal_data_type->label .= ' (cloned)';
  61. $tripal_data_type->type = '';
  62. }
  63. $form['label'] = array(
  64. '#title' => t('Label'),
  65. '#type' => 'textfield',
  66. '#default_value' => $tripal_data_type->label,
  67. '#description' => t('The human-readable name of this tripal data type.'),
  68. '#required' => TRUE,
  69. '#size' => 30,
  70. );
  71. return $form;
  72. }
  73. /**
  74. * Form API submit callback for the type form.
  75. */
  76. function tripal_data_type_form_submit(&$form, &$form_state) {
  77. $tripal_data_type = entity_ui_form_submit_build_entity($form, $form_state);
  78. $tripal_data_type->save();
  79. $form_state['redirect'] = 'admin/structure/bio_data_types';
  80. }
  81. /**
  82. * Form API submit callback for the delete button.
  83. */
  84. function tripal_data_type_form_submit_delete(&$form, &$form_state) {
  85. $form_state['redirect'] = 'admin/structure/bio_data_types/manage/' . $form_state['tripal_data_type']->type . '/delete';
  86. }