6. Drupal Fields Explained

In Chapter 5, “Drupal Content Explained,” we explored content types, and you created Articles, Basic Pages, Events, Sites, User Groups, Companies, and more.

The limitation we found at the end of Chapter 5 is that there were few or no differences between those content types.

This chapter shows you how to make your content types unique, interesting, and useful by adding fields.

In this chapter, you’ll use many different types of fields. To use all those different types of fields, you also expand your skills by downloading modules from Drupal.org.

At the end of this chapter, you should be able to

Image Add different types of fields to a content type.

Image Share a field across multiple content types.

Image Manage the display of fields in the full content view and teaser.

Image Understand Taxonomy and how Drupal categorizes content.

Image Download and install modules from Drupal.org.

Planning Your Fields

Fields provide almost unlimited possibilities for adding information to your content. Here are just a few of the many possibilities:

Image Text

Image Whole numbers

Image Decimal numbers

Image Images

Image Files such as PDFs and Microsoft Word documents

Image A pre-defined list of options

Image Addresses

Image Phone numbers

Image Dates and times

However, not all of these field types are available with a new Drupal site.

In Chapter 5, we saw that there are six default content types in Drupal. In this chapter, we will see that there are 13 default field types. All other field types must be added to your site by installing new modules.

We currently have four content types from Chapter 5 that need to be made more interesting. Those content types are Drupal Sites, Events, Companies, and User Groups. To be more useful, they need more information. They need fields.

Table 6.1 describes the fields we’ll use for each content type. Sometimes, we’ll use one of the existing field types. Other times we’ll set up new field types.

Table 6.1. Our Plan for Adding Fields to Content Types

Image

Sites Fields Explained

The Site content type has five fields planned. Four will be created using fields that come with default Drupal. The Link field needs to be added to the site, requiring you to add a module from Drupal.org.

Here’s what you’re going to do:

Image Edit field labels for title and body.

Image Add four fields that come with Drupal.

First, you need to set up the two fields that come with every content type: Title and Body.

Editing a Field: Title

When you created the Sites content type in Chapter 5, we suggested that you change the Title field to Site Name. Now make sure that was done:

1. Click Structure on the black menu bar.

2. Click Content Types.

3. Click Edit for the Sites content type, as shown in Figure 6.1.

Image

Figure 6.1. Edit link for the Sites content type

4. Scroll down to the Submission form Settings tab.

5. Make sure that the Title field label now reads Site Name, as shown in Figure 6.2.

Image

Figure 6.2. The Title field label for your Sites content type

6. Click Save Content Type.

Editing a Field: Body

When you created the Sites content type, you weren’t given an opportunity to choose the label of the Body field, so do that now:

1. Click Manage Fields for the Sites content type, as shown in Figure 6.3.

Image

Figure 6.3. Manage Fields link for the Sites content type

2. Click Edit for the Body field, as shown in Figure 6.4.

Image

Figure 6.4. Edit the link for Body field in the Sites content type

3. Change the label from Body to Description, as shown in Figure 6.5.

Image

Figure 6.5. The Label for the Body field

4. Click Save Settings at the bottom of the page.

5. Check that both your Title and Body fields have now been updated to Site Name and Description, as shown in Figure 6.6.

Image

Figure 6.6. Your Sites content type with updated labels

Reusing a Field: Image

You saw in Chapter 5 that the Article content type has an image field. You used it to upload the Drupal mascot. That image field is available for you to reuse on other content types if you choose. Or you can create another image field. How do you decide? Let’s see.

Figure 6.7 shows the Image field configuration page from the Article content type. Notice the page is divided into two sections: Article Settings and Image Field Settings.

Image

Figure 6.7. The Article Settings and Image Field Settings

If you decide to reuse the image field, you cannot change the Image Field Settings without making those changes for all the content types that use this field. That isn’t a major hurdle because there are only three things you change in Image Field Settings:

Image How many images can be uploaded

Image Where the images will be stored

Image What the default image will be if none is chosen

Because you don’t need to customize any of those three settings, you can reuse the existing Image field. Here’s how to do it:

1. Click Structure on the black menu bar, and then click Content Types.

2. Click Manage Fields for the Sites content type.

3. Look for the Add Existing Field area, as shown in Figure 6.8.

Image

Figure 6.8. The Add Existing Field area

4. Enter Screenshot for the Label.

5. Choose Image: field_image (image) from the Field to share option.

Image will automatically be filled in for the Form element to edit the data option because it is the only choice.

6. Check that your settings look like Figure 6.9.

Image

Figure 6.9. The initial settings for the Screenshot field

7. Click Save and you see a screen similar to Figure 6.10.

Image

Figure 6.10. The full settings for the Screenshot field

8. Enter Upload a screenshot of the home page for this site in the Help text field. This help message will appear under the Image field when people upload screenshots.

9. Review the Setting options on the page for future reference.

10. Click Save Settings.

Reusing a Field: Term Reference

When you created a page using the Article content type, you enter relevant words into a field called Tags. This allowed you to group your Articles according to these keywords.

Rather than re-create this field, you can reuse it. If you reuse this field, there are only two options that, if changed, will change for all content types using this field:

Image How many tags can be used.

Image Which group of tags can be used. Later, in the “Taxonomy Explained” section, we explain how you can manage these groups.

Now repeat the process you used to reuse the Image field, but reuse the Tags field for the Sites content type:

