Creating the Student Blog in Drupal using Cloning

Packt Publishing

For the purpose of this article we will clone the already existing Teacher Blog and create the Student Blog.

Setting Up the Student Blog

To create the student blog, we need to do two things:

Give users in the student role permissions over the blog post content type.

Clone the teacher_blog view, and edit it to display student blog posts.

Assigning Permissions

To allow students to blog in the site, we need to allow users in the student role the ability to create blog posts. Click the Administer | User management | Roles link, or navigate to admin/user/roles. Click the link to edit permissions for the student role.

Navigate down to the section for the node module. Select the options for create blog_post content, delete own blog_post content, and edit own blog_post content.

Click the Save permissions button to save the settings.

Students can now blog in the site.

Clone the Teacher Blog

Now that students have the ability to create blog posts, we now need to create a central place where people can read these posts. We have already set up this structure for the teacher blog; cloning this pre-existing view will allow us to quickly replicate this structure for the student blog.

To begin, click the Administer | Site building | Views link, or navigate to admin/build/views. Scroll down to the teacher_blog view and click the Clone link.

Change the view name to student_blog; change the view description to All posts to be displayed in the Student blog; change the View tag to student. Click the Next button to continue.

In the default settings, we want to change the User: Roles filter. As shown in the following screenshot, you can verify that you are editing the Defaults as indicated by Item 1; to edit the User: Roles filter, click the link as indicated by Item 2; and to edit the Title, click the link indicated by Item 3.

Change the User: Roles setting to student; this will only select content posted by users in the student role. Change the Title setting to Student blog.

As we add more content types (audio, video, and images) we will need to revisit this view to update the Node:Type filter. At this stage, this filter only selects blog posts and bookmarks.

Then, as shown in the following screenshot, click the Page link (indicated by Item 1) to change the settings for the Page display for this view. We need to edit both of the options under Page settings (indicated by Item 2). We also need to edit the Header (indicated by Item 3) in the Basic settings.

Under Page settings, change the Path to student-blog, and change Menu to Normal: Student blog.

Under Basic settings, edit the Header to read Hello! You are viewing posts from the student blog. Enjoy your reading, and comment frequently.

Click the Save button to save the view.

All student blog posts are now visible at http://yoursite.org/student-blog.

Getting Interactive

Now that students can create blogs in the site, you have the ability to foster dialogue within your class. The easiest way, of course, is simply through commenting. Students have the rights to comment on assignments, and on teacher and student blog posts. However, students might also want to reference other pieces of content in their work. In this section, we will set up a mechanism that will keep track of when one post within the site references another post within the site. This way, people can see when exchanges are occurring about different posts, and it provides another way (in addition to comment threads) for people to hold discussions within the course.

Seeing Who's Discussing What

Within the site, we will want to see who is discussing what posts. In web parlance, this is referred to as a backlink. Fortunately, the Views module comes with a means of tracking backlinks by default. We will clone and customize this existing view to get exactly the functionality we want.

The process of cloning this view includes the following steps:

The default backlinks view needs to be enabled and cloned.

In the cloned view, the different displays need to be edited:

In the Default display, Fields need to be added to the view, the Arguments need to be adjusted, and the Empty text needs to be deleted.

As the new view will only generate a block, the Page display should be removed.

In the Block display, the Items per page needs to be increased, the More link needs to be removed, and the Block settings needs to be changed.

Then, once the new view has been saved, the block created by this view needs to be enabled.

Enabling and Cloning the Backlinks View

To get started, click the Administer | Site building | Views link, or navigate to admin/build/views. As shown in the following screenshot, enable the default backlinks view.

Once we have enabled the backlinks view, we want to clone it. So, we click the Clone link.

Change the View name to conversations, and change the View description to Cloned from default "backlinks" view; displays a list of nodes that link to the node, using the search backlinks table. The View tag can be left blank.

Click the Next button, which brings us to the Edit page for the view.

Editing the Default Display

As shown in the following screenshot, we will make four main edits to this view. We will add Fields, adjust the Arguments, delete the Empty text, and remove the Page display.

To add Fields, click the + icon as indicated, in the preceding screenshot, by Item 1. Add three fields: Node: Post Date; Node: Type; and User: Name. Click the Add button, and then configure the new fields to your preferences.

