Commit fcf55cd2 authored by Rick Jones's avatar Rick Jones
Browse files

Issue #3040978 by junaidpv, RickJ: Only modify view link if profile is in use-tab mode

parent c47987eb
Loading
Loading
Loading
Loading
+19 −1
Changes for contrib/profile2_page.module: 19 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -139,6 +139,10 @@ function profile2_page_menu() {
 */
function profile2_page_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  if (strpos($root_path, 'user/%/') === 0 && isset($router_item['original_map'][3])) {
    $ptype = $router_item['original_map'][3];
    $profile = profile2_type_load($ptype);
    // Only do this if the current profile is in use-tab mode.
    if (!empty($profile->data['use_tab'])) {
      switch ($router_item['original_map'][2]) {
        case 'view':
          $href_suff = '/edit';
@@ -155,7 +159,6 @@ function profile2_page_menu_local_tasks_alter(&$data, $router_item, $root_path)
      }
      // Get the uid & profile type name.
      $uid = $router_item['original_map'][1];
    $ptype = $router_item['original_map'][3];

      if (profile2_access($access, profile2_by_uid_load($uid, $ptype))) {
        // Get the part of the link URL containing "user/<uid>".
@@ -170,6 +173,7 @@ function profile2_page_menu_local_tasks_alter(&$data, $router_item, $root_path)
      }
    }
  }
}

/**
 * Returns the base path to use as profile page.
@@ -252,6 +256,9 @@ function profile2_page_uri_callback($profile) {
  if (!empty($type->data['use_page'])) {
    return array('path' => profile2_page_get_base_path($type) . '/' . $profile->uid);
  }
  else if (!empty($type->data['use_tab'])) {
    return array('path' => "user/{$profile->uid}/view/{$profile->type}");
  }
  // Fall back to the default callback.
  return $profile->defaultUri();
}
@@ -293,6 +300,17 @@ function profile2_page_form_profile2_type_form_alter(&$form, &$form_state) {
      ),
    ),
  );
  $form['data']['edit_label'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow the profile title to be edited.'),
    '#description' => t('If enabled, the title of the profile is editable, and is used as-is when displaying the profile.'),
    '#default_value' => empty($type->is_new) && !empty($type->data['edit_label']),
    '#states' => array(
      'invisible' => array(
       ':input[name="data[use_page]"]' => array('checked' => FALSE),
      ),
    ),
  );
  $form['data']['use_tab'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide a separate tab for viewing profiles.'),