• Like
  • Save
Drupal Views development
Upcoming SlideShare
Loading in...5
×

Drupal Views development

  • 11,806 views
Uploaded on

Slides from Frederic G. MARAND's "Developing to the Views 7.3 API" at the Drupal Dev Days in Brussels, 2011-02-05. …

Slides from Frederic G. MARAND's "Developing to the Views 7.3 API" at the Drupal Dev Days in Brussels, 2011-02-05.

More details and code access on my blog.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
11,806
On Slideshare
0
From Embeds
0
Number of Embeds
9

Actions

Shares
Downloads
0
Comments
0
Likes
17

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • If you don't know Views UI, you will have a hard time understanding what all of this is about. If you don't know the basics of (PHP5) OOP, Views-style integration will look hairy. If you aren't used to module development, you will have a hard time understand why devs care about this.
  • Examples: - Flickr query plugin, - MongoDB Views integration Not EFQ query plugin including, but exists in contrib
  • Meaning it can be used in different places, or take input from the context, like the URL, or from the user Themability: the SemanticViews case So basically Views is a report builder. Just like Crystal Reports, but for Drupal. No (good) printing solutions.
  • Views introduced the concept early in Drupal, and it really caught the Drupal dev world with Drupal 6. This is really what Features is about But Features' Views integration, alas...
  • So you wanna talk to Views, eh ? Start by saying hello Other hook implementations will go elsewhere thanks to it.
  • Check: dr713.info dependencies[] = views dr713.module HVA
  • Skip if later than T0 + 15 minutes
  • Miscellany views_many_to_one_helper views_tab views_tabset views_join views_join_complex
  • Views invokes these hooks only when the cache has been deleted. This being configuration information, it needn't be recomputed constantly.
  • Domain Specific Language: not /that/ true, but the idea comes from seeing similar constructs usually be done with INI, XML or JSON files, whereas Views uses format to skip on the user-space parsing logic PHPTemplate vs Xtemplate, PHPTal, Smarty... Also CCK content types And, of course Features / Ctools exportables
  • Actually, area handlers are really much like field handlers, so they contribute to the query in some abstract sense (although not technically)
  • Why ? Arguments themselves translate to conditions in the query. Defaults and validation do not translate to the query itself, but can inject parameters or prevent the query from being ran. views_content_cache attempts to invalidate content depending on actual activity, like comment/node updates and VotingAPI
  • Sample problem-space ordering: partial IPv4 addresses - not number: must be left aligned - not string Sample problem-space filtering - filter on month of date
  • This is not what actually happens in code, but it simpler to figure out that way.

