Index: profile2.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/profile2/Attic/profile2.install,v retrieving revision 1.1.2.12 diff -u -p -r1.1.2.12 profile2.install --- profile2.install 21 Sep 2010 11:00:27 -0000 1.1.2.12 +++ profile2.install 16 Oct 2010 19:13:05 -0000 @@ -10,34 +10,57 @@ * Implements hook_install(). */ function profile2_install() { - // Auto-create a field for the full name, if it doesn't exist yet. - if (!field_info_field('profile_fullname')) { - $field = array( - 'field_name' => 'profile_fullname', - 'type' => 'text', - 'cardinality' => 1, - 'translatable' => FALSE, - ); - field_create_field($field); - } - $instance = array( - 'entity_type' => 'profile', - 'field_name' => 'profile_fullname', - 'bundle' => 'main', - 'label' => 'Full name', - 'description' => 'Specify your first and last name.', - 'widget' => array( - 'type' => 'text_textfield', - 'weight' => 0, - ), + // Create and save a main profile type + $main_profile_type = new ProfileType(array( + 'type' => 'main', + 'label' => t('Profile'), + 'weight' => 0, + )); + $main_profile_type->save(); + + // Grant the authenticated user permissions to view/edit own instance + // of this newly added profile type + // Authenticated user role is locked so hardwire this role ID + user_role_grant_permissions( + DRUPAL_AUTHENTICATED_RID, array('edit own main profile', 'view own main profile') ); - field_create_instance($instance); + + // Report the new profile to the user and offer options to + // manage permissions and fields + drupal_set_message(t( + "A default profile type 'Profile' has been created and basic permissions have been assigned. You can now !add_fields or !manage_perms.", + array( + '!add_fields' => l('add fields to this type', 'admin/structure/profiles/manage/' . $main_profile_type->type . '/fields'), + '!manage_perms' => l('manage permissions for it', 'admin/people/permissions', array('fragment' => 'module-profile2')), + ) + )); } /** * Implements hook_uninstall(). */ function profile2_uninstall() { + // Delete any existing profile types and their field instances explicitly + $sql = "SELECT pt.type FROM {profile_type} pt"; + $result = db_query($sql); + foreach($result as $row) { + // Delete field instances attached to this profile type + $instances = field_info_instances('profile_type', $row->type); + foreach($instances as $instance_name => $instance) { + field_delete_instances($instance); + } + + // Delete the profile type itself + $profile_type = new ProfileType(array( + 'type' => $row->type, + )); + $profile_type->delete(); + + // And purge all unlinked field information + field_purge_batch(1000); + } + + // Delete any system variables variable_del('profile_register'); } Index: profile2.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/profile2/Attic/profile2.module,v retrieving revision 1.1.2.42 diff -u -p -r1.1.2.42 profile2.module --- profile2.module 5 Oct 2010 15:45:05 -0000 1.1.2.42 +++ profile2.module 16 Oct 2010 19:13:05 -0000 @@ -640,18 +640,6 @@ class ProfileType extends EntityDB { } /** - * Implements hook_default_profile_type(). - */ -function profile2_default_profile_type() { - $types['main'] = new ProfileType(array( - 'type' => 'main', - 'label' => t('Profile'), - 'weight' => 0, - )); - return $types; -} - -/** * Implements hook_form_FORMID_alter(). * * Adds a checkbox for controlling field view access to fields added to