Hello!

Using Entity View Modes, I have added a new view mode for my user accounts called "User name" which aims to display just the user's first and last name, using fields located in their main profile. I have also added the same view mode in the Main Profile.

The user account's "Manage Display", under the "User Name" view mode is configured to show just the Main Profile field. But the only options for that field are "Visible" or '"Hidden". There is no place to pick in which view mode the profile should be shown. So the Main Profile is always shown using the default view mode.

See the attached screen capture...

Should there be a cog icon allowing to select the view mode for this field? (See second screen capture)

Cheers

Comments

mastoll’s picture

I have exactly the same question - how do you select the view mode in which the user profile should be displayed? I thought it was a Display Suites question, since I use DS. Someone else has asked an analogous question in the Panels issue cue - and received no response. Perhaps it's not Panels or Display Suites or Profile 2, but core-related? Is that what is responsible for user profile management?

guillaumev’s picture

StatusFileSize
new517 bytes

Hi,

The attached patch is a step in the right direction: it still won't allow you to select a specific view mode, but it will at least display the profile2 field in the same view mode as the user view mode (so let's say if you display your user account in a "teaser" view mode, profile2 will be displayed using this same "teaser" view mode)

bohemier’s picture

Thanks Guillaume! It looks good...

R.Hendel’s picture

Thanks a lot, Guillaume.
It works fine for me also...

nicstar’s picture

I know I am late to the party, but I wanted to share something that worked for me. I am using display suite and profile2. I had a specific DS view mode on my profile that I wanted to use in my user page. I used hook _entity_view_mode_alter() to force the view mode.

function MYMODULE_entity_view_mode_alter(&$view_mode, $context) {
  if ($context['entity_type'] == 'profile2'){
    $view_mode = 'MY_VIEW_MODE';
  }
}

Hope this helps someone.

bmango’s picture

@nicstar, thank you so much for your snippet. I was trying to work out how I could have different views modes for different roles viewing the same profile and was not having any success. I was just about to switch over to using panels when I found your code. Many thanks again.

Coyote6GraphX’s picture

StatusFileSize
new544 bytes

Life saver.... I don't know why this hasn't been committed yet to the main version. I updated the patch for version 1.5 so it would have the correct line numbers. Thanks!

Coyote6GraphX’s picture

Status: Active » Needs review
Related issues: +#2545862: Hardcoded $view_mode in profile2_user_view()

Marking as needs review and attached a related issue.

The last submitted patch, 2: 2148375-view_mode-2.patch, failed testing. View results

rickj’s picture

Assigned: Unassigned » rickj
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new540 bytes

Good fix, I was unaware of this issue. Patch #8 didn't apply to dev build due to line number changes, new patch here.

Note that the system displays the standard user account page using view mode 'account', this can't be changed, but you can use other view modes when displaying accounts from e.g. views, etc. If a view mode is not defined the display will fall back to the default mode.

  • RickJ committed 43c0306 on 7.x-1.x
    Issue #2148375 by Coyote6GraphX, RickJ, guillaumev: Displaying a profile...
rickj’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rickj’s picture

Assigned: rickj » Unassigned