Transcript

  • 1.
      Developing for the Views 7.3 API Frédéric G. MARAND aka fgm aka OSInet
  • 2. Session summary
    • Concepts
    • 3. Basic integration: default views & embedding
    • 4. Drupal-style integration: lifecycle hooks
    • 5. Views-style integration: handlers & plugins
    • 6. Going further
  • 7. 1. Concepts
  • 8. Concepts: Is this for you ?
  • 11. Concepts: Views API, why care ?
    • Code-based views
    • 12. Views-based code
    • 13. Views theming
    • 14. Extra view types
  • 15. Concepts: Why care ? More extras
  • 29. Concepts: I'm sold: what is a View ?
    • A pre-built query
      • SQL, NoSQL, WS...
      • 30. From Views UI or from code
      • 31. On known entities ....
      • 32. .... not in the EFQ sense
  • 33. Concepts: What is a View, again ?
    • A parametric query
      • Arguments
      • 34. Exposed filters
    • A query with formatted results
      • Layout plugins: Display, Style, Row
      • 35. Themable
      • 36. Yes, it means a REPORT
  • 37. Concepts: a report for coders
    • The « exportable » concept
      • Default views
      • 38. Normal views
      • 39. Overridden views
    • Features, anyone ?
  • 40. Concepts: enough talk
      Time for some <?php hooks(); ?>
  • 41. 2. Basic default/embed
  • 42. Basic: Hello, Views
    • hook_views_api()
      • Version matching
      • 43. Component location
      • 44. THE hook in your module
  • 45. Basic: HVA demo
      (Switch to code view)
  • 46. Basic: intermezzo Intermezzo: hooks & OO in Views Skip to HVD
  • 47. Basic: hooks & OO in Views
    • Hooks
    • 48. Passive observer pattern
    • 49. Parent is in charge
      • can override child
      • 50. can extend child
    • Implementations alter sibling results
    • 51. « horizontal »
    • Views OO
    • 52. Inheritance
    • 53. Children are in charge
      • can override parent
      • 54. can extend parent
    • No sibling results
    • 55. « vertical »
  • 56. Basic: Views objects
    • views_db_object
    • views_object
      • views_handler
      • 58. views_plugin … And a small collection of miscellaneous classes
  • 59. Basic: Views hooks
    • Pseudo-hooks
      • Declare a list of data
      • 60. Build a registry
      • 61. Use exactly one specified piece of data
      • 62. HV Data, HV DV, HV Plugins, HV QS…
    • True hooks
      • Accumulators: lifecycle hooks
      • 63. Alter hooks: HV QA, HV ALA
  • 64. Basic: supporting custom tables
    • hook_views_data
      • Base tables
        • [base] view type = base table
        • 65. The [table] array
      • Linked tables
        • POV: From the table being defined
        • 66. ...to another (left) table via a (left) field
        • 67. ...iteratively
        • 68. ...until a base table is found at the far left
      • Do not forget relationship handlers. Just not here.
      • 69. Yes, that's a pseudo-hook
    Back to Intermezzo
  • 70. Basic: altering the schema
    • hook_views_data_alter
      • Plain Old Drupal Alterator
    • Use cases
      • Expose new fields in a table supported by another module
      • 71. Add new sorts, filters... to another module
    • HVD/HVDA: Invocation time ?
  • 72. Basic: HVD demo
      Add Views support to dblog.module (Switch to code view)
  • 73. Basic: code-based Views
    • hook_views_default_views
      • Build a view object in code
      • 74. PHP as a DSL ?
      • 75. Didn't we see this somewhere else in Drupal ?
    • Work process
      • Views UI to/from code
      • 76. Single or multiple view files
      • 77. <?php ?> wrapper
      • 78. File names
  • 79. Basic: HVDV demo
      Provide a default view to dblog.module (Switch to code view)
  • 80. Basic: a page with a view
    • views_embed_view($name, $display = 'default')
      • The good:
        • Dead simple to use
        • 81. Argument passing
      • The bad:
        • Default display ? Really ?
        • 82. $view unavailable
      • The ugly:
        • Display side effects
  • 83. Basic: a page with a better view
    • view::execute_display()
      • Still side effects
      • 84. But more control: $view is available
    • view::preview()
      • Core of views_embed_view()
      • 85. Can refine the process as needed
      • 86. $view available
  • 87. 3. Drupal-style: lifecycle hooks
  • 88. Drupal style: early lifecycle hooks
    • A bunch of traditional hooks
    • 89. From view initialization to result rendering:
      • HV_pre_view :
        • start, no work done
        • 90. Alter view with view::attachment_(before|after)
      • HV_pre_build :
        • Displays initialized
        • 91. Alter view with view::attachment_(before|after)
        • 92. Before query building
  • 93. Drupal style: query lifecycle hooks
    • HV_query_alter()
      • Modify the query
      • 94. Beware the aliases !
    • HV_query_substitutions
      • Pseudo-hook: registry of ***CURRENT_USER*** -like
      • 95. Uncommon in « userland »
    • HV_pre_execute
      • nodeAccess not yet applied
  • 96. Drupal style: render lifecycle hooks
    • Query executed
    • 97. HV_pre_render
      • After the pre_render() methods in handlers
    • HV_admin_links_alter
      • Damage control on side effects
      • 98. Example: hide inline edit controls in list
    • Theming
      • Another story in its own right
  • 99. 4. Views style: handlers & plugins
  • 100. Views: handlers and plugins
    • views_db_object : the helpful parent
    • views_handler
      • define the query: fields, ordering, conditions, relations
      • 103. define area content
    • views_plugin
      • everything else
      • 104. including the query /engine/
  • 105. Views: « layout » plugins
    • Display
      • Outer content
      • 106. Define format: block, page, feed
    • Style
      • Row set
      • 107. Grid, table, list...
    • Row
      • Optional: some style plugins (table) have to intervene between rows
      • 108. Typical: views_plugin_row_fields
  • 109. Views: access plugins
  • 114. Views: query plugin
    • Build and run the actual query
    • 115. Mandatory
    • 116. Built-in: SQL via DBTNG (db_api in D6)
    • 117. Opportunity to interface non-SQL services with Views. Samples/experiments:
      • EntityFieldQuery http://drupal.org/project/efq_views
      • 118. MongoDB http://bit.ly/mongodbviews
      • 119. Web Services http://bit.ly/extendrviews
      • 120. SPARQL, YQL, Wolfram Alpha, ApacheSolr...
  • 121. Views: other plugins
    • Argument plugins
      • Not arguments themselves
      • 122. Default plugins
      • 123. Validation plugins
    • Cache plugins
      • Built-in: none, basic time-based
      • 124. Optional: views_content_cache
    • Others
      • Pagers, exposed_form, localization (none / core)
  • 125. Views: implementing plugins
    • Declare to Views
      • hook_views_plugins
      • 126. views_discover_plugins
    • File layout
      • D7 autoloading: <module>.info
      • 127. One per plugin
      • 128. Naming conventions
    • Alterability
      • hook_views_plugins_alter()
  • 129. Views: access plugin demo
      Write a variable-based access control plugin (Switch to code view)
  • 130. Views: access plugin questions
    • Views caching ?
    • 131. Non-Views caching ?
  • 132. Views: simple handlers
    • Filter handlers
      • Add conditions rules
      • 133. Translate to WHERE or HAVING for SQL
      • 134. Express a problem space condition as a (set of) query engine conditions
    • Sort handlers
      • Add sorting rules
      • 135. Translate to ORDER BY for SQL
      • 136. Express a problem space sorting as a query ordering
  • 137. Views: field handlers
    • Basic
      • Expose a DB column under its own name
    • Evolved
      • Expose several aliases from a single column
      • 138. Synthesize several columns into one field
  • 139. Views: complex handlers
    • Relationships
      • Remember implicit joins ? Make them explicit
      • 140. Allow multiple named join paths from table to base
    • Arguments
      • Basically filters
      • 141. But context-injected
      • 142. Can modify page: title, breadcrumbs...
      • 143. Can modify display: eg summary mode
    • Aggregate GROUP BY support ?
      • argument & field & filter & sort
  • 144. Views: area handlers
    • Areas ?
    • Why ?
      • No more in-DB PHP to have dynamic area content
      • 147. No more embedded views just for dynamic area content
    • Why handlers ?
      • Field handlers for the #global virtual table
  • 148. Views: implementing handlers
    • Declare to Views
      • No more hook_views_handlers
      • 149. Properties: hook_views_data[_alter]
      • 150. D7 autoloading: <module>.info
    • File layout: like plugins
  • 151. Views: area handler demo
      (Switch to code view)
  • 152. 5. Going further
  • 153. Going further: more info
    • This is just an intro!
      • Merlinofchaos' et alii book about Views 2 still relevant
      • 154. http://bit.ly/cckviewspanels
    • Online
      • http://views.doc.logrus.com/
      • 155. Advanced Help in your own site
    • Freenode IRC :
      • Work on Views itself: #drupal-views
      • 156. Support for your Views code: #drupal and #drupal-contribute (for contrib)
  • 157. The mandatory plug
    • This session is only an excerpt from the hands -on OSInet DR-713 course
      • 7-hour hands-on workshop
      • 158. Available in English and French
      • 159. On-demand in other languages
    • OSInet is a state registered french training provider with a full Drupal training syllabus
      • From content creator... to site builder ...
      • 160. ...to advanced module developer [email_address]
  • 161. The « other » mandatory plug We're hiring ! [email_address]
  • 162.
      </Developing for the Views 7.3 API Frédéric G. MARAND aka fgm aka OSInet>