Wednesday, August 12, 2009

Administer specific content types in drupal using views

As we know site content can be edited/deleted on admin/content/node page but this page is accessible to only those users whose have been granted permission for 'administer nodes' from admin/user/permissions page. Sometimes we want to give users edit/delete permissions for specific content types. Say we have a new Editor type role who should have add/edit/delete permission to some specific content types blogs, story. If we grant 'administer nodes' permission to Editor role, Users of editor type role will be able to add/edit/delete all type of nodes and will have complete access to admin/content/node page so we can not grant this permission to Editor.
First we need to assign following specific permissions to editor role from admin/user/permissions page
  • create blog entries
  • delete any blog entry
  • delete own blog entries
  • edit any blog entry
  • edit own blog
  • and add permissions for story content type or other content types as per your requirement.
Now While viewing a node of blog or story content type Editor will be able to edit these particular node types and can directly access edit page for these nodes from node/(nid)/edit. But our requirement is bit different we want a page like admin/content/node where Editor will be able to view list of story and blog nodes and can edit/delete both node types.
We are going to use views to resolve this as we have already assigned permission to editor for these two type of nodes the only one thing left is to create a page like admin/content/node.
So here we go.....

  1. Create a new view from admin/build/views/add. Enter View name, View description as per your need . select Node from view type. See image below
  2. Click next
  3. Add 'page' type display. See image below.
  4. Add path 'editor/page-blog/edit' under page settings. you can choose your own path where this view will be rendered.
  5. Fields : Select Node Title, Node Edit Link, Node Post date. See image below
  6. Basic Settings : Set the basic settings for following. See the image below
  7. Basic Settings : style type: table, Use pager: yes , etc
  8. Basic Settings : Check sortable for Title and Post date style type settings. See the image below.
  9. Now select filters Node published(exposed), Node title (exposed) and Node type(exposed). If you are selecting Filter:Node type exposed you have to be very careful while selecting the exposed settings. Must see the screen shot for Node type: exposed after point 22.
  10. When you press expose button for Node:Published you will see following fields. See the screen shot below select highlighted radio and check box.
  11. Node:Title exposed settings screen shot is below. Select the settings as highlighted.
  12. Select Node types Blog entry and story For filter:Node types. See the screen shot below for exposed settings.
Save the view and goto URL you have specified for Views: Page settings :path . For this case I have specified editor/page-blog/edit . By mistake I've specified path editor/page-blog/edit instead of editor/story-blog/edit. . This path has nothing to do with data rendered by view, but it looks better if we specify a sensible path depending on page data.

See the screen shot below for the view just created.


We can add one more field Node type as well which also could be made sortable like Title and Post date.

2 comments:

  1. Very good stufff...really helped me a lot!!

    i will follow you on twitter!!!!

    thanks

    ReplyDelete
  2. Really very effective stuff

    I really appreciate you for your hard work.
    It will be very helpful for beginners and intermediators.

    Thanks

    ReplyDelete