diff --git a/profile2.module b/profile2.module index 71a5230..1548656 100644 --- a/profile2.module +++ b/profile2.module @@ -155,6 +155,8 @@ function profile2_menu() { $items['user/%user/edit/%profile2_menu'] = array( 'load arguments' => array('%map', 'edit'), 'title' => 'Edit profile', + 'title callback' => 'profile2_menu_title_profile', + 'title arguments' => array(3), 'access callback' => 'profile2_profile_edit_access', 'access arguments' => array(3), 'page callback' => 'profile2_profile_edit', @@ -168,7 +170,7 @@ function profile2_menu() { 'access arguments' => array('delete', 3), 'page callback' => 'drupal_get_form', 'page arguments' => array('profile2_delete_confirm_form', 3), - 'type' => MENU_CALLBACK, + 'type' => MENU_VISIBLE_IN_BREADCRUMB, 'file' => 'profile2.pages.inc', ); return $items; @@ -208,6 +210,19 @@ function profile2_menu_load($type_id, $map, $op = '') { } /** + * Menu title callback for a profile edit link. + * + * @param Drupal\profile2\Profile $profile + * The profile to return a title for. + * + * @return string + * The unsanitized profile label. + */ +function profile2_menu_title_profile(Profile $profile) { + return $profile->label(); +} + +/** * Implements hook_menu_local_tasks_alter(). */ function profile2_menu_local_tasks_alter(&$data, $router_item, $root_path) { diff --git a/profile2.pages.inc b/profile2.pages.inc index 96aaba8..2b0dd06 100644 --- a/profile2.pages.inc +++ b/profile2.pages.inc @@ -8,24 +8,55 @@ use Drupal\profile2\Profile; /** - * Confirmation form for deleting a profile. + * Form constructor to confirm deletion of a profile. + * + * @param Drupal\profile2\Profile $profile + * The profile to delete. + * + * @return array + * A form render array suitable for drupal_render(). + * + * @see profile2_delete_confirm_form_submit() */ -function profile2_delete_confirm_form($form, $form_state, Profile $profile) { +function profile2_delete_confirm_form(array $form, array &$form_state, Profile $profile) { $form_state['profile'] = $profile; - // @todo Work out a good confirmation question. - $confirm_question = t('Are you sure you want to delete %label?', array('%label' => $profile->label())); - return confirm_form($form, $confirm_question, $profile->uri()); + $form_state['account'] = entity_load('user', $profile->uid); + $form['pid'] = array('#type' => 'value', '#value' => $profile->id()); + + if ($GLOBALS['user']->uid == $profile->uid) { + $confirm_question = t('Are you sure you want to delete your %label profile?', array( + '%label' => $profile->label(), + )); + } + else { + $confirm_question = t("Are you sure you want to delete %name's %label profile?", array( + '%name' => user_format_name($form_state['account']), + '%label' => $profile->label(), + )); + } + return confirm_form($form, $confirm_question, $profile->uri(), NULL, t('Delete')); } /** - * Submit handler for deleting a profile. + * Form submission handler for profile2_delete_confirm_form(). */ function profile2_delete_confirm_form_submit(array $form, array &$form_state) { $form_state['profile']->delete(); - // @todo Work out a good deletion message. - drupal_set_message(t('Deleted %label.', array('%label' => $form_state['profile']->label()))); + + if ($GLOBALS['user']->uid == $form_state['profile']->uid) { + $message = t('Your %label profile has been deleted.', array( + '%label' => $form_state['profile']->label(), + )); + } + else { + $message = t("%name's %label profile has been deleted.", array( + '%name' => user_format_name($form_state['account']), + '%label' => $form_state['profile']->label(), + )); + } + drupal_set_message($message); // Redirect to the user page. - $uri = entity_load('user', $form_state['profile']->uid)->uri(); - $form_state['redirect'] = $uri['path']; + $uri = $form_state['account']->uri(); + $form_state['redirect'] = array($uri['path'], $uri['options']); }