Social Networks and Extending the User Profile in Drupal: Part-2

0
77
7 min read

Building the Profile

The Content Profile module creates a new content type called Profile when it is enabled. By default, this content type is set to be used as a profile. We need to complete a few additional steps to make our profile fully functional.

  1. Edit the default settings for the Profile content type
  2. Configure the base Content Profile settings
  3. Add any required fields to the Profile content type
  4. Add any taxonomy terms to the Profile content type
  5. Assign rights to create and edit the Profile content type

Edit the Settings of the Profile Content Type

As mentioned above, when the Content Profile module is enabled, it creates a new content type named Profile. To use this new node type effectively, we need to change the default settings.

To do this, click on the Administer | Site building | Content types link, or navigate to admin/content/types. Click the Edit link for the Profile content type.

The Automatic Nodetitles module—enabled earlier in the first part of  this article—adds a new fieldset labeled Automatic title generation at the top of the administrative screens where we edit content types.

Social Networks and Extending the User Profile in Drupal

As shown in the preceding screenshot, we have two options. For the first option, we want to select Automatically generate the title and hide the title field.

For the second option—Pattern for the title—we should enter [author-name]’s profile. [author-name] is a token; when the node is created, the token will be replaced by the username of the person creating the node. So, if a user named Jill created the profile node, the title would be Jill’s profile.

The Token module allows us to use a wide range of tokens in addition to [author-name]. To see the full list of available tokens, expand the Replacement patterns fieldset as indicated in the preceding screenshot by Item 1.

The settings listed here also need to be adjusted:

  • In the Submission form settings section, delete the Body field label. We do not want this node type to have a body field; we will add all needed fields using CCK
  • In the Workflow settings section, set the Default options to Published, and Attachments to Disabled
  • In the Comment settings section, set the Default comment settings to Disabled

After you have made the necessary adjustments, click the Save content type button to submit the form and save your changes.

Configure the Base Content Profile Settings

To configure the base Content Profile settings, click on the Administer  Site building | Content types link, or navigate to admin/content/types. Click the Edit link for the Profile content type. Then, click the Content Profile tab.

Social Networks and Extending the User Profile in Drupal

The base settings allow us to configure how the node profile will be displayed on the user profile page. As shown in the preceding screenshot, in the User page display style section we have four options:

  • Don’t display this content profile on the user account page—only select this option if you will be overriding the core user profile page via the theming layer. This is an advanced theming technique; refer to the handbook page on overriding user profiles at http://drupal.org/node/35728.
  • Display it as link to the profile content—select this option if you only want to link to the full profile node from the user profile page.
  • Display the full content—this option displays the full node on the user profile page.
  • Display the content’s teaser—this option displays the teaser view on the profile page. As discussed later in this section, this option provides us some flexibility not found in the other options. For our example, choose this option.

The final two options—Include an edit link to the display and Show a link to the content profile creation page, if there is no profile—should both be selected, as they improve usability.

The Weight can be left at 0.

When these settings have been adjusted as needed, click the Submit button to save the changes.

Add Fields to the Profile Content Type

Now that we have edited the defaults of the Profile node type, and adjusted the base settings of the Content Profile, we are ready to add fields and taxonomy terms to our profile. The CCK fields and Taxonomies will provide structure to our user profiles.

For this example, we want to extend our profile by adding two fields, and one vocabulary.

The fields we will add will both be text fields; one for a Brief bio, and the second for a Full bio.

We will also add a Vocabulary to the Profile content type called Interests. Adding this vocabulary is covered in the next section of this article.

Add the Brief Bio Field

To add the text fields, go to the Content Types administration page by clicking the Administer | Content Management | Content Types link, or by navigating to admin/content/types. Click the manage fields link for the profile content type.

In the Add section, we want to add a New field. Enter the following values:

  • Label: Brief bio
  • Field name: brief_bio
  • Field type: text
  • Widget type: text area (multiple rows)

Click the Save button; this brings up the admin screen where you can configure the field.

Social Networks and Extending the User Profile in Drupal

As shown in the preceding screenshot, the form to configure the text field has two sections: Profile settings and Global settings.

Adjusting the Profile Settings

In the Profile settings, we have two options; enter the values specified below:

  • Rows: 3
  • Help text: Enter your brief bio. 500 characters maximum

For this example, we do not need to set any Default value.

Adjusting the Global Settings

In the Global settings, we have four options; enter the values specified below:

  • Required: No; leave unchecked
  • Number of values: 1
  • Text processing: Plain text
  • Maximum length: 500

For this example, we do not need to set any Allowed values.

Once the field has been configured as needed, click the Save field settings button to save your changes.

Adding the Full Bio Field

Adding the Full Bio is nearly identical to adding the Brief bio. When adding the field, use the following values:

  • Label: Full bio
  • Field name: full_bio
  • Field type: text
  • Widget type: text area (multiple rows)

Click the Save button; this brings up the admin screen where you can configure the field.

In the Profile settings, enter:

  • Rows: 5
  • Help text: Enter your full, extended biography.

In the Global settings, we enter:

  • Required: No; leave unchecked
  • Number of values: 1
  • Text processing: Filtered text (user selects input format)
  • Maximum length: none, leave blank

Once the field has been configured as needed, click the Save field settings button to save your changes.

Adjusting the Field Display

As we discussed above when we configured the base options for Content Profiles, we want to show the node teaser on the user profile page. To take advantage of this option, we need to configure how we display our fields. To do this, go to the Content Types administration page by clicking the Administer | Content Management | Content Types link, or by navigating to admin/content/types. Click the edit link for the profile content type, and then, click the Display fields tab.

Social Networks and Extending the User Profile in Drupal

As seen in the preceding screenshot, you can control how fields are displayed in the Teaser view and in the Full node view.

In the settings shown in the preceding screenshot, we have set the Brief bio to show on the Teaser view (that is, on the user profile page), and the Full bio to display on the Full node view (that is, when the entire profile is being viewed). Our settings display a truncated overview on the user profile page, with a link to the more detailed full node view.

Add Taxonomy Terms to the Profile Content Type

As described above, we want to add an Interests vocabulary.

To add new vocabularies, click on the Administer | Content management | Taxonomy| link, or navigate to admin/content/taxonomy. Click the Add vocabulary tab.

Adding the Interest Vocabulary

For Interests, enter the following values:

  • Vocabulary name: Interests
  • Description: none, leave blank
  • Help text: Describe your interests. Separate each interest with a comma
  • Content types: select Profile; leave others unchecked
  • Settings: select Tags; leave others unchecked
  • Weight: -6

Click the Save button to create the new vocabulary.

Assign Rights to Profile Nodes

Click on the Administer  User Management | Roles| link, or navigate to admin/user/roles. Select the role(s) that you would like to be able to create node-based profiles. Generally, users should be given the rights to create profile content, and edit own profile content. This will allow users to create their own profiles, and update them as needed, but also protects users from accidentally deleting their profile.

Only site administrators or especially trusted users should be given the rights to edit any profile content or delete any profile content.

LEAVE A REPLY

Please enter your comment!
Please enter your name here