Exercise 8.7: Set up profile fields
Last updated
Last updated
Previously, you added fields to content types. You can also add fields to user profiles. This means you can let users share information about themselves and then you can display it. You can also control permissions so only trusted users can see profiles. Below you can see the profiles will have a text field for description and also a list of interests and a profile picture.
Go to Configuration → People → Account settings → Manage fields.
This interface is similar to the one for adding fields to content, now you can Add a new field with the following settings:
Type: Text → Text (plain, long)
Label: About me
Machine Name: field_about_me
Go to the Manage form display tab and set the Widget for About me to: Text area (multiple rows).
Review the User settings. We will keep all the default settings, however, review the options before you save.
Click Save settings.
We need to create a new “Interests” vocabulary we can use in this case.
Go to Structure → Taxonomy → Add vocabulary.
Name: Interests
Save the vocabulary
At this stage we can decide not to add any terms to the vocabulary, rather rely on users to add them when they create or update their profile.
Go back to Configuration → People → Account settings → Manage fields.
Add a new field:
Type: Reference → Taxonomy term
Label: Interests
Allowed number of values: Unlimited
Create referenced entities if they don't already exist: Yes
Vocabulary: Interests
Widget: Select Autocomplete (Tags style). This can be configured after you add the field, from the Manage form display tab.
Save settings.
Return to the front page.
Click Your username in the top administration menu, then View profile, then the Edit profile tab.
At the bottom of the form you can see the options available.
Fill in some text for About me and type in tags (comma-separated for multiple tags) for Interests, such as Jogging, Sailing, Drupal.
Under Picture, upload an image if you haven't already.
Save.
Click the View tab and now you can view the admin profile.
You can also manage the display of the fields, for example hiding the label. As your Drupal skills improve, you can make changes to the site design through Theming to alter the way this information looks; or change what displays through Manage display configuration pages.