1. Click Structure on the black menu bar, and then click Content Types.

2. Click Manage Fields for the Sites content type.

3. Enter Tags for the Label.

4. Choose Term Reference: field_tags (Tags) from the Field to share option.

5. Choose Autocomplete Term Widget (Tagging) for the Form element to edit the data option.

6. Check that your settings look like Figure 6.11.

Image

Figure 6.11. Reusing a Term Reference field

7. Click Save.

8. Keep the default settings and click Save Settings.

Observe that the Tags field is now added to the list of other fields on the Sites content type, as shown in Figure 6.12.

Image

Figure 6.12. The Tags field has been added to your Sites content type

Adding a Field: Boolean

In addition to reusing fields, you can create new ones.

Your plan has a field that enables the content author to show whether the site is an official Drupal site. The Boolean field option would be perfect for this because it provides an either/or choice. A Boolean field is perfect for choices such as Yes/No and True/False.

For the Official site field, the site will be listed as either an official site (true) or not an official site (false). Now add this field:

1. Make sure you are on the Manage Fields page for Sites content type. As a reminder, you can get there by clicking Structure, Content Types, and then Manage Fields for Sites.

2. Look for the Add New Field, as shown in Figure 6.13.

Image

Figure 6.13. The Add New Field area

3. Enter Official Site as the field label.

4. Enter sites_officialsite for the field name.

5. Select Boolean as the type of data to store.

6. Select Check Boxes/Radio Buttons as the form element to edit the data.

7. Make sure that your settings match Figure 6.14.

Image

Figure 6.14. Adding a new Boolean field

8. Click Save.

9. On the next screen, enter Yes for On value and No for Off value, as shown in Figure 6.15.

Image

Figure 6.15. The Boolean field settings

10. Click Save Field Settings.

11. Scroll down the next screen and click Save Settings again.

12. Notice the new field is now added to the list, as shown in Figure 6.16.

Image

Figure 6.16. The Official Site field has been added to your Sites content type

One question you might have is about the Machine Name, which in this example was sites_officialsite. The naming convention is up to you but here is a tip. If you are creating a field that is unique to a specific content type, inserting the content type name in the field name is a good idea. For example, field_sites_image will be used only for Sites, but field_image will be reused by multiple content types. This can help you distinguish between fields that are unique and fields that are reused.

Adding a List (Text) Field

Now you can create a Topics field. This allows people to choose what topics you’ll find on each site. There are a variety of ways to do this, but here’s one of the simplest options: List (Text):

1. Make sure you are on the Manage Fields page for Sites content type. (As a reminder, you can get there by clicking Structure, Content types, and then Manage Fields for Sites.)

2. Look for the Add New Field area.

3. Enter Topics as the field label.

4. Enter sites_topics for the field name.

5. Select List (text) as the type of data to store.

6. Select Check Boxes/Radio Buttons as the form element to edit the data.

7. Make sure that your settings match Figure 6.17.

Image

Figure 6.17. Adding a new List (Text) field

8. Click Save.

9. On the next screen, enter the various topics that a Drupal site can address. In Figure 6.18, we entered News, Tutorials, Groups, Events, Modules, and Themes. Each topic is on a new line.

Image

Figure 6.18. The settings for a List (Text) field

10. Click Save Field settings.

11. Scroll down the next screen and click Save Settings again.

12. Notice the new field is now added to the list, as shown in Figure 6.19.

Image

Figure 6.19. The Topics field has been added to your Sites content type

Creating New Sites Content

In Chapter 5, when you created the Sites content type, you added Drupal.org as an example. Now add a new Site using all your new fields:

1. Click Add Content.

2. Click Sites.

Your content creation page should look like Figure 6.20.

Image

Figure 6.20. The content creation screen for your Sites content type

3. Complete the content type form with the following:

Image Site Name: Groups.Drupal.org.

Image Body: http://groups.drupal.org is the official Drupal community site.

Image Thumbnail: If you are comfortable creating your own screenshots, you can visit http://groups.drupal.org and capture a screenshot. Otherwise, you can download a screenshot at http://www.drupal7explained.com/chapter6.

Image Tags: Drupal, Groups, Community.

Image Official site: Yes.

Image Topics: Groups.

Figure 6.21 shows what your new fields should look like.

Image

Figure 6.21. Using the new fields for your Sites content type

4. Click Save. Your new content should look like Figure 6.22.

Image

Figure 6.22. A content item published using your Sites content type

Repeat this process for http://DrupalModules.com. This site offers ratings and reviews on Drupal modules, but it is not an official site. There is a screenshot at http://www.drupal7explained.com/chapter6 if you need it. Figure 6.23 shows how your content should look when it has been created.

Image

Figure 6.23. Another content item published using your Sites content type

Companies Fields Explained

The Companies content type reuses several fields created on other content types and adds one more type of field. Using the same processes you used so far, you can edit and/or add the following fields:

Image Title: Company Name

Image Body: Description

Image Image: Logo

Image Term reference: Tags

Image List (Text): Services

Image Link: Link

Now set up those fields.

Editing a Field: Title

1. Click Structure on the black menu bar and then Content types.

2. Click Edit for the Companies content type.

3. Scroll down to the Submission Form Settings tab.

4. Make sure that the Title field label now reads Company Name.

5. Click Save Content Type.

Editing a Field: Body

