Hi there,

For project specific regions I needed to display a view of users which naturally have their profiles attached. Because of the nature of this view listing page, I was looking to have a sort of user teaser view mode active so I wouldn't get the full profile. Unfortunately even if I created a teaser view mode for users the full profile would still come through because there is no relationship there. I'm submitting a feature request to have profile entities inherit the view modes of their users. This addition will still allow profiles to be displayed on their own but will give admins much greater control on the display of user entities also (with profiles).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

smithmilner’s picture

This is still a ways from complete but it works!

smithmilner’s picture

I've found that view modes can be missing depending on profile2's order in the hook_entity_info_alter(). This is stab in the dark to try and get a final result on the user entity.

smithmilner’s picture

hello?

fago’s picture

Status: Active » Needs work

Sounds good to me, the hack in the entity-info-alter hook is very ugly though. I think just inheriting the view-modes that are available during alter should do it - if someone adds one in after us, he can do it for profile2 too.

smithmilner’s picture

Ok, we'll go back to the first version of the patch to avoid ugly hackyness. Another small issue here is that users have a view mode called "full" which for all purposes is identical to profile2's view mode "account". After the profile2 inherits user view modes we end up with a duplicated view mode as seen in the second screenshot. I think it would be ideal to change the machine name of profile2's view mode to be "full" so it's inline with users. I haven't thought about what sort of implications that might have, what do you think?

user view modes: https://skitch.com/smithmilner/gc9au/welcome-to-participedia-participedia

profile2 view modes(after patch): https://skitch.com/smithmilner/gc9ab/welcome-to-participedia-participedia

langworthy’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, profiles_inherit_user_viewmodes-1218232-2.patch, failed testing.

smithmilner’s picture

Status: Needs work » Needs review
FileSize
1.13 KB

aha, editor renamed it to .txt. Let's try this again...

Status: Needs review » Needs work

The last submitted patch, profiles_inherit_user_viewmodes-1218232-8.patch, failed testing.

smithmilner’s picture

Status: Needs work » Needs review
FileSize
966 bytes

Rerolled against dev.

kevinquillen’s picture

That patch worked for me! Went in circles for two hours on this.

fago’s picture

Status: Needs review » Needs work
+++ b/profile2.module
@@ -93,6 +93,17 @@ function profile2_entity_info() {
+ * profile2 entity inherits view modes from users

Should start capitalized and end with a point, in short it should be a full sentence.

+++ b/profile2.module
@@ -356,7 +367,7 @@ function profile2_user_view($account, $view_mode, $langcode) {
-        $account->content['profile_' . $type]['view'] = $profile->view('account');
+        $account->content['profile_' . $type]['view'] = $profile->view($view_mode);

This is changes the view-mode which is used by default, which might break people's settings.

Thus, we cannot change the default view-mode. Maybe just go with 'account' for view mode "full" and pass through others.

mpgeek’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.34 KB

Here is another version with a more general approach that takes into account the fact that default view mode for profile2 is account that is associated with the full view mode for user, as pointed out in #12. A more general approach would likely be to implement view modes along the lines of the way entity reference provides display mode configuration when attaching to another entity.

Sophie.SK’s picture

Applied the patch and it seems to be working for me - thanks! :)

RickJ’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#2148375: Displaying a profile with a specific view mode

Closed as duplicate of #2148375: Displaying a profile with a specific view mode. The actual code fix is a one-liner, there is no need to map 'full' to 'account'.

If a view mode doesn't exist the display falls back to the default. The system displays the regular user account page using view mode 'account', but there is no need to preclude adding 'full' as another view mode for other purposes.