Create A "My Content" View For Your Drupal Website

It's funny how you are working on finding a solution to a problem and you end up finding something interesting that distracts you from your original problem. That's what happened to me and I ended up creating the My Content view, write this article, and still haven't solved my original problem which had something to do with grouping authors. I wanted an easy way to view the articles that I had published and also the articles that I hadn't published yet. As far as I know there is nothing out of the box that allows you to do this. A view of some sort I thought would be the best option. I also wanted the content listed in the view to be based on who is logged on the site. Let me show you how I went about creating the view.

Modules Required

  • View

After you have installed the View module, go to Admin Menu>Structure>Views. Click on Add A New View.

view1

In the view name field type the name you want to call it. The page title will default to this name but you can change it if you wish. Set the other settings as shown above. Click continue and edit.

viewsettings1

Relationships

Relationships are basically a join between tables. The node table only has a reference to the user who created the node by the user id. Thus we create a relationship to the user table so we have access to the user information. Click the Add button in the Relationships box.

ViewsettingsRelationship1

Click on Content: Author and click Add and Configure Relationships. In the Identifier box you can put something more descriptive. Leave the rest as default and Apply.

ViewSettingsRelationship2

 Next find Show under Format. We don't want content, we want fields. Click on content.

FormatShow1

Select fields and click Apply. The Page: Row Style Options page will come up. Click Apply. The default field Content: Title is displayed and we actually want this. If you scroll to the preview at the bottom you will see a list of titles. Pretty cool! Let's add a couple of fields. Click the Add button. You will see a very long list of fields that we can choose from. Click on Content: Published and User: Name. Click on Add and Configure Fields. The Configure field: Content: Published page is now shown. For now we will leave the default settings. Click Apply.

FieldsConfigure1

Do the same with the Configure field: User: Name page and use the defaults. Click Apply. Scroll down to the preview section and you will see what we have created so far. Under Filter Criteria you will see the field, Content: Published (Yes). Let's remove this filter because we also want to see our unpublished content. Click on Content: Published (Yes) and then click on the Remove button. 

Contextual filters

 There are different contexts a filter value can come from but mainly it comes from the URL. You can also instruct Views to look elsewhere such as id of the user that is logged in. Let's add Content: Author uid and click Add and Configure Contextual Filters.

ContextualFilter1

 You are now on the Configure contextual filter: Content: Author uid page. 

ContextualFilter2

 Click Provide default value and select User ID from logged in user. Click Apply. Depending on how you use your login there may or may not be anything in the preview at the bottom. In my case, the Admin login doesn't have any content written so nothing is showing. Click Save. This is how your settings should look:

ViewSettings2 You can click on view page and see the finished view. You can grab the Path in Page Settings and create a menu item with it. This completes our view. Experiment with some of the settings to get the look you want. 

Author: Christian Apostolu
Christian Apostolu's picture
About:

Owner/founder of Crush The Soul, software developer, amateur athlete, frustrated musician. 

"Once we accept our limits, we go beyond them." - Albert Einstein

 

Category: