Setup, Intro Views Basics Argument Handling Tabbed Views Templating Fusion / Union A Break From Views Actions Workflow Workflow_NG CCK Computed Field  (time permitting) Development Tips phpED demo Multisite for Multi-User More Views  (time permitting) Views_build_view() Views and AJAX Views_Calc Morning : 8 to 12 Afternoon : 1 to 5 BREAK BREAK LUNCH
What is VIEWS?  http://av1.example1/admin/build/views/add   A smart SQL query builder (plus extras) By default –  “a view is a list of ALL site nodes” … but… …  this is more useful when we FILTER to show only specific nodes Arguments and filters can be set to limit which  nodes  to “list” Can also: select which fields to use sort theme
Keep in mind – views lists nodes.  (Exercise 1, 1a) Drupal saying:  “everything’s a node” … but, of course, not really everything… Lots of things in Drupal aren’t natively nodes” Users Taxonomy terms Comments And others But there are modules to make most of these things into nodes… so then they can be used with views..  
Page or Block Very similar except Block Views automatically show in the Block admin page so block functions apply (page filters, per theme, weightings, etc) View Type List ( ALWAYS use this to theme ) Table – nice if you want to throw together a quick table Teaser – very handy if you theme a teaser (contemplate) and have many views that use same teaser template Other modules can add other types (RSS, etc)
Fields – Table and List only Pick which fields to show on your view Filters and Arguments Pick which nodes to show Arguments: use $_GET (i.e. URL) to pass arguments to use for filtering (more on this later) Exposed Filters Let users chose filtering options  (Exercise 2) Sort
Arguments are basically filters But we can  take  arguments from URL to use in our filters  (Exercise 3) Why  take  instead of  pass ? Block views can also read from URL Argument handling code (PHP) allows us to convert argument into what the filter is designed to handle Think of: better to have URL with text but need ID for filter. But also other uses: Embed into the views array  ( http://av1.eclipse/archived )  Handle end cases – i.e. filter bad arguments  ( http://av1.training/user/blah/my_widgets )  (Exercise 6)
Used to collect multiple views together on single page  (Exercise 4) Views automatically builds tabbed pages for you based on path provided Can also add to existing pages such as User, or other existing tabs created by 3 rd  party modules  (Exercise 5)
Easiest approach is to theme a node type’s teaser and then just use teaser views… …  but when that’s not enough… Views provides very powerful templating support. Basic approach  (Exercise 7) List view  (only LIST views work for templating) Select required fields Use views Theme Wizard to get code for template.php, views-list-[view_name].tpl.php, views-list-[view_name].css
All tpl files belong in the theme folder LiquidCMS Enhancements: Support for multiple themes by better use of “default theme” concept (Drupal 5) Views_templater() function to simplify template.php code  Drupal 6 has much better theming support through the use of hierarchical themes
Allows user to pull in  “related”   information Nodes need to use some form of relational linking to join them together Node_family set of modules or CCK nodereference field are currently supported – but most cases you will want to use nodereference field Examples: numerous examples on  http://av1.umg
Simply ORs multiple views together  (Exercise 8) A bit tricky when using views with arguments or exposed filters Drupal 6: both views_union and views_fusion modules have been made obsolete by Drupal 6 as Views 2 handles node relationships. This is a VERY good thing as both these modules are a bit flaky.
 
An action is a specially written PHP function whose parameters are configured through the web. Action templates may be added by other modules and then the site admin may add instances of this action by filling out template.  ( http://av1.workflow/admin/build/actions )  Actions include things like sending an email or changes workflow state of a node. Modules can then call these actions when needed
Workflows define “states” for different node types And then help us manage the transition of nodes through this “state machine” Add on modules provide various functionality driven by a node’s state – for example: Fire an action (e.g. send an email) when a node passes from one state to another Control access privileges based on the state a node is in
“ A rule-based event driven action evaluation system.” Much different than Workflow – whereas Workflow only manages tracking a nodes states, _NG provides a configurable action system with it. Sort of like combining Actions and Workflows – but these aren’t standard Drupal Actions – but for Drupal 6, workflow_ng will support Drupal actions.
Lets you add a computed (i.e. PHP) field to a custom content type Choose whether to store your computed field in the database.  Value of the field is set using PHP code so it can draw on anything available to Drupal: other fields the current user database tables etc. More info:  http://drupal.org/node/126522
PHP Debugger (NuSphere) If you are doing code design - a debugger is your most powerful tool LiquidCMS recommendation: phpEd  ( http://www.nusphere.com/ )   Breakpoints, including conditional breakpoints Traverse call stack Remote debugging PHP and MySQL manuals built in Look up user defined functions, php functions, files with simple right click  DEMO
Use Drupal’s multisite capabilities to help with multi-developer environments. Create a site folder per user: site1.jayson, site1.adam, site1.joe Along side: www.site1.gc.ca, stage1.intranet, etc Each user can set specific site “variable” settings using their custom $conf array in settings.php Developers can add their own modules under sites/mysite/modules folder that other users won’t see
Devel Many useful tools including SQL query report www.drupal.org/project/devel   Coder Highlights proper coding style www.drupal.org/project/coder   Masquerade Easy switching between other user www.drupal.org/project/masquerade
LiquidCMS Devel Modules: Php_errors: monitors php errors which are occurring on your site, archives a weekly list, emails report to defined roles -  www.drupal.org/project/php_errors   Mail_redirect: when using db with “live” email addresses; this module prevents spamming users during testing and redirects all site email to test mail domain – see  www.drupal.org/projects/mail_redirect  for more info
Programatically call a view Endless uses: Call a view inside a view template to get embedded views Great for AJAX calls Examples: http://av1.umg/artist/amy-winehouse http://av1.umg/search-main/ http://av1.umg/artist-news/snoop-shoots-jay-z
Module adds simple calculations to a views table.  You can SUM, AVERAGE, or COUNT a selection of fields in a row, or perform the same calculations on selected columns. Gives spreadsheet like capabilities to Table views.
Exercise 1: All Widgets  (all_widgets) Basic Exercise 1a: My Widgets  (admin_widgets, my_widgets) Simple filter Exercise 2: Pick User’s Widgets  (pick_widgets) Exposed filter Exercise 3: User’s Widgets  (users_widgets) Simple argument handling Dynamic titles
Exercise 4: Tabbed Widget’s (Users) Widget page with a tab for each user’s widgets Exercise 5: MyAccount Tab  (myaccount_widgets) Add tab to existing tab sets Exercise 6: MyAccount Tab  (myaccount_widgets) Arg handling code Exercise 7: View Templates  (admin_widgets2)   Exercise 8: Views Union  (robyn_s_admin_w) Join 2 views together using the views_union module

Dn D Custom 1

  • 1.
  • 2.
    Setup, Intro ViewsBasics Argument Handling Tabbed Views Templating Fusion / Union A Break From Views Actions Workflow Workflow_NG CCK Computed Field (time permitting) Development Tips phpED demo Multisite for Multi-User More Views (time permitting) Views_build_view() Views and AJAX Views_Calc Morning : 8 to 12 Afternoon : 1 to 5 BREAK BREAK LUNCH
  • 3.
    What is VIEWS? http://av1.example1/admin/build/views/add A smart SQL query builder (plus extras) By default – “a view is a list of ALL site nodes” … but… … this is more useful when we FILTER to show only specific nodes Arguments and filters can be set to limit which nodes to “list” Can also: select which fields to use sort theme
  • 4.
    Keep in mind– views lists nodes. (Exercise 1, 1a) Drupal saying: “everything’s a node” … but, of course, not really everything… Lots of things in Drupal aren’t natively nodes” Users Taxonomy terms Comments And others But there are modules to make most of these things into nodes… so then they can be used with views.. 
  • 5.
    Page or BlockVery similar except Block Views automatically show in the Block admin page so block functions apply (page filters, per theme, weightings, etc) View Type List ( ALWAYS use this to theme ) Table – nice if you want to throw together a quick table Teaser – very handy if you theme a teaser (contemplate) and have many views that use same teaser template Other modules can add other types (RSS, etc)
  • 6.
    Fields – Tableand List only Pick which fields to show on your view Filters and Arguments Pick which nodes to show Arguments: use $_GET (i.e. URL) to pass arguments to use for filtering (more on this later) Exposed Filters Let users chose filtering options (Exercise 2) Sort
  • 7.
    Arguments are basicallyfilters But we can take arguments from URL to use in our filters (Exercise 3) Why take instead of pass ? Block views can also read from URL Argument handling code (PHP) allows us to convert argument into what the filter is designed to handle Think of: better to have URL with text but need ID for filter. But also other uses: Embed into the views array ( http://av1.eclipse/archived ) Handle end cases – i.e. filter bad arguments ( http://av1.training/user/blah/my_widgets ) (Exercise 6)
  • 8.
    Used to collectmultiple views together on single page (Exercise 4) Views automatically builds tabbed pages for you based on path provided Can also add to existing pages such as User, or other existing tabs created by 3 rd party modules (Exercise 5)
  • 9.
    Easiest approach isto theme a node type’s teaser and then just use teaser views… … but when that’s not enough… Views provides very powerful templating support. Basic approach (Exercise 7) List view (only LIST views work for templating) Select required fields Use views Theme Wizard to get code for template.php, views-list-[view_name].tpl.php, views-list-[view_name].css
  • 10.
    All tpl filesbelong in the theme folder LiquidCMS Enhancements: Support for multiple themes by better use of “default theme” concept (Drupal 5) Views_templater() function to simplify template.php code Drupal 6 has much better theming support through the use of hierarchical themes
  • 11.
    Allows user topull in “related” information Nodes need to use some form of relational linking to join them together Node_family set of modules or CCK nodereference field are currently supported – but most cases you will want to use nodereference field Examples: numerous examples on http://av1.umg
  • 12.
    Simply ORs multipleviews together (Exercise 8) A bit tricky when using views with arguments or exposed filters Drupal 6: both views_union and views_fusion modules have been made obsolete by Drupal 6 as Views 2 handles node relationships. This is a VERY good thing as both these modules are a bit flaky.
  • 13.
  • 14.
    An action isa specially written PHP function whose parameters are configured through the web. Action templates may be added by other modules and then the site admin may add instances of this action by filling out template. ( http://av1.workflow/admin/build/actions ) Actions include things like sending an email or changes workflow state of a node. Modules can then call these actions when needed
  • 15.
    Workflows define “states”for different node types And then help us manage the transition of nodes through this “state machine” Add on modules provide various functionality driven by a node’s state – for example: Fire an action (e.g. send an email) when a node passes from one state to another Control access privileges based on the state a node is in
  • 16.
    “ A rule-basedevent driven action evaluation system.” Much different than Workflow – whereas Workflow only manages tracking a nodes states, _NG provides a configurable action system with it. Sort of like combining Actions and Workflows – but these aren’t standard Drupal Actions – but for Drupal 6, workflow_ng will support Drupal actions.
  • 17.
    Lets you adda computed (i.e. PHP) field to a custom content type Choose whether to store your computed field in the database. Value of the field is set using PHP code so it can draw on anything available to Drupal: other fields the current user database tables etc. More info: http://drupal.org/node/126522
  • 18.
    PHP Debugger (NuSphere)If you are doing code design - a debugger is your most powerful tool LiquidCMS recommendation: phpEd ( http://www.nusphere.com/ ) Breakpoints, including conditional breakpoints Traverse call stack Remote debugging PHP and MySQL manuals built in Look up user defined functions, php functions, files with simple right click DEMO
  • 19.
    Use Drupal’s multisitecapabilities to help with multi-developer environments. Create a site folder per user: site1.jayson, site1.adam, site1.joe Along side: www.site1.gc.ca, stage1.intranet, etc Each user can set specific site “variable” settings using their custom $conf array in settings.php Developers can add their own modules under sites/mysite/modules folder that other users won’t see
  • 20.
    Devel Many usefultools including SQL query report www.drupal.org/project/devel Coder Highlights proper coding style www.drupal.org/project/coder Masquerade Easy switching between other user www.drupal.org/project/masquerade
  • 21.
    LiquidCMS Devel Modules:Php_errors: monitors php errors which are occurring on your site, archives a weekly list, emails report to defined roles - www.drupal.org/project/php_errors Mail_redirect: when using db with “live” email addresses; this module prevents spamming users during testing and redirects all site email to test mail domain – see www.drupal.org/projects/mail_redirect for more info
  • 22.
    Programatically call aview Endless uses: Call a view inside a view template to get embedded views Great for AJAX calls Examples: http://av1.umg/artist/amy-winehouse http://av1.umg/search-main/ http://av1.umg/artist-news/snoop-shoots-jay-z
  • 23.
    Module adds simplecalculations to a views table. You can SUM, AVERAGE, or COUNT a selection of fields in a row, or perform the same calculations on selected columns. Gives spreadsheet like capabilities to Table views.
  • 24.
    Exercise 1: AllWidgets (all_widgets) Basic Exercise 1a: My Widgets (admin_widgets, my_widgets) Simple filter Exercise 2: Pick User’s Widgets (pick_widgets) Exposed filter Exercise 3: User’s Widgets (users_widgets) Simple argument handling Dynamic titles
  • 25.
    Exercise 4: TabbedWidget’s (Users) Widget page with a tab for each user’s widgets Exercise 5: MyAccount Tab (myaccount_widgets) Add tab to existing tab sets Exercise 6: MyAccount Tab (myaccount_widgets) Arg handling code Exercise 7: View Templates (admin_widgets2) Exercise 8: Views Union (robyn_s_admin_w) Join 2 views together using the views_union module

Editor's Notes

  • #2 table, list and teaser views View tabs Argument handling Views templating/theming filters and exposed filters Views Modules: View calc fusion and union of views usernodes Non-Views: Actions, workflow, workflow_ng CCK Computed field Advanced: views_build_view function and how to use views in ways you'd never think of query substitution - when you can't quite get it right. ajax and views