1. Go to the Manage Fields page for the Companies content type.

2. Click Edit for the Body field.

3. Change the label from Body to Description.

4. Click Save Settings at the bottom of the page.

5. Check that both your Title and Body fields have now been updated to Site Name and Description, as shown in Figure 6.24.

Image

Figure 6.24. The edited fields for your Companies content type

Reusing a Field: Image

1. Make sure you are on the manage fields page for the Companies content type.

2. Look for the Add Existing Field area.

3. Enter Logo for the Label.

4. Choose Image: field_image (image) from the Field to Share option.

Image will automatically be filled in for the Form Element to Edit the Data option because it is the only choice.

5. Click Save.

6. Default image: You can download this from http://www.drupal7explained.com/chapter6. This image shows if someone adds a Company but does not add a logo. Notice that there are two Default images settings. You want the one that is at the top of the screen. If you use the setting at the bottom of the screen, that change will apply to all other content types using this field.

7. Click Save Settings.

8. Check that your Image field has been successfully reused, as shown in Figure 6.25.

Image

Figure 6.25. The Logo field added to your Companies content type

Reusing a Field: Term Reference

1. Make sure you are on the manage fields page for the Companies content type.

2. Look for the Add Existing Field area.

3. Enter Tags for the Label.

4. Choose Term reference: field_tags (Tags) from the Field to share option.

5. Choose Autocomplete Term Widget (Tagging) for the Form element to edit the data option.

6. Click Save.

7. Keep the default settings and click Save Settings.

8. Check that your Tags field has been successfully reused, as shown in Figure 6.26.

Image

Figure 6.26. The Tags field added to your Companies content type

Adding a List (Text) Field

1. Make sure you are on the Manage Fields page for the Companies content type.

2. Look for the Add New Field area.

3. Enter Services as the field label.

4. Enter companies_services for the field name.

5. Select List (Text) as the type of data to store.

6. Select Check Boxes/Radio Buttons as the form element to edit the data.

7. Click Save.

8. On the next screen, enter the various services that a Drupal company can provide: Coding, Themes, Hosting, Training, and Support. Make sure that each service is listed on a new line.

9. Click Save Field Settings.

10. Scroll down the next screen and click Save Settings again.

11. Notice the new field is now added to the list, as shown in Figure 6.27.

Image

Figure 6.27. The Services field added to your Companies content type

Adding a Link Field

Now try something different. Break out of the field options that you have seen so far and add a new field option.

You can add a new type of field by going to Drupal.org and downloading a module. The module that is going to enable you to add links as fields is called (simply) Link.

Here’s the workflow you can use. We call it the FITS workflow because using it means that your new feature FITS nicely inside your site:

1. Find the module.

2. Install the module.

3. Turn on the module.

4. Set up the module.

Step 1: Find the Module

1. Open another tab in your browser.

2. Go to http://drupal.org/project/link, as shown in Figure 6.28.

Image

Figure 6.28. The Drupal.org page for the Link module

3. Scroll down to the bottom of the screen and find the Downloads area, as shown in Figure 6.29.

Image

Figure 6.29. The Drupal.org download area for the Link module

Here’s what to look for when finding the right file:

Image You need to look at the files that are in the green area. If files are in the green area, that means they are the recommended version.

Image You need to look for the files labeled 7, rather than 5, 6, or 8. If files are labeled with 7, that means they work with Drupal 7.

Image It doesn’t often matter if you choose the tar.gz or zip files.

Image Don’t worry if the version numbers have changed since the screenshots in this book were created. You will be fine if you choose the latest release in green, which is marked for Drupal 7.

Figure 6.30 shows the marked recommended version for Drupal 7.

Image

Figure 6.30. The correct Drupal 7 download link for the Link module

4. Right-click the tar.gz link as marked in Figure 6.30, and copy the link or copy the shortcut. The exact command depends on the browser you use. The URL that you copy should look like this: http://ftp.drupal.org/files/projects/link-7.x-1.0.tar.gz. If you have any problems doing this and want help or another way to install your files, visit http://www.drupal7explained.com/chapter6.

5. Return to the browser tab that has your site.

Step 2: Install the Link Module

1. Click the Modules link on the black menu bar.

2. Click Install New Module, as shown in Figure 6.31.

Image

Figure 6.31. The Install New Module link

3. Click in the Install from a URL area, and paste the URL you captured when you copied the link, as shown in Figure 6.32.

Image

Figure 6.32. Entering the Link module’s URL into the Install from a URL area

4. Click Install. You’ll see a screen such as the one in Figure 6.33, which says Installation Was Completed Successfully.

Image

Figure 6.33. The success screen after installing a module

5. Click Enable Newly Added Modules. Clicking this link doesn’t actually enable any modules, but it takes you back to the Module page where you can turn on the module.

Step 3: Turn on the Module

1. Scroll down the page and check the box next to the Link module, as shown in Figure 6.34.

Image

Figure 6.34. Edit link for the Sites content type

2. Click Save Configuration.

Step 4: Set Up the Module

1. Click Structure on the black menu bar.

2. Click Content Types.

3. Click Manage Fields for the Companies content type.

4. Add the Link field:

Image Label: Site; Figure 6.35 then shows label as “Link”

Image Field name: link (Each content type will have a link field so plan on reusing this field.)

Image Type of data to store: Link

Image Form element to edit data: Link

