profile2.admin.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. if (!$profile_type->isLocked() && $op != 'add' && $op != 'clone') {
  60. $form['actions']['delete'] = array(
  61. '#type' => 'submit',
  62. '#value' => t('Delete profile type'),
  63. '#weight' => 45,
  64. '#limit_validation_errors' => array(),
  65. '#submit' => array('profile2_type_form_submit_delete')
  66. );
  67. }
  68. return $form;
  69. }
  70. /**
  71. * Form API submit callback for the type form.
  72. */
  73. function profile2_type_form_submit(&$form, &$form_state) {
  74. $profile_type = entity_ui_form_submit_build_entity($form, $form_state);
  75. // Save and go back.
  76. $profile_type->save();
  77. $form_state['redirect'] = 'admin/structure/profiles';
  78. }
  79. /**
  80. * Form API submit callback for the delete button.
  81. */
  82. function profile2_type_form_submit_delete(&$form, &$form_state) {
  83. $form_state['redirect'] = 'admin/structure/profiles/manage/' . $form_state['profile2_type']->type . '/delete';
  84. }