1 of 50

Introduction to Views

MidCamp

March 17-20, 2016

Slides: http://bit.ly/midcamp-views-2016

Rate: https://joind.in/talk/d126e

2 of 50

Who am I?

Les Lim

Twitter: @lesmana

IRC: Les_Lim

drupal.org/u/les-lim

Drupal since 2006

Minneapolis, MN

3 of 50

Twin Cities Drupal

Twin Cities Drupal Camp

June 22-25, 2016

University of Minnesota

Law School

4 of 50

Objectives

  • Understand the concept of Views in Drupal, and when a site builder would use them
  • Understand basic configuration options in Views, and how each configuration affects the behavior of the View
  • Gain familiarity with the Views user interface

5 of 50

What is/are Views?

  • “Views” is shorthand for the “Views module”
  • “Views” is a Drupal tool for configuring dynamic lists
  • Views are lists

6 of 50

What is/are Views?

  • “Views” is shorthand for the “Views module”

7 of 50

What is/are Views?

  • “Views” is a Drupal tool for configuring dynamic lists

8 of 50

What is/are Views?

  • Views are lists

9 of 50

What are examples of Views?

Frontpage View

The default Frontpage View is:

  • based on content,
  • formatted as a list being shown as teasers,
  • filtered to show only published content that has been promoted to the front page,
  • sorted to keep sticky content at the top, otherwise more recently created content first,
  • all of which is displayed by Drupal as a page.

10 of 50

What are examples of Views?

Files View

The administrative Files View is:

  • based on files,
  • formatted as a table being shown as columns of fields,
  • exposing filters that allow the user to enter filter values for file name, MIME type, and/or file status,
  • sorted initially by the file’s last changed date, with clickable column headers to sort by different columns,
  • all of which is displayed by Drupal as a page.

11 of 50

What are examples of Views?

“Who’s online” View

The “Who’s online” View is:

  • based on users,
  • formatted as a list being shown as rows of selected fields,
  • filtered to show only active users who have accessed the site in the last 15 minutes,
  • sorted to put more recently online users at the top,
  • all of which is displayed by Drupal as a block.

12 of 50

Five key components of Views

  • Base: what kind of item to list
  • Format: how to arrange and display each item
  • Filter criteria: rules that govern which items go in
  • Sort criteria: rules that govern which items go first
  • Displays: how Drupal should use the View

13 of 50

How are Views configured?

“Who’s online” View

14 of 50

How are Views configured?

“Who’s online” view

15 of 50

How are Views configured?

“Who’s online” view

Name of view (base)

List of View displays

16 of 50

Displays

  • Displays represent different forms a View may take

  • Les Lim – one display
  • Optimus Prime – two displays

17 of 50

Displays

  • You can configure any number of displays for a View

18 of 50

Displays

  • The type of display determines how Drupal will use the display

    • Attachment: a display appended to a different View display
    • Block: the display is available to be placed in Drupal’s block placement interface
    • Embed: Drupal itself does nothing with this display, but another module may execute it
    • Entity Reference: the display is used when configuring a Reference field to determine what may be referenced
    • Feed: the display is output as an XML or other type of feed
    • Page: the display is given a URL path and is the main content for that path

19 of 50

Displays

  • Example: Frontpage View�Contains two displays
    • Page display (left)
    • Feed display (below)

20 of 50

Displays

  • Most Views should only need one display
  • Multiple displays can be super confusing and frustrating
  • If you think you need two displays, consider whether you actually need two different Views

21 of 50

How are Views configured?

“Who’s online” view

List of View displays

View operations

Display configuration

for “Who’s online” display

Display operations

Save/cancel changes (applies to all displays in the View)

22 of 50

Editing display configurations

  • Each link opens a modal window with editing options
  • Configuration changes can be applied to all displays in the View, or just the current one

23 of 50

24 of 50

Editing display configurations

25 of 50

Formatting

  • Two components:
    • Format: How to arrange the rows in the view. Sometimes called “Style format”.
    • Show: The method used to build the content of each row. Sometimes called “Row format”.

26 of 50

Formatting

  • Format component options
    • Grid
    • HTML List
    • Table
    • Unformatted List
  • Contrib modules may provide other formats

Grid

Table

27 of 50

Formatting

  • Each format option has its own additional settings

Grid

28 of 50

Formatting

  • Show component options
    • Fields: Pick and choose individual fields to display
    • “User”, “Content”, “File”, etc: display each entity using one of those entity’s display modes

29 of 50

Formatting

  • Each “Show” option also has its own additional settings
  • When not using Show: Fields, the “Fields” configuration is not used.

30 of 50

Formatting

  • Example:
    • Format: Grid� Columns: 2
    • Show: User� View mode: Compact

31 of 50

Fields

Determines which pieces of information to show for each row

Any number of fields may be added

32 of 50

Fields

“Add fields” lists all fields available for inclusion in this display

“Search” and “Type” filters can help you find the intended

33 of 50

Fields

Each field has its own configuration settings

The Formatter determines how the field value will be rendered

34 of 50

Fields

Style Settings:

  • Customize the HTML used to wrap the field

35 of 50

Fields

Rewrite Results:

  • Change the output of the field
  • Can use the value of other fields as replacement tokens

36 of 50

Fields

Rewrite Results:

User Email field, re-written with custom text and tokens replaced with values

37 of 50

Fields

No results behavior:

  • What to do with this field, if the field has no value

38 of 50

Fields

Fields can be re-ordered or removed from the display using the “Rearrange” action

39 of 50

Filter criteria

  • Rules that determine which items are shown in a display
  • Adding, rearranging, and removing filters works the same as fields

40 of 50

Filter criteria

  • Operator: the type of comparison being made
  • “Filter to users whose last access time is greater than or equal to 15 minutes ago.”

41 of 50

Filter criteria

  • Exposed filters allow the value to be set by the end user
  • Works best with Page displays – possible but complicated with other display types

42 of 50

Sort criteria

  • Rules that determine the order in which rows are displayed
  • Priority is with the topmost sort criterion
  • Additional sorts are only germane if the previous sort is a tie

43 of 50

Sort criteria

  • Exposed sorts allow the sort order to be selected by the end user
  • Can select between ascending and descending order

44 of 50

Creating a View

  • Scenario: A website for a farmers market
  • Content type for Vendors
  • Content type for Recipes, submitted by Vendors
  • Same scenario used in the Drupal 8 User Guide project (www.drupal.org/project/user_guide)

45 of 50

Creating a View

  • “Can we have a page that shows all of the vendors on the site?”

46 of 50

Five key components of Views

  • Base: What kind of item are we listing?
  • Format: How should the items be arranged and displayed?
  • Filter criteria: Which items should be included or excluded?
  • Sort criteria: What order should the items follow?
  • Displays: how should the View be made available in Drupal?

47 of 50

Creating a View

“Can we have a page that shows all of the vendors on the site?”

  • Base: Content
  • Format: Unformatted list, teasers
  • Filter criteria: Only vendor content, only published content,
  • Sort criteria: Alphabetically by vendor title
  • Displays: Page

48 of 50

Creating a View

  • Creating a new View starts with the “Add new view” setup wizard
  • Fills in simple configuration

49 of 50

(video goes here)

50 of 50

Rate this talk!

https://joind.in/talk/d126e

All comments welcome.