5. Click Save.

6. Scroll down and click Save Settings.

7. Check that Link has been successfully added to your Companies content type, as shown in Figure 6.35.

Image

Figure 6.35. The Link field added to your Companies content type

Creating New Companies Content

In Chapter 5, when you created the Companies content type, you added Acquia as an example. Now add a new Company, using all your new fields:

1. Click Add Companies.

2. Click Companies.

Your Content Creation page should look like Figure 6.36.

Image

Figure 6.36. The content creation screen for your Companies content type

3. Complete the content type form with the following:

Image Company Name: OSTraining

Image Body: http://ostraining.com is the company run by Steve, who co-authored this book. Yes, he is sneaking in a mention of his company.

Image Logo: You can download this from http://www.drupal7explained.com/chapter6.

Image Tags: Atlanta, Training

Image Services: Training

Image Link Title: OSTraining

Image URL: http://OSTraining.com

4. Click Save. Your new content should look like Figure 6.37.

Image

Figure 6.37. The OSTraining content item live on your site

5. Repeat this process for Phase 2 Technology. Here are the details:

Image Title: Phase 2 Technology

Image Body: Phase 2 Technology is based in Washington DC and has been involved with many of the largest Drupal projects. It has also written a lot of code for Drupal.

Image Logo: You can download this from http://www.drupal7explained.com/chapter6.

Image Tags: Washington DC, Large Projects

Image Services: Coding

Image Link Title: Phase 2 Technology

Image URL: http://phase2technology.com

Figure 6.38 shows how your content should look when it has been created.

Image

Figure 6.38. Edit link for the Sites content type

Editing Fields

After using your Companies content type twice, you might feel that some of the fields could be improved. For example, there are at least two possible improvements to the Services field:

Image Currently N/A is an option. You might want to force companies to tell you what services they provide.

Image Many companies might provide more than one service.

It is possible to go back and edit fields and fix these problems; however, you can’t change the type of field. For example, you can’t change an Image field to a Text field. But you can edit the settings of each field. A word of warning before you start: You can safely change these settings before you enter all of your site’s content, but be careful about making changes after your content has been added:

1. Go to Structure, Content Types, and click on Manage Fields for the Companies content type.

2. Click Edit next to Services. You now see the options that you can change.

3. To remove N/A as an option, check the box that says Required field, as shown in Figure 6.39.

Image

Figure 6.39. Making the Services field into a Required field

To allow companies to provide more than one service, change the Number of Values list further down the page, as shown in Figure 6.40.

Image

Figure 6.40. Changing the number of values allowed for the Services field

Click Save.

Events Fields Explained

Now that you have created two new content types, you can be a little more adventurous. The Events content type will have more fields and you can modify them.

Here are the fields for your Events content type:

Image Title: Event Name

Image Body: Description

Image Image: Event Logo

Image Term Reference: Tags

Image Link: Registration

Image Decimal: Event Price

Image Date: Event Date

Image Entity Reference: Sponsors

Let’s go and set up those fields one-by-one:

Editing a Field: Title

1. Go to Structure, Content types, and then click Edit for the Events content type.

2. Make sure that the Title field label now reads Event Name.

Editing a Field: Body

1. Go to the Manage Fields page for the Events content type.

2. Click Edit for the Body field, and change the label from Body to Description.

Reusing a Field: Image

1. Make sure you are on the Manage Fields page for the Events content type.

2. Look for the Add Existing field area.

3. Enter Event Logo for the Label.

4. Choose Image: field_image (image) from the Field to share option.

5. Click Save and then Save Settings.

Reusing a Field: Term Reference

1. Look for the Add Existing Field area.

2. Enter Tags for the Label.

3. Choose Term reference: field_tags (Tags) from the Field to share option.

4. Choose Autocomplete term widget (tagging) for the Form element to edit the data option.

5. Click Save and then Save Settings.

Reusing a Field: Link

1. Look for the Add Existing Field area.

2. Enter Link for the Label.

3. Choose Link: field_link (Link) from the Field to share option.

4. Choose Link for the Form element to edit the Data option.

5. Click Save and then Save Settings.

Adding a Field: Decimal

There are three types of number fields provided by default: Integer, Float, and Decimal. You need a field for the price of your event.

An Integer field enables only whole numbers, so if you use that you cannot enter 9.95 for your price. You would have to enter 9 or 10.

The Float field and Decimal give you the option to have a decimal. The difference is that a Float field is generally used for numbers where exact precision is not so important. However, you know the exact price of your events, so add a Decimal field for your event price.

1. Make sure you are on the Manage Fields page for the Events content.

2. Locate the Add New Field. Here are the choices to make when adding this next field:

Image Label: Event Price.

Image Field name: events_price.

Image Type of data to store: Decimal.

Image Form element to edit the data: Text field.

3. Click Save.

4. On the next screen, keep the default settings.

5. Click Save Field Settings.

6. Prefix: $. This dollar sign appears in front of the field.

7. Click Save Settings again.

You’ve now modified, reused, or added six new fields. Check that your fields match those shown in Figure 6.41.

Image

Figure 6.41. The fields for your Events content type

Adding a Field: Date

When you added fields to your Companies content type, you installed a module called Link to allow you to add Link fields.

For your Events content type, use exactly the same process: FITS. This process enables you to install the Date module and make sure it FITS into your site.

