profile2.admin.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @file
  4. * Profile type editing UI.
  5. */
  6. /**
  7. * UI controller.
  8. */
  9. class Profile2TypeUIController extends EntityDefaultUIController {
  10. /**
  11. * Overrides hook_menu() defaults.
  12. */
  13. public function hook_menu() {
  14. $items = parent::hook_menu();
  15. $items[$this->path]['description'] = 'Manage profiles, including fields.';
  16. return $items;
  17. }
  18. }
  19. /**
  20. * Generates the profile type editing form.
  21. */
  22. function profile2_type_form($form, &$form_state, $profile_type, $op = 'edit') {
  23. if ($op == 'clone') {
  24. $profile_type->label .= ' (cloned)';
  25. $profile_type->type = '';
  26. }
  27. $form['label'] = array(
  28. '#title' => t('Label'),
  29. '#type' => 'textfield',
  30. '#default_value' => $profile_type->label,
  31. '#description' => t('The human-readable name of this profile type.'),
  32. '#required' => TRUE,
  33. '#size' => 30,
  34. );
  35. // Machine-readable type name.
  36. $form['type'] = array(
  37. '#type' => 'machine_name',
  38. '#default_value' => isset($profile_type->type) ? $profile_type->type : '',
  39. '#maxlength' => 32,
  40. '#disabled' => $profile_type->isLocked() && $op != 'clone',
  41. '#machine_name' => array(
  42. 'exists' => 'profile2_get_types',
  43. 'source' => array('label'),
  44. ),
  45. '#description' => t('A unique machine-readable name for this profile type. It must only contain lowercase letters, numbers, and underscores.'),
  46. );
  47. $form['data']['#tree'] = TRUE;
  48. $form['data']['registration'] = array(
  49. '#type' => 'checkbox',
  50. '#title' => t('Show during user account registration.'),
  51. '#default_value' => !empty($profile_type->data['registration']),
  52. );
  53. $form['actions'] = array('#type' => 'actions');
  54. $form['actions']['submit'] = array(
  55. '#type' => 'submit',
  56. '#value' => t('Save profile type'),
  57. '#weight' => 40,
  58. );
  59. $form['weight'] = array(
  60. '#type' => 'weight',
  61. '#title' => t('Weight'),
  62. '#default_value' => $profile_type->weight,
  63. '#description' => t('When showing profiles, those with lighter (smaller) weights get listed before profiles with heavier (larger) weights.'),
  64. '#weight' => 10,
  65. );
  66. if (!$profile_type->isLocked() && $op != 'add' && $op != 'clone') {
  67. $form['actions']['delete'] = array(
  68. '#type' => 'submit',
  69. '#value' => t('Delete profile type'),
  70. '#weight' => 45,
  71. '#limit_validation_errors' => array(),
  72. '#submit' => array('profile2_type_form_submit_delete')
  73. );
  74. }
  75. return $form;
  76. }
  77. /**
  78. * Form API submit callback for the type form.
  79. */
  80. function profile2_type_form_submit(&$form, &$form_state) {
  81. $profile_type = entity_ui_form_submit_build_entity($form, $form_state);
  82. // Save and go back.
  83. $profile_type->save();
  84. $form_state['redirect'] = 'admin/structure/profiles';
  85. }
  86. /**
  87. * Form API submit callback for the delete button.
  88. */
  89. function profile2_type_form_submit_delete(&$form, &$form_state) {
  90. $form_state['redirect'] = 'admin/structure/profiles/manage/' . $form_state['profile2_type']->type . '/delete';
  91. }