As a site visitor viewing a documentation collection, I want to see a table summarizing the documentation pages within the collection. The table should have documentation page title, first 200 characters or so, and comment count. This is important since it makes it easier for me to find documentation I am interested in.


Figure 10.15: An example of how a collection table may look.

How to demo

  1. Log in to the site and create a documentation collection, if necessary.
  2. View a documentation collection. Verify that its related documentation pages are listed in a table at the bottom of the page, with name, the first 200 characters (or so) of the body, and comment count. Also verify that the title links to the full documentation page.

Preparation

  • The site should have the documentation page and collection content types, as provided by the first exercise in this suite.

Suggested solution

  1. Add a new view with the name documentation pages in a collection, and have it list content of type documentation collection. Create a block displaying a table, and set the title to documentation pages in this collection.
  2. Add a contextual filter content: nid. If no filter value is present, build a default value with content ID from URL. Use validation to assure that only collection node IDs are accepted.
  3. Add a relationship, using the node reference field on the documentation collections. Make sure to use all delta, to collect all related documentation pages. *If using the Entity Reference Module you will be selecting "Entity Reference: Referenced Entity" for this relationship.
  4. Add the documentation page fields you want to display, using the relationship to the documentation page. Make sure to also update the title field, provided by default.
  5. For the documentation page body, either use the trimmed formatter or use the trim this field to a maximum length in the rewrite results settings, to limit the body to 200 characters. Note: In the screencast, there was an error in the field that Johan used. He had attempted to use one of the fields from the Documentation Collection content type instead of using the Body field from the Documentation Page content type. So, to be explicit with this step, choose the Content: Body field and select the Documentation Pages relationship.
  6. Give the view block an administrative title.
  7. In the block administration page, place the new view block at the bottom of the content region.
  8. Change the field display settings for documentation collections, to hide the default output of the documentation page references.

Comments

  • It is logically correct, but not entirely intuitive that you restrict the objects listed in the view to documentation collections – while what's being displayed is documentation pages. It might help thinking of relationships as providing new fields on the object you are listing – the collection gets new fields like collection:page:title and collection:page:body.
  • Make sure that you add the fields used on the documentation page rather than the documentation collection and to select the right relationship in the field configuration. (This comment is directed toward the error that was made in the screencast.)
  • The default order of the relationships will be their deltas – their sorting order in the documentation collection. You could, however, sort by documentation page title or any other available data if you want to override this.
  • The view's limit on items to display relates to the base objects loaded by the view. So that even if you restrict the number of collections to one, all related pages will show. This is similar to how Views would handle a multiple-value field. If the view is configured to display each value as a separate row, each row won't count as a new result in the database query created by Views.
  • At the block administration page, it makes sense to set block visibility to only show at documentation collection pages. The view wouldn't display anything at other pages, but setting the block visibility will prevent Views from ever being called, saving some performance for your site.

The suggested solution should be complemented with links to the relevant sections in this book.

AttachmentSize
09.15 table with docspages.png94.36 KB