Use the Date module to add Date fields. As a reminder, here is how the FITS process works:

1. Find the module.

2. Install the module.

3. Turn on the module.

4. Set up the module.

Step 1: Find the Date Module

1. Open another tab in your browser.

2. Go to http://drupal.org/project/date. The screen should look like Figure 6.42.

Image

Figure 6.42. The Drupal.org page for the Date module

3. Scroll to Downloads area and the Locate the tar.gz link associated with Drupal 7. The correct link is highlighted in Figure 6.43.

Image

Figure 6.43. The Drupal 7 download link for the Date module

4. Right-click the tar.gz link, and copy the link or copy the shortcut. The exact command depends on the browser you use. The link should look like this: http://ftp.drupal.org/files/projects/date-7.x-2.5.tar.gz.

5. Return to the browser tab that has your site.

Step 2: Install the Date Module

1. Click Modules on the black menu bar.

2. Click Install New Module.

3. Click in the Install from URL field, and paste the URL you captured when you copied the link. Your screen should look like Figure 6.44.

Image

Figure 6.44. Installing the Date module

4. Click Install.

5. Click Enable Newly Added Modules.

Step 3: Turn on the Date Module

When enabling modules earlier in this book, you had to check only one box. The Date module is different. Look at the screen in Figure 6.45 to see the Date module provides many boxes to check. However, you don’t need to check all those boxes. To set up a date field for your Events, you need to check only three boxes.

Image

Figure 6.45. The options for the Date module

1. Check the box next to the Date, Date API, and Date Popup modules.

2. Click Save Configuration.

Step 4: Set Up the Date Module

1. Click Structure and then Content Types. Then click Manage Fields for the Events content type.

2. Add new field label: Event date

Image Field name: events_date.

Image Type of data to store: Date

Image Form element to edit the data: Popup calendar

3. Click Save.

4. Check Collect an End Date, as shown in Figure 6.46.

Image

Figure 6.46. The Field Settings for the Date field

5. Click Save Field Settings; then click Save Settings.

Adding a Field: Entity Reference

When you installed the Date module, you saw that it was different from the other modules you had used before. The Date module was different because it came with a variety of features and you didn’t need to turn them all on.

Now, here’s another type of module. The Entity Reference module has two things different about it:

Image Unlike the Link and Date module, the Entity Reference module requires another module to work.

Image Unlike Link, Date, Blog, Poll, and the other modules you’ve used so far, the name of this module doesn’t immediately tell you what it does. As you become more experienced with Drupal, you’ll find that the name of the module doesn’t always clearly match the purpose you’ll use it for. Regarding the Entity Reference module, visit http://www.drupal7explained.com/chapter6 for an explanation of the name.

You can use the Entity Reference module to cross-link your content. Your Events have Companies who sponsor them. To show these sponsors, use the Entity Reference module to link from your Events content to your Companies content.

You still use the FITS workflow to make your module work, but the first part involves installing more modules. Now see how to set up an Entity reference field.

Step 1: Find the Modules

Go to Drupal.org and find the Drupal 7 download URLs for these three modules:

1. Entity reference: http://drupal.org/project/entityreference.

2. Entity API: http://drupal.org/project/entity

3. CTools: http://drupal.org/project/ctools

Step 2: Install the Modules

1. Click Module on the black menu bar.

2. Click Install new module.

3. Click in the Install from URL area and paste in the download URL for the Entity reference module that you captured in Step 1.

4. Click Install.

5. Repeat this process. Click Enable newly added modules.

6. Repeat this process for the Entity API and CTools modules.

Step 3: Turn on the Modules

1. Check the Chaos Tools box.

2. Check the Entity Reference box.

3. Check the Entity API box.

4. Click Save configuration.

Step 4: Set Up the Modules

1. Click Structure, Content types, and then manage fields for the Events content type and locate the Add New Field option.

2. Add new field label: Sponsors:

Image Field name: events_sponsors.

Image Type of data to store: Entity reference.

Image Form element to edit data: Select list.

3. Click Save.

4. Target Bundles: Choose Companies, as shown in Figure 6.47.

Image

Figure 6.47. Linking your Events content to your Companies content

5. Click Save Field Settings.

6. Number of values: Unlimited.

7. Click Save Settings.

Check that your Events content type looks like Figure 6.48.

Image

Figure 6.48. The Sponsors field added to your Events content type

Creating Content: Events

In Chapter 5, when you created the Events content type, you created a content item for DrupalCon Portland. Now that you’ve added all your extra fields, go back and add another event:

1. Click Add content and then click Events.

2. Complete the content type form with the following:

Image Title: DrupalCon Munich.

Image Body: Drupal holds a big conference in North America every year, but it also holds one in Europe. In 2012, the European DrupalCon was in Munich.

Image Event Logo: You can download this from http://www.drupal7explained.com/chapter6.

Image Tags: DrupalCon, Europe, Munich

Image Registration Title: DrupalCon Munich

Image URL: http://munich2012.drupal.org

Image Event Price: $450.00

Image Event Date: August 20, 2012 at 09:00 to August 24, 2012 at 16:00

Image Sponsors: Acquia, Phase 2 Technology

3. Before you click Save, make sure that your content looks like Figure 6.49.

Image

Figure 6.49. Adding content to your Events content type

4. After you click Save, your content should look like Figure 6.50.

Image

Figure 6.50. Edit link for the Sites content type

