Note: Have to have database logging module enabled (often gets turned off in production, this deletes the view!)
Views Settings
Let's setup Views for success.
Setup tips for debugging
Go to Views Settings
Turn on Show SQL query
Turn on Show performance Statistics
Most of us have made a basic view
Show [view_type (entity)] of type [types_of_this_entity] tagged with: [core_tags] sorted by: [views_sort]
We have a deadline... let's do this quick!
Screenshot of basic view making
Screenshot of basic view
But what are we really building and why?
Lists of Data, displayed in different ways.
Things get complicated really fast.
View Types
View types are not just content, they can be any entity, and a few non-entity extras
Make sure you choose the right view type, so that your relationships work later on
Contrib modules can add additional view types
Filters
This is the large set of data.
Start by getting this correct.
Then you can get more sophisticated with display, sorting, contextual filters and relationships.
Sorts
The order we want to see things in. This is pretty straight forward, but there's more here...
Sorts and Exposed Filters
This is where sorts get powerful. We can set up complex sorts that the user can manipulate.
Adding an exposed filter
Create View
Add Filters
Select "Expose to visitors"
Basic view with exposed sorts (filters)
Change the view filter names
Example of the view with Filters
Advanced Options for Views - Exposed Forms
Advanced Options for Views - Exposed Forms Options
Adding tabs to views
Contextual Filters
Filters from somewhere else (not on this content)
Where regular filters are a broad stroke, Contextual Filters are details.
Screenshot of Contextual Filters
Basic Contextual Filter Options:
What the filter should do if there isn't a value in the URL
What the filter should do if there is a value, (and therefore include any default values from the first section)
Some other options that are independent of how the value gets set
Some Options Explained:
Content ID from URL: 333 from '/node/333'
Taxonomy Term ID: 444 from '/taxonomy/term/444'
User ID from logged in user: 555 from '/user/555' (note: anonymous is 0)
User ID from route context: User ID from D8 Symphony, can also look at author ID
More Options Explained:
Raw value from the URL: each slash is an argument
So: argument '2' would be 'structure' from '/admin/structure/types'
Query parameters: each query is an argument
So: argument 'harry' would be '777' from /admin/structure/types/?harry=777&sally=888
Fixed: any 'hardcoded' value (not flexible, I just want to say the value right here)
Relationships
Links two entities together
If there is an entity reference (this includes taxonomy terms) there can be a relationship.
Without the relationship ALL the view can display is the ID of the entity that is referenced by the Entity ID.
Diagram of Relationships
One to many, many to one
MAKE SURE YOU GO THE RIGHT WAY or you’ll take a performance hit.
Content referenced from field_job_company this is what you want.
Content using field_job_company this is the reverse relationship.
Stretch
Please stand up
and chat with your neighbor
ask them where they grew up.
Let's Make Some Views!
Examples of contextual filters and relationships
A view with a contextual filter
Adding a relationship
Wrong way to do contextual filters
Advanced Features
Descriptions of Advanced Features
Machine name: Add to target with code (a default will be added).
Administrative comment: Just add a note.
Use Ajax: See next slide.
Hide attachments in summaries: relates to attachment view type (kind of a corner case).
Advanced Features - AJAX
Use Ajax: YES!
Do this if you have exposed filters, or dynamic views.
Options such as paging, table sorting and exposed filters will not need a page refresh!
Use this unless it breaks things (more than one view on a page may break the AJAX).
More Descriptions of Advanced Features
Use Aggregation & Query Settings: change the fundamentals of views and how SQL queries
are generated. Use if you have complex SQL problem.
Administrative comment: just add a note
Caching: see next slide
CSS class: Add a class to the view wrapper.
Advanced Features - Caching
Caching: YES!
Time based: Wait for some period of time, then rerun query. You might not see updates
right away. (This is the old way from D7 and before - legacy option!)
Tag based: Default and D8 way! D8 puts tags everywhere that let keep track of what is
related to what. When one tag changes, D8 keeps track of other changes that also might
need to be made.