Drupal 7 : Staging Content on Views

The ‘Preview’ functionality in Drupal, that allows you to see how a node is rendered in Drupal, before it is saved and Published, is not always fully useful to ‘preview’ or ‘stage’ your content. Reasons could be many - One of them being - It simply would not working if you are using Views to display your node!. Until the node is published and saved, it may not be possible to preview how the node will be displayed in the view.


Example: Here is a View on the homepage from one of my sites and I would like to preview how the thumbnail is (auto) cropped, where the teaser is trimmed etc, before publishing the node.

Previewing your node in Views will help

  • If you have views displaying your node(s) - Ex: Slider Images and Teasers on the homepage of your site
  • If you are using a View to display a single node by overriding node/nid with a View

This article proposes a solution which allows users with specific roles on your drupal site to draft a node and save it in unpublished state, and preview associated views with the unpublished content.

Consider you have a drupal site, where you publish content of type ‘article’. The teasers of such articles are shown on your site’s home page using a view. Also consider your site, has users with a role, say ‘Editor’, to whom you would like to grant the privilege of staging unpublished content.

Requirements:

  • You will need to decide upon

    • The content types you wish to be allowed to be staged (‘article’ in this case)

    • The roles of the users who should be able to stage content (‘Editor’ in this case)

    • And obviously the view which is displaying content - assuming that you already have the views module enabled with a view displaying content, probably on your homepage

  • Download and Enable ‘Flag’ module

The Solution:

  1. Flag module can be administered for admin/structure/flags . Flag module, provides a default flag called ‘Bookmark’. You may delete this flag, or simply disable it for all content types, as we would not be using it.

  2. Start by creating a new flag at admin/structure/flags/add as described:

    1. Flag name => stage_for_preview

    2. Flag type => Node

    3. Title => Stage For Preview

    4. Global flag => Unchecked

    5. Flag link text => Stage this node for preview

    6. Unflag link text => Unstage this node

    7. Roles that may use this flag => Check the boxes under both Flag and Unflag for Editor

    8. Bundles => Article

    9. You may leave all other options to defaults


      Once you save the flag, you will notice that under all content of type articles you can now see a link called "Stage this node for Preview". When Clicked it will turn to "Unstage this node" Link. We will be using these links later to stage and unstage content for previewing.

  3. Next, the View which is displaying the content, needs to be modified a bit. Edit the View. Let us assume that the view currently has the following filters as shown below

    1. Content: Type = article

    2. Content: Published = Yes

  4. While Editing the View, under Relationships add a new relationship by clicking on the ‘add’ link against Relationships

    1. Enable the checkbox - "Flags: Node flag" and click on “Apply (all displays)”

    2. Uncheck Include only flagged content

    3. Under Flag , select stage_for_preview

    4. By => Current user

    5. Save the relationship by Clicking on “Apply (all displays)”

  5. While Editing the View, under Filter Criteria, add a new filter by clicking on the ‘add’ link against Filter Criteria

    1. Enable the checkbox - “Flags: Flagged” and click on “Apply (all displays)”

    2. Under Relationship, select flag from the dropdown

    3. Status => Flagged

    4. Save the filter by Clicking on “Apply (all displays)”

  6. Now you have an additional filter in your view, which allows only the nodes flagged by the current logged in user, to be displayed. By default, views adds all filters by ‘and’ operator. Click on the drop-down arrow link beside the ‘add’ link against Filter criteria and click on “And/Or, Rearrange”. This page allows you to group filter criteria and the operators connecting the filters. Click on “Create new filter group” and then group your filters as shown in the below pic, by drag-and-drop. Then click on “Apply (all displays)” to save the rearranged filters.


    Here we are telling the View, to display not just the published articles but also the ones which have been flagged for staging by the current user who is seeing the view.

  7. Don't’ forget to save the View now!

Bingo,. now if any of your editor wishes to preview the node, all he/she has to do is :

  • Save the node in unpublished status

  • Click on "Stage this node for Preview" link on that node

  • Navigate to the page containing the view and the Editor can see the unpublished node in the view (because the node was staged by the editor)

  • If the Editor is satisfied with the preview on the node, (s)he can open the node, unstage it by clicking on the “Unstage this node” link and Publish the node

  • If the Editor is not satisfied by the preview, he/she can edit the node and preview the changes simultaneously while saving the unpublished node.

The unpublished node, which is ‘Staged for Preview’ is visible on the view only to the logged in Editor.

 

Comments