Views for
Developers

DrupalCon Denver March 2012

Photo by S Baker

Fotopedia

By Bevan Rudge, PreviousNext

Drupal.geek.nz

Twitter.com/BevanR

PreviousNext.com.au

Photo by S Baker

Fotopedia

By Bevan Rudge, PreviousNext

Drupal.geek.nz

Twitter.com/BevanR

PreviousNext.com.au

Learn to:

1
Reuse existing features

2

Add new
& custom features

Construction is difficult

Lots of moving parts

By decade_null (Flcikr)

By decade_null (Flcikr)

Simple
solutions for
complex problems

"Don't tell me how complicated
the problem is

Tell me how
simple your solution is."

Views is

Awesome

Build awesome

stuff with it

ByJoi Ito, Fotopedia

Views is

Awesome

Build awesome

stuff with it

ByJoi Ito, Fotopedia

Developed by

Palantir.net

Developed by

Palantir.net

Developed by

Palantir.net

Developed by

Palantir.net

Developed by

Palantir.net

Developed by

Palantir.net

Developed by

Palantir.net

Developed by

Palantir.net

Custom code is expensive

  • It takes time to implement
  • It is buggy & needs fixing
  • Upgrading it takes time
  • Adding features takes time

Time is money

Before you extend,

Can you bend?

Know more config

Write less code

Anatomy of a View

Custom markup for fields

No wrapper elements be default

Duplicate Views field configuration?

or

Drupal "View Modes"

e.g. "teaser", "full" and

Duplicate Views field configuration?

or

Drupal "View Modes"

e.g. "teaser", "full" and

Or Fences module

extends field configuration

Or Fences module

extends field configuration

Field concatenation

Render field as (custom) link

Display custom text for empty fields

Summary views

AND/OR filters

Contextual Filters are always in the first group, even though they do not appear in the UI.

So you could OR contextual filters if you want.

Result summaries (Pager summaries)

Result summaries (Pager summaries)

Aggregate/COUNT queries

Alternative pagers: Date

Alternative pagers: Alpha/Glossary

Review

  • Don't write custom code (if you can avoid it)
  • Seek simple solutions
  • Anatomy of a view
  • Custom markup for Fields
  • Field concatenation
  • Fields as custom links
  • No Results Behaviour for Fields
  • Summary views

Review

  • AND/OR configuration for Filters
  • And for Contextual Filters
  • Result Summaries
    E.g. "Showing 1-7 of 17 items"
  • Aggregate/COUNT queries
  • Date-based pagers
  • Alphabetical "Address book" style pagers
  • Views Link Area module for links in Header/Footer/Empty Areas

Learn to:

1
Reuse existing features

2

Add new
& custom features

Documentation

Classes you can extend

Exposing a class to views

  • Implement hook_views_api()

Exposing a class to views

  • Implement hook_views_api()
  • Create a subclass of the appropriate Views class

Exposing a class to views

  • Implement hook_views_api()
  • Create a subclass of the appropriate Views class
  • Expose the class/include in the *.info file

Exposing a class to views

  • Implement hook_views_api()
  • Create a subclass of the appropriate Views class
  • Expose the class/include in the *.info file
  • Expose the class via hook_views_data()

Review

  • Documentation
  • Object-oriented class hierarchy
  • How Views Link Area module extends Views to expose an Area Plugin
    • Implement hook_views_api()
    • Create a subclass of the appropriate Views class
    • Expose the class/include in the *.info file
    • Expose the class via hook_views_data()
  • What classes are for which configuration features in the Views UI