Drupal for Education and E/Learning
上QQ阅读APP看书,第一时间看更新

Creating Content Types for the Teacher Blog

In this section, we will outline how to create two content types used in the Teacher blog. This section will refer to the process outlined in Chapter 3. When creating a content type you will need to:

  1. Create the content type
  2. Add fields to the content type (optional—not all content types require additional fields)
  3. Assign a taxonomy to the content type (optional—not all content types will be organized using taxonomy)
  4. Assign permissions to the content type

The Blog Post Content Type

The Blog post content type will be one of the publishing tools available to users in this site. To create this content type, click the Administer | Content management | Content types link, or navigate to admin/content/types.

As described in Chapter 3, to create a new content type, click the Add content type tab.

For the Identification section, use the following values:

Name: Blog post

Type: blog_post

Description: Create a blog post.

In the Submission form settings section, the Explanation or submission guidelines can be set to: Create your blog post. Enliven your post with relevant details, and describe these details with sumptuous prose.

Tip

The values of the Explanation or submission guidelines are somewhat arbitrary; while this section can be used to give instructions, it can also be used to have fun. Obviously, the rules of civil and appropriate discourse apply, but you can use these instructions to add a touch of unexpected flavor.

In the Workflow settings, set default settings to Published.

In the Comment settings section, set the default to Read/Write, and configure the comment displays as described in Chapter 3.

Click the Save content type button to create the content type.

Add Fields

No fields need to be added to this content type.

Assign Taxonomy

Click the Administer | Content management | Taxonomy, or admin/content/taxonomy.

As shown in the following screenshot, click the edit vocabulary link for the Keywords taxonomy we created in Chapter 3.

Assign Taxonomy

Then, add Blog post to the list of Content types as shown in the following screenshot:

Assign Taxonomy

Click the Save button to save your changes.

Assign Permissions

Click the Administer | User management | Roles link, or navigate admin/user/roles. Click the edit permissions link for the teacher role.

Tip

Every time we create a new content type, we will need to assign user roles permissions to use the content type. The permissions for content types are usually assigned via the node module.

Assign Permisblog post content typetaxonomy, assigningsions

Tip

Assigning a role the Administer nodes permission will allow all users in that role to add, edit, or delete all posts of all content types. Administer nodes permissions should only be assigned to highly trusted users. The permissions described in this section need to be assigned individually for all content types.

Content types usually have five permissions. For every individual content type, the following permissions can be assigned:

  • Create: This permission allows a user to create nodes of a specific content type
  • Delete own: This permission allows users to delete posts they have authored
  • Delete all: This permission allows users to delete any post, regardless of who created it.
  • Edit own: This permission allows user to edit posts they have authored
  • Edit all: This permission allows users to edit any post, regardless of who authored it.

As shown in the preceding screenshot, we want to assign the teacher role permissions to create blog_post content, delete own blog_post content, and edit own blog_post content.

Click the Save permissions button to save the permissions.

Hey! Why Not Use the Blog Module?

Drupal comes with a blog module. Although it could be used for this site, we are opting not to use it because of how we are structuring the blog. Unlike more traditional blogs, we will be configuring this blog to make it easy to include audio, video, and images, as well as text. A person's blog will contain the full range of content they create.

Additionally, Drupal's blog module has some features that work better for single user or multiple user blogs than for this site. These features include some default displays that list all blog posts. For this site, we will be using Views to create displays for our content; this allows for a greater degree of flexibility than the blog module. So, rather than trying to override the default behavior of the blog module, we will sidestep the issue entirely.

The Assignment Content Type

To create Assignments, we will create another content type. This content type will be very similar to the blog post content type we just created, with one exception: Assignments will contain a Date field to allow teachers to specify a Due date. As described earlier in this chapter, and in Chapter 3, we need to follow four steps:

  1. Create the content type
  2. Add fields to the content type (optional—not all content types require additional fields)
  3. Assign a taxonomy to the content type (optional—not all content types will be organized using taxonomy)
  4. Assign permissions to the content type

Getting Started: Installing Modules

To add and display date fields, we need to download and install the Date and Calendar modules. Navigate to the project pages for Date and Calendar at http://drupal.org/project/date and http://drupal.org/project/calendar.

As described in Chapter 3, upload the modules into the sites/all/modules directory.

Then, click the Administer | Site building | Modules link, or navigate to admin/build/modules as shown in the following screenshot:

Getting Startecontent type, creatingassignment content typed: Installing Modules

Enable the Calendar, Calendar Popup, Date, Date API, Date Popup, and Date Timezone modules. These modules are all part of the Date and Calendar modules.

Tip

If your server has a PHP version below 5.2, you will need to enable the Date PHP4 module. To check your PHP version, click the Administer | Reports | Status report link, or navigate to admin/reports/status.

Click the Save configuration button to save the settings, and enable the modules.

The Assignment Content Type

Navigate to Administer | Content management | Content Types, or admin/content/types. Click the Add content type tab.

For the Identification section, use the following values:

Name: Assignment

Type: assignment

Description: Add an assignment.

In the Submission form settings section, the Explanation or submission guidelines can be set to: Create an assignment. Remember to set a due date. Additionally, you can change the Body field label to Description.

In the Workflow settings, set default settings to Published.

In the Comment settings section, set the default to Read/Write, and configure the comment displays as described in Chapter 3.

Click the Save content type button to create the content type.

Add Fields

Now that we have created the Assignment content type, we need to add a Date field to specify a Due date for assignments.

As shown in the screenshot below, click the manage fields link.

Add Fields

We will then Add a New field, as shown in the screenshot below.

Add Fields

Enter the following values:

Label: Due date

Field name: due_date

Field type: Datetime

Selecting the field type exposes the Form element to edit the data option; select Text Field with Date pop-up calendar option.

Click the Save button. This brings up the final settings screen for Date fields, pictured in the screenshot below.

Add Fields

For most uses, including this one, the default settings will work perfectly well. However, we want to highlight 6 places on this screen that allow you to customize Date fields in order to make them do exactly what you want.

Item 1; Default Value: set to Now. This will autofill the form with the current time, which helps guide users as they fill it out.

Item 2; Input format: the default value is in military time. In some cases, users are more comfortable using AM/PM to indicate times.

Item 3; Help text: The text here will be shown to users as they are creating assignments. For this example, we can use Enter the date and time where the assignment will be due.

Item 4; Required: as all assignments have due dates, we set this to Required.

Item 5; Granularity: the items specified here will be presented to users as options when they create content. For example, if you only want to collect a day, you would set the granularity to Year, Month and Day. In this example, as we want to set a specific time assignments are due, so we opt to include Hours and Minutes.

Item 6; Date display: similar to Item 2, above, the default value is in military time. If this will pose a problem for your users, set it to a 12 hour time setting.

Once you have adjusted the settings, click the Save field settings button in order to save your changes.

Ordering Fields

After saving your field settings, you will be returned to the Manage fields page.

Ordering Fields

The fields can be adjusted via drag and drop. Drag the Due date to be second on the page. Click the Save button in order to submit the form and save the changes.

Assign Taxonomy

As described in Chapter 3, and earlier in this chapter, use the Keyword taxonomy to categorize assignments.

For a greater degree of control, we can create an additional taxonomy for assignments named Type of Assignment. This would allow teachers to apply keywords to assignments separate from the keywords used for other content. While this is not necessary, increased organization can be useful in larger sites.

Assign Permissions

As described earlier in this chapter, assign the teacher role permissions to create assignment content, delete own assignment content, and edit own assignment content.

Click the Save permissions button to save the permissions.