Editing the Default Field Display

When you were creating Companies, you saw that you could go back and edit the settings of fields. It is also possible to alter the display of fields. For example, your fields take up two lines at the moment, with the label on one line and the field content on the next line. You may want to place all the details for a field onto just one line. Also, your Sponsor names don’t link back to the relevant Companies content.

Here’s how you can make your fields look better:

1. Go to Structure, Content types, and click Manage Display for the Events content type.

You’ll see a screen like the one shown in Figure 6.51.

Image

Figure 6.51. The Manage Display screen for the Events content type

2. Using the Label column, you can control the display of your labels. Choosing Inline puts the label and field content on one line. Choosing Hidden removes the label entirely. Figure 6.52 shows some recommended settings.

Image

Figure 6.52. The Label settings for the Events content type

3. Using the Format column, you can change some options about how each field displays. For example, the Link field offers a variety of ways that you can mix-and-match the Label and URL parts of the field, as shown in Figure 6.53.

Image

Figure 6.53. The Format settings for the Events content type

Also, some fields have gear icons on the right side of the screen, as marked in Figure 6.54.

Image

Figure 6.54. The gear icon to change display settings

4. Now, automatically link your Sponsor information to their profiles. To do that, click the gear icon in the Sponsor’s row and check the box that says Link Label to the Referenced Entity. This is shown in Figure 6.55. Click Update to complete the change.

Image

Figure 6.55. Edit link for the Sites content type

5. Click Save to make sure that your changes aren’t lost.

Editing the Teaser Display

In the previous section, you controlled how your Events appear when someone sees all the content. Sometimes, however, they see only part of the content. A great example is the homepage. Figure 6.56 shows how your DrupalCon Munich content appears on the homepage.

Image

Figure 6.56. The Teaser for the Events content type

The limited homepage display is done for a good reason. If you put all the fields from all of your content on the homepage, it would make one long page. So, Drupal uses Teasers, which contain only part of the content. Here’s how you can control what’s in the Teaser:

1. Go to Structure, Content types, and then the Manage Display screen for Events.

2. Click the Teaser button in the top-right corner, as shown in Figure 6.57. Drupal uses these top-right buttons often, and they can be easy to miss.

Image

Figure 6.57. The Teaser link on the Manage Display page

3. Notice that almost all the fields are placed in the Hidden area, as shown in Figure 6.58. This means that they will not currently show in the Teaser area.

Image

Figure 6.58. The Manage Display page for the Events content type

4. Change the Label for the Event Date field to Inline.

5. Change the Format for the Event Date field to Date and Time. The Date now jumps to the top area of the screen.

6. Change the Label for the Event Logo field to Hidden.

7. Change the Format for the Event Logo field from Hidden to Image.

8. Click the gear icon for the Event Logo.

9. Change the Image style from original to thumbnail.

10. Change the Link Image to Field to Content.

11. Click Update.

If you want to rearrange the order of these fields, you can do that by holding down and moving the crosses next to each field, as shown in Figure 6.59.

Image

Figure 6.59. The arrow used to rearrange fields

12. Click Save.

13. Return to the homepage and observe your DrupalCon Munich teaser, as shown in Figure 6.60.

Image

Figure 6.60. The teaser for your Events content type

14. Click the title of the content or click the Read more link and you can see the full content together with your display changes. It should look like Figure 6.61.

Image

Figure 6.61. The default display for your Events content type

User Groups Fields Explained

Here are the fields for your User Groups content type:

Image Title: User Group Name

Image Body: Description

Image Term Reference: Tags

Image Link: User Group Website

Image Entity reference: Organizers

Image Address: User Group Location

Now set up those fields one by one. This time, you can simplify the instructions. If you get stuck, look back to earlier sections in this chapter, and you’ll see how to do these tasks.

Editing a Field: Title

Edit the Title field label so that it reads Event Name.

Editing a Field: Body

Edit for the Body field and change the label from Body to Description.

Reusing a Field: Term Reference

Reuse the Tags field and give it the label Tags.

Reusing a Field: Link

Reuse the Link field and give it the label User Group Website.

Adding a Field: Entity Reference

When you created your Events field, you used Entity Reference to link between your content. Now with your User Groups, you can use Entity Reference to link to users. The goal is that when people register on your site, you can link to them as group organizers:

1. Add new field label: Organizers

Image Field name: user_groups_organizers

Image Type of Data to Store: Entity reference

Image Form Element to Edit Data: Autocomplete

2. Click Save.

Image Target Type: User

3. Click Save Field settings.

Image Number of Values: Unlimited

4. Click Save Settings.

Adding a Field: Address

To add addresses to content, install the Address Field module. Address Field does rely on the Chaos Tools (CTools) module but you already have that installed.

Use the FITS workflow to make sure it FITS nicely inside your site.

Step 1: Find the Module

1. Open another tab in your browser.

2. Go to http://drupal.org/project/addressfield.

3. Locate the tar.gz file associated with Drupal 7.

4. Right-click the tar.gz link and copy the link or copy the shortcut. The exact command depends on the browser you use.

5. Return to the browser tab that has your site.

Step 2: Install the Module

1. Click Module and then Install New Module.

2. Click in the Install from URL field and paste the URL you captured when you copied the link.

3. Click Install.

4. Click Enable Newly Added Modules.

Step 3: Turn on the Module