Next, edit the Arguments by clicking the Search: Links to link as indicated in the preceding screenshot by Item 2. We will edit the argument handling as shown in the following screenshot:

Select the options to only validate for Blog posts and Bookmarks. Additionally, check the option for Validate user has access to the node.

These argument settings confirm that we are only checking for backlinks on Blog posts and Bookmarks. As we add more content types (for audio, video, and images) we will need to update this view to check for backlinks on these additional content types as well.

Click the Update button to store these changes.

Then, we will remove the Empty text by clicking the Filtered HTML link as indicated by Item 3 in the screenshot just above the preceding one. Delete the existing empty text string, and click the Update button to store the changes.

Deleting the empty text makes it so the view will not be displayed if the view returns no content. Although this would not be useful on a Page display, it is useful for a Block display, as this hides the block when there is nothing to show.

Remove the Page Display

As shown by Item 4 in the screenshot just above the preceding one, click the link to show the Page display type.

We are going to be displaying the backlinks in a block, and will not need the Page display. Therefore, we want to remove it by clicking the Remove display button as shown in the preceding screenshot.

Once we have clicked the Remove display button, click the Block link to edit the Block display.

Edit the Block Display

When we are editing the Block display, we will need to edit three values.

Change the Items per page option (as indicated by Item 1 in the preceding screenshot) to 10.

Change the More link option (indicated by Item 2) to No by unchecking the Create more link checkbox.

Change the Admin text under the Block settings option (indicated by Item 3) to conversations.

Click the Save button to save the view.

Then, return to Administer | Site building | Views link, or navigate to admin/build/views, and disable the default backlinks view. Although we used it as a starting point, we now have no further need for it; therefore, we can disable it.

Enabling the Block

As a result of the modifications we have just completed for our new view, we created a block that will display any backlinks when we are looking at Blog posts or Bookmarks. For the final step, we will enable our new block.

Click the Administer | Site building | Blocks link, or navigate to admin/build/block.

We named this block when we adjusted the Block settings as shown in the preceding screenshot by Item 3. The value of the Admin text, which we set to conversations, is the name of the block.

To display the block, use the drop-down menu to select the desired region.

Select Right sidebar, and then click the Save blocks button at the bottom of the page to save the settings.

Seeing It Work

In this article, we have built the framework for the student blog, and started to build out the functionality that will support various types of interaction and discussion between people on the site. Now that we have built out this functionality, it's time to see how it fits together.

The backlinks functionality uses the site's search index to track links. The search index gets updated when cron jobs are run. You can run a cron job manually by navigating to http://yoursite.org/cron.php when logged in as a site administrator. If your backlinks are not showing (or any time search gives you unexpected results) triggering a cron job manually can help resolve the issue.

In this section, we will add some sample content to illustrate the functionality we have just built. To start, add some sample student users. For this example, we will add two new students—lucy and helen.

We will then log in as helen and create two new blog posts. Helen's first post is shown in the following screenshot:

Copy the URL into your clipboard, and then, while still logged in as helen, create another blog post.

When creating this second post, add a link to Helen's first awesome blog post.

To add the link, highlight the text you want to be the hyperlinked, and then click the link icon, indicated by the arrow in the screenshot above. Paste the URL into the Link form, and then click the OK button.

Finally, submit the post.

Next, log out, and log back in again as lucy. As shown in the following screenshot, lucy will click the Student blog link to see what her classmates have been writing.

Lucy will read Helen's first awesome blog post, and after being inspired or motivated by helen's post, lucy will create her own post where she links back to Helen's first awesome blog post.

At this point, both helen and lucy have linked to helen's first post. When we navigate to this, we will see a screen which looks like the following screenshot:

The What links here block that we created earlier in the article shows all posts within the site that link back to this blog post. This allows site members to communicate with one another through comments, or through their own blogs.

Summary

In this article we created the foundation that will support both teacher-led and student-led led interaction. The instructor blog, appearing on the home page of the site, can give structure to the class and provide guidance to students. The student blogs, collected and displayed via the view we created, provides a place for students and teachers to see each other's work, and to provide feedback via comments.

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.