ChadoDataTypeUIController.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @file
  4. */
  5. /**
  6. * UI controller.
  7. */
  8. class ChadoDataTypeUIController extends EntityDefaultUIController {
  9. /**
  10. * Overrides hook_menu() defaults.
  11. */
  12. public function hook_menu() {
  13. $items = parent::hook_menu();
  14. $items[$this->path]['description'] = 'Manage Chado data types, including adding
  15. and removing fields and the display of fields.';
  16. // We don't want to let the user add new Chado data types. They
  17. // are added automatically.
  18. unset($items[$this->path . '/add']);
  19. unset($items[$this->path . '/import']);
  20. return $items;
  21. }
  22. }
  23. /**
  24. * Access callback for the entity API.
  25. */
  26. function chado_data_type_access($op, $type = NULL, $account = NULL) {
  27. return user_access('administer chado data types', $account);
  28. }
  29. /**
  30. * Generates the chado data type editing form.
  31. */
  32. function chado_data_type_form($form, &$form_state, $chado_data_type, $op = 'edit') {
  33. if ($op == 'clone') {
  34. $chado_data_type->label .= ' (cloned)';
  35. $chado_data_type->type = '';
  36. }
  37. $form['label'] = array(
  38. '#title' => t('Label'),
  39. '#type' => 'textfield',
  40. '#default_value' => $chado_data_type->label,
  41. '#description' => t('The human-readable name of this chado data type.'),
  42. '#required' => TRUE,
  43. '#size' => 30,
  44. );
  45. // Machine-readable type name.
  46. $form['type'] = array(
  47. '#type' => 'machine_name',
  48. '#default_value' => isset($chado_data_type->type) ? $chado_data_type->type : '',
  49. '#maxlength' => 32,
  50. // '#disabled' => $chado_data_type->isLocked() && $op != 'clone',
  51. '#machine_name' => array(
  52. 'exists' => 'chado_data_get_types',
  53. 'source' => array('label'),
  54. ),
  55. '#description' => t('A unique machine-readable name for this chado data type. It must only contain lowercase letters, numbers, and underscores.'),
  56. );
  57. $form['data']['#tree'] = TRUE;
  58. $form['data']['sample_data'] = array(
  59. '#type' => 'checkbox',
  60. '#title' => t('An interesting chado data switch'),
  61. '#default_value' => !empty($chado_data_type->data['sample_data']),
  62. );
  63. $form['actions'] = array('#type' => 'actions');
  64. $form['actions']['submit'] = array(
  65. '#type' => 'submit',
  66. '#value' => t('Save chado data type'),
  67. '#weight' => 40,
  68. );
  69. //Locking not supported yet
  70. /*if (!$chado_data_type->isLocked() && $op != 'add') {
  71. $form['actions']['delete'] = array(
  72. '#type' => 'submit',
  73. '#value' => t('Delete chado data type'),
  74. '#weight' => 45,
  75. '#limit_validation_errors' => array(),
  76. '#submit' => array('chado_data_type_form_submit_delete')
  77. );
  78. }*/
  79. return $form;
  80. }
  81. /**
  82. * Form API submit callback for the type form.
  83. */
  84. function chado_data_type_form_submit(&$form, &$form_state) {
  85. $chado_data_type = entity_ui_form_submit_build_entity($form, $form_state);
  86. $chado_data_type->save();
  87. $form_state['redirect'] = 'admin/structure/chado_data_types';
  88. }
  89. /**
  90. * Form API submit callback for the delete button.
  91. */
  92. function chado_data_type_form_submit_delete(&$form, &$form_state) {
  93. $form_state['redirect'] = 'admin/structure/chado_data_types/manage/' . $form_state['chado_data_type']->type . '/delete';
  94. }
  95. /**
  96. * Menu argument loader; Load a model type by string.
  97. *
  98. * @param $type
  99. * The machine-readable name of a model type to load.
  100. * @return
  101. * A model type array or FALSE if $type does not exist.
  102. */
  103. function chado_data_type_load($type) {
  104. return chado_data_get_types($type);
  105. }