The profile label is by default the same as the profile type label, however it's possible to customize the profile label via custom code or Rules.

To specify a pattern for the profile label generation using Rules, the following steps are necessary.

  1. Be sure to have a Profile2 version from 04.01.2012 or later running (e.g. >= version 1.2) and to have the Rules module enabled.
  2. Create a suitable rule, which updates the profile label on event "Before saving a profile". Alternatively, just import the following example rule:
  3. { "rules_generate_a_profile_label" : {
        "LABEL" : "Generate a profile label",
        "PLUGIN" : "reaction rule",
        "TAGS" : [ "profile2" ],
        "REQUIRES" : [ "rules", "profile2" ],
        "ON" : [ "profile2_presave" ],
        "IF" : [ { "data_is" : { "data" : [ "profile2:type" ], "value" : "main" } } ],
        "DO" : [
          { "data_set" : {
              "data" : [ "profile2:label" ],
              "value" : "[profile2:user:name]\u0027s [profile2:type:label]"
            }
          }
        ]
      }
    }

    If you are using the provided rule, make sure it's activated for your profile type by editing the condition and customize the user pattern by editing the action.

That's it. Once you have edited a profile using the profile pages module, you'll notice the new profile labels appearing in the page title(s). But take note, profile labels are only updated when a profile is saved, i.e. created or updated.

Comments

parasox’s picture

What are profile labels for? Does this basically auto-generate a title for users so they don't have to keep thinking up something to say in it? I guess I'm not sure what the use of this is, or why it's important. New to D7 and profile2.

Patroclas’s picture

You are nearly correct

When Profile2 is set to show a profile type as a separate page, the user does not have the option to set a title - by default it uses the profile-type label - which is not very user-friendly. This post tells you how to change that. Just remember that if you import the exammple rule, you still need to edit it to read your profile type and to set the tokens for the page title.

fago has done a great job in providing this - it's really easy to set up - thanks!

Barto.G’s picture

From this exemple i've put together a rule to generate a path alias for each user profile (after creation) :

{ "rules_profile_path_alias" : {
    "LABEL" : "Set profile2 path alias",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "path", "profile2" ],
    "ON" : [ "profile2_insert" ],
    "DO" : [
      { "path_alias" : {
          "source" : "profile-main\u002F[profile2:user:uid]",
          "alias" : "profile\u002F[profile2:user:name]"
        }
      }
    ]
  }
}

My profile machine name is "main" so URLs are mysite/profile-main/1 (site/profile-[machine-name]/[uid]) so under "Create or delete any URL alias" ajust the first part of the path to match yours

bisonbleu’s picture

Unfortunately, this Rule only works for one language on a multilingual setup when profiles are displayed on separate pages.

  • In my case, French is the default language, the other language is English. So in the French UI Rules does its job nicely i.e. changing the default label to [profile2:field-member-first-name] [profile2:field-member-last-name]. But when I switch to the English UI, I still see the default label Member Profile.

Is this a Rules problem or a Profile2 problem?
Anyone has a solution for this use case?

:~: Senior Drupal Site Builder