1. Check the box next to Address field.

2. Save configuration.

Step 4: Set Up the Module

1. Click Structure, Content types, and then manage fields for the User Groups content type:

Image Label: User Group location

Image Field name: Address (you can easily reuse this field on other content types.)

Image Type of Data to Store: Postal address

Image Form Element to Edit Data: Dynamic address form

2. Click Save.

3. Click Save Field Settings.

4. Review your options, but stay with default for this activity.

5. Click Save Settings.

Check your User Group fields. They should now look like Figure 6.62.

Image

Figure 6.62. The fields for your User Groups content type

Creating Content: User Groups

In Chapter 5, when you created the User Groups content type, you created a content item for Drupal Atlanta. Now that you’ve added all your extra fields, go back and add another user group:

1. Click Add content, and then click User Groups.

2. Complete the content type form with the following:

Image Title: Washington D.C. Drupal.

Image Body: This group is for everyone living in the Washington D.C. metro area who’s interested in Drupal.

Image Tags: Washington D.C.

Image Link Title: Washington D.C. Drupal.

Image Link URL: http://groups.drupal.org/washington-dc-drupalers.

Image Organizers: Choose yourself because you are the only current user.

Image Address: Stetson’s Famous Bar & Grill, 1610 U St, Washington, District of Columbia, 20009.

After you click Save, your content should look like Figure 6.63.

Image

Figure 6.63. Content created via your User Groups content type

As a final touch, improve the display of the fields:

1. Go to Structure, Content types, and click Manage Display for the User Groups content type.

2. Set all the Labels to Inline, except for Description, which should remain set to Hidden.

3. Click the gear icon next to Organizers, and check the box that says Link label to the referenced entity. Click Update.

4. Use the crosses on the left of the screen; reorganize the fields so that they match, as shown in Figure 6.64.

Image

Figure 6.64. The Manage Display screen for your User Groups content type

5. Click Save.

6. Visit your content. It should now look like Figure 6.65.

Image

Figure 6.65. The modified version of content created via your User Groups content type

Now you have one more task to complete your User Groups:

7. Go and find your own local User Group. You might be in North America, Europe, Asia, Africa, or Australasia, but there is a good chance you’ll find a Drupal User Group meeting near you. You can use a search engine or look on http://groups.drupal.org. Find the website, location, and information for your local user group and add it to your site.

Taxonomy Explained

Out of all the fields available in Drupal, one is more frequently used, misused, explained, and misunderstood than any other: Taxonomy.

Taxonomy is Drupal’s way of organizing content.

Without realizing it, you’ve actually been using Taxonomy already. Whenever you have used Tags, you have used Taxonomy.

Because Taxonomy is so important, we’re going to explain it in more detail than any other field. We show you how Tags works and then show you how to build your own Taxonomies to organize your content.

Understanding the Term Reference Field: Terms

To start, do as follows:

1. Go to Structure Taxonomy.

You’ll see that Tags and Forums are listed on the page. Notice that these are in the column called Vocabulary Name. In Drupal, both Tags and Forums are examples of what Drupal calls Vocabularies.

2. Click List Terms next to Tags, as shown in Figure 6.66.

Image

Figure 6.66. The List Terms link for the Tags Vocabulary

3. You now see a list of all the terms you’ve added to the site, as shown in Figure 6.67.

Image

Figure 6.67. All the terms listed for the Tags Vocabulary

As you can see, all those keywords and phrases that you’ve added are called Terms in Drupal. That explains the name of the field type you’ve used through this chapter: Term Reference. The Term Reference field enables people to enter terms and for you to show them on the page.

So, there are four definitions that help you understand how Drupal categorizes content:

Image Taxonomy: This is the name given to the whole system of organizing content in Drupal.

Image Vocabulary: This is the name given to a group of terms.

Image Terms: These are the keywords and phrases that actually categorize your content.

Image Term Reference field: This is how your terms are connected to your content.

Let’s see an example of how this can work with your content types.

You can improve your Companies content type. You can allow your companies to categorize themselves according to which language they speak.

Here’s what you need to set up:

Image Vocabulary: Languages

Image Terms: English, Spanish, German, French, Chinese, and so on.

Image Term Reference field: The field will be called Languages Spoken and attached to your Companies content type.

Figure 6.68 shows an overview of that categorization.

Image

Figure 6.68. The Languages Vocabulary with specific terms

Step 1: Create the Vocabulary

1. Click Structures on the black menu bar.

2. Click Taxonomy.

3. Click Add Vocabulary.

4. Name: Languages Spoken.

5. Click Save.

Step 2: Add the Terms

1. Click Add terms next to Languages Spoken:

Image Name: English

2. Click Save:

Image Name: Spanish.

3. Click Save:

Image Name: German.

4. Click Save.

Repeat for several more languages.

Step 3: Add the Term Reference Field

1. Go to Structure, Content types, and then click manage fields next to Companies.

2. Add the New Field label: Languages Spoken:

Image Field name: languages_spoken

Image Field type: Term reference.

Image Form element: Check boxes/radio buttons.

Why do you choose this rather than autocomplete? You don’t want to choose autocomplete because autocomplete enables people to enter their own choices. In this example, you don’t want people to enter their own languages.

3. Click Save:

Image Vocabulary: Languages Spoken

4. Click Save Field Settings:

Image Number of values: Unlimited.

