Views Configuration at Drupal Camp Toronto 2012

2,525 views

Published on

So you know how to use Views, but feel like you're just scratching the surface. Views is a powerful module that allows you to build out complex functionality with just a few clicks of the mouse. This session will cover some of the more advanced features of the Views and take your knowledge of Views to the next level.

Topics include:
Changing the Results (adding more data, filtering options)
Contextual Filters (Arguments)
Relationships: Pulling in Related Data to Views
Formatting Views and Changing the Markup
Creating Administrative and Interactive Views
Extending Views with Other Modules

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,525
On SlideShare
0
From Embeds
0
Number of Embeds
206
Actions
Shares
0
Downloads
30
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Get people to open their manuals, and check out the “before you start” activity. This is an activity for people who arrive early. It is optional. Whether they are familiar with this technique or not, it is useful. Wireframes can make it easier for participants to communicate their questions. Go around and try to get familiar with the kinds of projects students are interested in, find some commons threads you can bring up later. \n
  • Fill in information about your company!! Or ALT+TAB to your own site, or add in your own slides.\n
  • With these things, you can create\n
  • First frame the problem that Views was made to conquer. \n
  • This is an example of custom PHP development - combining queries, logic and display. You’d connect to your database, gather data, and then display it- in this case the HTML output is a table. Later if you wanted to change the query or change the output, you’d have to edit code like this.\n
  • Each time you make a new View you start with the wizard. Note: when you select Show content/users/taxonomy- that is the base table and you can’t change that later.\n
  • You can get most things done right from within the wizard. Note that the WIZARD disappears after your initial set up.\n
  • And when you want to access the advanced settings, there is the full UI. \n1. You can change for example, if content is listed in a TABLE or in a bulleted list. \n2. You can add filters, and change the default sort orders. \n3. You can specific what path it’s on and who can access it. \n4. You can relate content to other content by checking the context. \n
  • First you select the kind of information you want to query. Views can query Content, users, taxonomy and comments. This cannot be changed afterwards. Say for example, you want to query content. \n
  • You can then pull individual fields to display, instead of showing the whole record. Views can then be output in a number of formats. As an HTML list, or just showing two specific fields, as a sortable table, or as points on a map, using a mapping module to extend Views.\n
  • Content can be output in various ways. For example, as a page with a full path. Or as a block that can be placed in the layout. Or as an RSS feed, attachment, etc. We’ll see how to do this soon!\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • You can WAIT to do this part of the presentation until after you have demo’d the basic functionality. \n
  • This shows a list of author content showing on the user’s profile page.\nOther examples could be “show me a list of MY content in a block on the site”\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • You can WAIT to do this part of the presentation until after you have demo’d the basic functionality. \n
  • 1st - select the region field. formatted as plain text. \n2nd - rewrite the output so the two fields are in one row.\n3rd, this shows the out roughly. \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • At the bottom of the Views UI you see the query code output.\n
  • At the bottom of the Views UI you see the query code output.\n
  • Good things to know about Views!\n
  • Apply what you’ve learned to new situations.\nContinue to keep track of developments in the community.\nImprove your site building skills by becoming familiar with more popular modules.\nLook at popular Drupal websites to learn: How did they do that?\n
  • Views Configuration at Drupal Camp Toronto 2012

    1. 1. VIEWSCONFIGURATION
    2. 2. About me • Drupal consulting, development, and training • Help organizations build@suzanne_kennedy awesome Drupalevolvingweb.ca websites with custom functionality
    3. 3. What Can You Do with Views?• Site Building Tools • Lists of content • A way to build pages and blocks • Related content blocks• Interactive Lists • Fancy lists (calendars, slideshows, maps) • User control of sorts/filters
    4. 4. Introduction to Views
    5. 5. Views: Query builder• <?php // Connecting, selecting database $link = mysql_connect(mysql_host, mysql_user, mysql_password) or die(Could not connect: . mysql_error()); echo Connected successfully; mysql_select_db(my_database) or die(Could not select database); // Performing SQL query $query = SELECT * FROM my_table; $result = mysql_query($query) or die(Query failed: . mysql_error()); • // Printing results in HTML // Printing results in HTML echo "<table>n"; echo "<table>n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "t<tr>n"; while ($line = mysql_fetch_array($result, foreach ($line as $col_value) { } MYSQL_ASSOC)) { echo "tt<td>$col_value</td>n"; echo "t</tr>n"; echo "t<tr>n"; } echo "</table>n"; foreach ($line as $col_value) { // Free resultset echo "tt<td>$col_value</td>n"; mysql_free_result($result); } // Closing connection mysql_close($link); echo "t</tr>n"; ?> } echo "</table>n";
    6. 6. Views Wizard Choose base table Change types Term filters Simple sort
    7. 7. Views Wizard Page or block Display settings Add to menu
    8. 8. Views Editor
    9. 9. Choose What to ListContent Users Taxonomy CommentsContent title D. Schrute adventure Wow, cant Germany city breakwait to get dwight city break 8 Sept visit. J. Halpert Spain sailing joe Me too! shopping 8 Sept
    10. 10. Choose a Format
    11. 11. Choose a Display Web Page Title http://example.com/city-guides Google Page display (banner)City guides Sign upBeppu nameFar far away, behind the word mountains, far from the countries Vokalia andConsonantia, there live the blind texts. Separated they live in Bookmarksgrove right atthe coast of the Semantics, a large language ocean. email Block display ButtonParisFar far away, behind the word mountains, far from the countries Vokalia andConsonantia, there live the blind texts. Separated they live in Bookmarksgrove right at City guides by topicthe coast of the Semantics, a large language ocean. Budget City breakMali FamilyFar far away, behind the word mountains, far from the countries Vokalia and LuxuryConsonantia, there live the blind texts. Separated they live in Bookmarksgrove right at Sun and seathe coast of the Semantics, a large language ocean.
    12. 12. CHANGING THERESULTS
    13. 13. Filtering Results
    14. 14. Filtering Criteria Choose a field to filter by
    15. 15. Operators for FiltersOperatorschangebased onthe fieldbeingused to filter
    16. 16. Operators for FiltersFilter toshow onlyusers whohave apicture.
    17. 17. Filtering by Date • Use the Date Views moduleFilter to onlyshowresults witha start datein the future
    18. 18. Contextual Filters
    19. 19. What are Contextual Filters?• Dynamic filters• Filter content based on the context of the view• Aka arguments Eddie Eddie likes to travel with his mandolin. Or sometimes the ukelele. In a pinch, hell travel with just his tambourine. By this contributor... Best in Beppu Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. Paris excursions Far far away, behind the word mountains, far from the countries Vokalia and
    20. 20. Where does the context come from?• The URL • node/24 • taxonomy/term/• Passed directly to the view • From Panels • In code• PHP Code • Add custom code snippet to determine what argument to pass to the view (Bad)
    21. 21. Where does the context come from?
    22. 22. Examples• Author Page: Show content by this author• Blog Post: Show blog posts in the same category• Any Node Page: Show fields from the current node
    23. 23. About the Author
    24. 24. Related Content
    25. 25. Contextual Filters for Content Panes
    26. 26. Views relationships
    27. 27. Views Relationships• Join a Views result to a related record, so you can show fields from that record
    28. 28. Add Relationship to an Instructor Node Course InstructorCourse Title NameDepartment Field Specialty FieldCourse No. Field Entity ReferenceInstructor Field
    29. 29. Adding a Relationship
    30. 30. Add Relationship to an Instructor Node
    31. 31. Inverse Relationships with Entity Reference• Course->Instructor: Create a relationship from your result to the referenced content• Instructor->Course Create an inverse relationship from the referenced content to the referencing content
    32. 32. Other Use Cases• Blog posts: Info about the author of a node• Admin view of nodes: Link to translations• Events calendar: Info about room location
    33. 33. Relationships + Contextual Filters Examples• Blog Post: Show the other blog posts by the post’s author• Course Page: Show other courses by the course’s instructor
    34. 34. Listing more stuffwith Views
    35. 35. Choose what Views shows Choose base table Change types Term filters Simple sort
    36. 36. What else can you show with Views?• Aggregator items• Solr search results• Content Revisions• Products• Media• Webform Submissions• Files
    37. 37. Apache Solr• Apache Solr Views Integration module
    38. 38. Webform Submissions
    39. 39. Aggregator items
    40. 40. Your Custom Data• hook_views_data• Tell Views about the custom data that you’ve added with your module• http://evolvingweb.ca/story/developing- views-part-i-describing-your-data-views
    41. 41. Your Custom Data
    42. 42. CHANGING THEMARKUP
    43. 43. Views Formats
    44. 44. Built-in Formats• Table• Unformatted List• HTML List• Jump List• Grid
    45. 45. Views stylesUnformatted list - Teasers
    46. 46. Views styles Unformatted list - Fields TitleTrimmed body Thumbnail image
    47. 47. Views styles Table
    48. 48. Views styles HTML list
    49. 49. Extending Views Formats• Views Slideshow• Views Accordion• Calendar• Map (GMap, Open Layers, Leaflet modules)
    50. 50. Configuring Views Styles
    51. 51. Views Slideshow
    52. 52. Views Slideshow Config
    53. 53. Views Accordion
    54. 54. Calendar
    55. 55. Building a Calendar• Calendar provides a views template
    56. 56. Calendar Config
    57. 57. Map View
    58. 58. Altering Field Output
    59. 59. Altering Field Output
    60. 60. Altering Field Output
    61. 61. Altering Field Output
    62. 62. Theming ViewsOutput
    63. 63. Theme Information
    64. 64. Theme Information
    65. 65. Theme preprocess functions for Viewsmytheme_preprocess_views_view(&$vars) - generic for all viewsmytheme_process_views_view(&$vars) - generic for all viewsmytheme_preprocess_views_view_list(&$vars) - generic for List style viewsmytheme_preprocess_views_view_field(&$vars) - generic for each field
    66. 66. INTERACTIVE VIEWS
    67. 67. Giving Users Control
    68. 68. Allowing users to filter content
    69. 69. Modules for Filtering• Better Exposed Filters • Provides more options for exposed filters• Views Dependent Filters • Exposed filters that show up when a particular option is selected
    70. 70. Exposed Sorts• Use a table view and expose sorts to users
    71. 71. Exposing Search• Provide a ‘keywords’ exposed filter
    72. 72. Ajax-enabled Views• Add Ajax for pagers, filters
    73. 73. Extending Views:Administrative Views
    74. 74. Administrative Views Modules• Administrative Views• Draggable Views• Views Bulk Operations
    75. 75. Administrative Views
    76. 76. Draggable Views
    77. 77. Draggable Views
    78. 78. Views Bulk Operations
    79. 79. More Views Features
    80. 80. Previewing Output
    81. 81. Viewing the Query
    82. 82. Views in CodeExport ViewsAdd Views to Your Features
    83. 83. Q+A

    ×