5. Click Save Settings.

Step 4: Use the Term Reference Field

Go to Find Content and click Edit next to any of the companies you’ve added. You can now choose to add the languages spoken by that company.

So that’s the process that you can use for categorizing content in Drupal. However, Taxonomy can be much more flexible than you’ve seen so far.

Arranging Terms in a Simple Hierarchy

You can add terms to your Events content type. These enable Event organizers to show what topics will be covered during an event. Notice this time that you organize your terms into a hierarchy. The organization of the terms is also shown in Figure 6.69:

Image Vocabulary: What topics will be covered?

Image Terms: Community:

Image Learning Drupal

Image Contributing to Drupal

Image Running a User Group

Image Design:

Image Building themes

Image Building photo galleries

Image Making Drupal mobile-ready

Image Coding:

Image Building modules

Image Security

Image Integrating Drupal with other software

Image Term Reference field: The field will be called What Topics Will Be Covered? and attached to your Events content type.

Image

Figure 6.69. The What Topics Will Be Covered? Vocabulary with specific terms

Step 1: Create the Vocabulary

1. Click Structures on the black menu bar.

2. Click Taxonomy.

3. Click Add Vocabulary:

Image Name: What Topics Will Be Covered?

4. Shorten the machine_readable name.

5. Click Save.

Step 2: Add the Terms

1. Click Add Terms next to What Topics Will Be Covered?

Image Name: Community and then click Save.

Image Name: Learning Drupal and click Save.

Image Name: Contributing to Drupal and click Save.

Image Name: Running a User Group and click Save.

2. Repeat that process for these four terms: Design, Building Themes, Building Photo Galleries, and Making Drupal Mobile-Ready.

3. Repeat that process for these four terms: Coding, Building Modules, Security, and Integrating Drupal with Other Software.

4. Click the List tab at the top-right of the page. You’ll see a list of all your terms, which should look like Figure 6.70.

Image

Figure 6.70. The terms in your What Topics Will Be Covered? vocabulary

5. You can use the arrows next to each term to drag-and-drop each term. If this doesn’t work for you, click Edit, Relations, and you can use the Parent Terms field to organize your terms. Your aim is to organize your terms to match your original plan, as shown in Figure 6.71.

Image

Figure 6.71. The rearranged terms in your What Topics Will Be Covered? vocabulary

Step 3: Add the Term Reference Field

1. Go to Structure, Content types, and then click Manage Fields next to Events.

2. Add New Field label: What Topics Will Be Covered?

Image Field name: events_topics_covered

Image Field type: Term reference.

Image Form element: Check boxes/radio buttons.

3. Click Save:

Image Vocabulary: What Topics Will Be Covered?

4. Click Save field settings:

Image Number of values: Unlimited.

5. Click Save Settings.

Step 4: Use the Term Reference Field

Go to Find content and click edit next to any of the events you’ve added. You can now choose to add the topics covered by that event.

Arranging Terms in a Complex Hierarchy

So far, you’ve seen three ways in which terms can be organized:

Image Tags: The terms are completely unorganized with no hierarchy.

Image Languages Spoken: The terms are ordered with no hierarchy.

Image What Topics Will Be Covered?: The terms are ordered and in a simple hierarchy where many terms are organized under parent terms.

There is a fourth option: You can have a complex hierarchy where one term has multiple parents.

Now you can see an example of how this might work. Both Building Themes and Making Drupal Mobile-Ready are under two parent terms:

Image Vocabulary: What Topics Will Be Covered?

Image Terms: Community:

Image Learning Drupal

Image Contributing to Drupal

Image Running a User Group

Image Design:

Image Building themes

Image Building photo galleries

Image Making Drupal mobile-ready

Image Coding:

Image Building modules

Image Building themes

Image Making Drupal mobile-ready

Image Security

Image Integrating Drupal with other software

Now see how you can organize terms in this way:

1. Go to Structure, Taxonomy.

2. Click list terms next to What Topics Will Be Covered?

3. Click Edit next to Building themes.

4. Click Relations.

5. Using your cursor, you can select more than one parent term, as shown in Figure 6.72. Depending on the type of computer you use, you may also need to touch a key, such as Shift or Command. In the example shown in Figure 6.72, we’re selecting both Design and Coding.

Image

Figure 6.72. Choosing the parent terms for a particular term

6. Click Save.

You can see that Building Themes is now underneath two terms, as shown in Figure 6.73.

Image

Figure 6.73. A complex hierarchy of terms

7. Repeat that process for Making Drupal mobile-ready.

The only disadvantage with this complex hierarchy is that the drag-and-drop feature will not work any longer. You must rearrange all the terms by clicking Edit, Relations, and selecting a parent.

What’s Next?

Now see what your Drupalville site looks like at the end of this chapter. It should look similar to Figure 6.74.

Image

Figure 6.74. Your Drupalville site at the end of this chapter

Don’t worry if your site doesn’t match this exactly. If you understand the concepts covered in this chapter, you’ll be fine to move on to Chapter 7, “Drupal Modules Explained.”

Chapters 5 and 6 show you how content works in Drupal. However, most websites don’t just have content, they also have features. In Chapter 7, you move beyond content and add more features to your site. You add social bookmarks, contact forms, sitemaps, and more.

You add those features by adding more modules. In this chapter, you installed several modules using the FITS workflow. In the next chapter, you add many more.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset