/[drupal]/contributions/modules/views/docs/docs.php
ViewVC logotype

Contents of /contributions/modules/views/docs/docs.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.16 - (show annotations) (download) (as text)
Wed Jun 17 18:25:02 2009 UTC (5 months, 1 week ago) by merlinofchaos
Branch: MAIN
CVS Tags: DRUPAL-6--2-7, HEAD
Branch point for: DRUPAL-6--2, DRUPAL-7--3
Changes since 1.15: +29 -1 lines
File MIME type: text/x-php
Implement a post_render hook (for themes too) and cache method.
1 <?php
2 // $Id: docs.php,v 1.15 2009/06/01 23:33:37 merlinofchaos Exp $
3 /**
4 * @file
5 * This file contains no working PHP code; it exists to provide additional documentation
6 * for doxygen as well as to document hooks in the standard Drupal manner.
7 */
8
9 /**
10 * @mainpage Views 2 API Manual
11 *
12 * Much of this information is actually stored in the advanced help; please
13 * check the API topic. This help will primarily be aimed at documenting
14 * classes and function calls.
15 *
16 * An online version of the advanced help API documentation is available from:
17 * @link http://views-help.doc.logrus.com/help/views/api @endlink
18 *
19 * Topics:
20 * - @ref view_lifetime
21 * - @ref views_hooks
22 * - @ref views_handlers
23 * - @ref views_plugins
24 * - @ref views_templates
25 */
26
27 /**
28 * @page view_lifetime The life of a view
29 *
30 * This page explains the basic cycle of a view and what processes happen.
31 */
32
33 /**
34 * @page views_handlers About Views' handlers
35 *
36 * This page explains what views handlers are, how they're written, and what
37 * the basic conventions are.
38 *
39 * - @ref views_field_handlers
40 * - @ref views_sort_handlers
41 * - @ref views_filter_handlers
42 * - @ref views_argument_handlers
43 * - @ref views_relationship_handlers
44 */
45
46 /**
47 * @page views_plugins About Views' plugins
48 *
49 * This page explains what views plugins are, how they're written, and what
50 * the basic conventions are.
51 *
52 * - @ref views_display_plugins
53 * - @ref views_style_plugins
54 * - @ref views_row_plugins
55 */
56
57 /**
58 * @defgroup views_hooks Views' hooks
59 * @{
60 * Hooks that can be implemented by other modules in order to implement the
61 * Views API.
62 */
63
64 /**
65 * Describe table structure to Views.
66 *
67 * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded.
68 * This must either be in the same directory as the .module file or in a subdirectory
69 * named 'includes'.
70 *
71 * The full documentation for this hook is in the advanced help.
72 * @link http://views-help.doc.logrus.com/help/views/api-tables @endlink
73 */
74 function hook_views_data() {
75 // This example describes how to write hook_views_data() for the following
76 // table:
77 //
78 // CREATE TABLE example_table (
79 // nid INT(11) NOT NULL COMMENT 'Primary key; refers to {node}.nid.',
80 // plain_text_field VARCHAR(32) COMMENT 'Just a plain text field.',
81 // numeric_field INT(11) COMMENT 'Just a numeric field.',
82 // boolean_field INT(1) COMMENT 'Just an on/off field.',
83 // timestamp_field INT(8) COMMENT 'Just a timestamp field.',
84 // PRIMARY KEY(nid)
85 // );
86
87 // The 'group' index will be used as a prefix in the UI for any of this
88 // table's fields, sort criteria, etc. so it's easy to tell where they came
89 // from.
90 $data['example_table']['table']['group'] = t('Example table');
91
92 // Define this as a base table. In reality this is not very useful for
93 // this table, as it isn't really a distinct object of its own, but
94 // it makes a good example.
95 $data['example_table']['table']['base'] = array(
96 'field' => 'nid',
97 'title' => t('Example table'),
98 'help' => t("Example table contains example content and can be related to nodes."),
99 'weight' => -10,
100 );
101
102 // This table references the {node} table.
103 // This creates an 'implicit' relationship to the node table, so that when 'Node'
104 // is the base table, the fields are automatically available.
105 $data['example_table']['table']['join'] = array(
106 // Index this array by the table name to which this table refers.
107 // 'left_field' is the primary key in the referenced table.
108 // 'field' is the foreign key in this table.
109 'node' => array(
110 'left_field' => 'nid',
111 'field' => 'nid',
112 ),
113 );
114
115 // Next, describe each of the individual fields in this table to Views. For
116 // each field, you may define what field, sort, argument, and/or filter
117 // handlers it supports. This will determine where in the Views interface you
118 // may use the field.
119
120 // Node ID field.
121 $data['example_table']['nid'] = array(
122 'title' => t('Example content'),
123 'help' => t('Some example content that references a node.'),
124 // Because this is a foreign key to the {node} table. This allows us to
125 // have, when the view is configured with this relationship, all the fields
126 // for the related node available.
127 'relationship' => array(
128 'base' => 'node',
129 'field' => 'nid',
130 'handler' => 'views_handler_relationship',
131 'label' => t('Example node'),
132 ),
133 );
134
135 // Example plain text field.
136 $data['example_table']['plain_text_field'] = array(
137 'title' => t('Plain text field'),
138 'help' => t('Just a plain text field.'),
139 'field' => array(
140 'handler' => 'views_handler_field',
141 'click sortable' => TRUE,
142 ),
143 'sort' => array(
144 'handler' => 'views_handler_sort',
145 ),
146 'filter' => array(
147 'handler' => 'views_handler_filter_string',
148 ),
149 'argument' => array(
150 'handler' => 'views_handler_argument_string',
151 ),
152 );
153
154 // Example numeric text field.
155 $data['example_table']['numeric_field'] = array(
156 'title' => t('Numeric field'),
157 'help' => t('Just a numeric field.'),
158 'field' => array(
159 'handler' => 'views_handler_field_numeric',
160 'click sortable' => TRUE,
161 ),
162 'filter' => array(
163 'handler' => 'views_handler_filter_numeric',
164 ),
165 'sort' => array(
166 'handler' => 'views_handler_sort',
167 ),
168 );
169
170 // Example boolean field.
171 $data['example_table']['boolean_field'] = array(
172 'title' => t('Boolean field'),
173 'help' => t('Just an on/off field.'),
174 'field' => array(
175 'handler' => 'views_handler_field_boolean',
176 'click sortable' => TRUE,
177 ),
178 'filter' => array(
179 'handler' => 'views_handler_filter_boolean_operator',
180 'label' => t('Published'),
181 'type' => 'yes-no',
182 ),
183 'sort' => array(
184 'handler' => 'views_handler_sort',
185 ),
186 );
187
188 // Example timestamp field.
189 $data['example_table']['timestamp_field'] = array(
190 'title' => t('Timestamp field'),
191 'help' => t('Just a timestamp field.'),
192 'field' => array(
193 'handler' => 'views_handler_field_date',
194 'click sortable' => TRUE,
195 ),
196 'sort' => array(
197 'handler' => 'views_handler_sort_date',
198 ),
199 'filter' => array(
200 'handler' => 'views_handler_filter_date',
201 ),
202 );
203
204 return $data;
205 }
206
207 /**
208 * The full documentation for this hook is now in the advanced help.
209 *
210 * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded.
211 * This must either be in the same directory as the .module file or in a subdirectory
212 * named 'includes'.
213 *
214 * This is a stub list as a reminder that this needs to be doc'd and is not used
215 * in views anywhere so might not be remembered when this is formally documented:
216 * - style: 'even empty'
217 */
218 function hook_views_plugins() {
219 // example code here
220 }
221
222 /**
223 * Register handler, file and parent information so that handlers can be
224 * loaded only on request.
225 *
226 * The full documentation for this hook is in the advanced help.
227 */
228 function hook_views_handlers() {
229 // example code here
230 }
231
232 /**
233 * Register View API information. This is required for your module to have
234 * its include files loaded; for example, when implementing
235 * hook_views_default_views().
236 *
237 * @return
238 * An array with the following possible keys:
239 * - api: (required) The version of the Views API the module implements.
240 * - path: (optional) If includes are stored somewhere other than within
241 * the root module directory or a subdirectory called includes, specify
242 * its path here.
243 */
244 function hook_views_api() {
245 return array(
246 'api' => 2,
247 'path' => drupal_get_path('module', 'example') . '/includes/views',
248 );
249 }
250
251 /**
252 * This hook allows modules to provide their own views which can either be used
253 * as-is or as a "starter" for users to build from.
254 *
255 * This hook should be placed in MODULENAME.views_default.inc and it will be
256 * auto-loaded. This must either be in the same directory as the .module file
257 * or in a subdirectory named 'includes'.
258 *
259 * The $view->disabled boolean flag indicates whether the View should be
260 * enabled or disabled by default.
261 *
262 * @return
263 * An associative array containing the structures of views, as generated from
264 * the Export tab, keyed by the view name. A best practice is to go through
265 * and add t() to all title and label strings, with the exception of menu
266 * strings.
267 */
268 function hook_views_default_views() {
269 // Begin copy and paste of output from the Export tab of a view.
270 $view = new view;
271 $view->name = 'frontpage';
272 $view->description = t('Emulates the default Drupal front page; you may set the default home page path to this view to make it your front page.');
273 $view->tag = t('default');
274 $view->view_php = '';
275 $view->base_table = 'node';
276 $view->is_cacheable = '0';
277 $view->api_version = 2;
278 $view->disabled = FALSE; // Edit this to true to make a default view disabled initially
279 $view->display = array();
280 $display = new views_display;
281 $display->id = 'default';
282 $display->display_title = t('Defaults');
283 $display->display_plugin = 'default';
284 $display->position = '1';
285 $display->display_options = array (
286 'style_plugin' => 'default',
287 'style_options' =>
288 array (
289 ),
290 'row_plugin' => 'node',
291 'row_options' =>
292 array (
293 'teaser' => 1,
294 'links' => 1,
295 ),
296 'relationships' =>
297 array (
298 ),
299 'fields' =>
300 array (
301 ),
302 'sorts' =>
303 array (
304 'sticky' =>
305 array (
306 'id' => 'sticky',
307 'table' => 'node',
308 'field' => 'sticky',
309 'order' => 'ASC',
310 ),
311 'created' =>
312 array (
313 'id' => 'created',
314 'table' => 'node',
315 'field' => 'created',
316 'order' => 'ASC',
317 'relationship' => 'none',
318 'granularity' => 'second',
319 ),
320 ),
321 'arguments' =>
322 array (
323 ),
324 'filters' =>
325 array (
326 'promote' =>
327 array (
328 'id' => 'promote',
329 'table' => 'node',
330 'field' => 'promote',
331 'operator' => '=',
332 'value' => '1',
333 'group' => 0,
334 'exposed' => false,
335 'expose' =>
336 array (
337 'operator' => false,
338 'label' => '',
339 ),
340 ),
341 'status' =>
342 array (
343 'id' => 'status',
344 'table' => 'node',
345 'field' => 'status',
346 'operator' => '=',
347 'value' => '1',
348 'group' => 0,
349 'exposed' => false,
350 'expose' =>
351 array (
352 'operator' => false,
353 'label' => '',
354 ),
355 ),
356 ),
357 'items_per_page' => 10,
358 'use_pager' => '1',
359 'pager_element' => 0,
360 'title' => '',
361 'header' => '',
362 'header_format' => '1',
363 'footer' => '',
364 'footer_format' => '1',
365 'empty' => '',
366 'empty_format' => '1',
367 );
368 $view->display['default'] = $display;
369 $display = new views_display;
370 $display->id = 'page';
371 $display->display_title = t('Page');
372 $display->display_plugin = 'page';
373 $display->position = '2';
374 $display->display_options = array (
375 'defaults' =>
376 array (
377 'access' => true,
378 'title' => true,
379 'header' => true,
380 'header_format' => true,
381 'header_empty' => true,
382 'footer' => true,
383 'footer_format' => true,
384 'footer_empty' => true,
385 'empty' => true,
386 'empty_format' => true,
387 'items_per_page' => true,
388 'offset' => true,
389 'use_pager' => true,
390 'pager_element' => true,
391 'link_display' => true,
392 'php_arg_code' => true,
393 'exposed_options' => true,
394 'style_plugin' => true,
395 'style_options' => true,
396 'row_plugin' => true,
397 'row_options' => true,
398 'relationships' => true,
399 'fields' => true,
400 'sorts' => true,
401 'arguments' => true,
402 'filters' => true,
403 'use_ajax' => true,
404 'distinct' => true,
405 ),
406 'relationships' =>
407 array (
408 ),
409 'fields' =>
410 array (
411 ),
412 'sorts' =>
413 array (
414 ),
415 'arguments' =>
416 array (
417 ),
418 'filters' =>
419 array (
420 ),
421 'path' => 'frontpage',
422 );
423 $view->display['page'] = $display;
424 $display = new views_display;
425 $display->id = 'feed';
426 $display->display_title = t('Feed');
427 $display->display_plugin = 'feed';
428 $display->position = '3';
429 $display->display_options = array (
430 'defaults' =>
431 array (
432 'access' => true,
433 'title' => false,
434 'header' => true,
435 'header_format' => true,
436 'header_empty' => true,
437 'footer' => true,
438 'footer_format' => true,
439 'footer_empty' => true,
440 'empty' => true,
441 'empty_format' => true,
442 'use_ajax' => true,
443 'items_per_page' => true,
444 'offset' => true,
445 'use_pager' => true,
446 'pager_element' => true,
447 'use_more' => true,
448 'distinct' => true,
449 'link_display' => true,
450 'php_arg_code' => true,
451 'exposed_options' => true,
452 'style_plugin' => false,
453 'style_options' => false,
454 'row_plugin' => false,
455 'row_options' => false,
456 'relationships' => true,
457 'fields' => true,
458 'sorts' => true,
459 'arguments' => true,
460 'filters' => true,
461 ),
462 'relationships' =>
463 array (
464 ),
465 'fields' =>
466 array (
467 ),
468 'sorts' =>
469 array (
470 ),
471 'arguments' =>
472 array (
473 ),
474 'filters' =>
475 array (
476 ),
477 'displays' =>
478 array (
479 'default' => 'default',
480 'page' => 'page',
481 ),
482 'style_plugin' => 'rss',
483 'style_options' =>
484 array (
485 'mission_description' => 1,
486 'description' => '',
487 ),
488 'row_plugin' => 'node_rss',
489 'row_options' =>
490 array (
491 'item_length' => 'default',
492 ),
493 'path' => 'rss.xml',
494 'title' => t('Front page feed'),
495 );
496 $view->display['feed'] = $display;
497 // End copy and paste of Export tab output.
498
499 // Add view to list of views to provide.
500 $views[$view->name] = $view;
501
502 // ...Repeat all of the above for each view the module should provide.
503
504 // At the end, return array of default views.
505 return $views;
506 }
507
508 /**
509 * This hook is called right before all default views are cached to the
510 * database. It takes a keyed array of views by reference.
511 */
512 function hook_views_default_views_alter(&$views) {
513 if (isset($views['taxonomy_term'])) {
514 $views['taxonomy_term']->set_display('default');
515 $views['taxonomy_term']->display_handler->set_option('title', 'Categories');
516 }
517 }
518
519 /**
520 * Stub hook documentation
521 *
522 * This hook should be placed in MODULENAME.views_convert.inc and it will be auto-loaded.
523 * This must either be in the same directory as the .module file or in a subdirectory
524 * named 'includes'.
525 */
526 function hook_views_convert() {
527 // example code here
528 }
529
530 /**
531 * Stub hook documentation
532 */
533 function hook_views_query_substitutions() {
534 // example code here
535 }
536
537 /**
538 * This hook is called at the very beginning of views processing,
539 * before anything is done.
540 *
541 * Adding output to the view cam be accomplished by placing text on
542 * $view->attachment_before and $view->attachment_after
543 */
544 function hook_views_pre_view(&$view, &$display_id, &$args) {
545 // example code here
546 }
547
548 /**
549 * This hook is called right before the build process, but after displays
550 * are attached and the display performs its pre_execute phase.
551 *
552 * Adding output to the view cam be accomplished by placing text on
553 * $view->attachment_before and $view->attachment_after
554 */
555 function hook_views_pre_build(&$view) {
556 // example code here
557 }
558
559 /**
560 * This hook is called right before the execute process. The query is
561 * now fully built, but it has not yet been run through db_rewrite_sql.
562 *
563 * Adding output to the view cam be accomplished by placing text on
564 * $view->attachment_before and $view->attachment_after
565 */
566 function hook_views_pre_execute(&$view) {
567 // example code here
568 }
569
570 /**
571 * This hook is called right before the render process. The query has
572 * been executed, and the pre_render() phase has already happened for
573 * handlers, so all data should be available.
574 *
575 * Adding output to the view cam be accomplished by placing text on
576 * $view->attachment_before and $view->attachment_after
577 *
578 * This hook can be utilized by themes.
579 */
580 function hook_views_pre_render(&$view) {
581 // example code here
582 }
583
584 /**
585 * Post process any rendered data.
586 *
587 * This can be valuable to be able to cache a view and still have some level of
588 * dynamic output. In an ideal world, the actual output will include HTML
589 * comment based tokens, and then the post process can replace those tokens.
590 *
591 * Example usage. If it is known that the view is a node view and that the
592 * primary field will be a nid, you can do something like this:
593 *
594 * <!--post-FIELD-NID-->
595 *
596 * And then in the post render, create an array with the text that should
597 * go there:
598 *
599 * strtr($output, array('<!--post-FIELD-1-->', 'output for FIELD of nid 1');
600 *
601 * All of the cached result data will be available in $view->result, as well,
602 * so all ids used in the query should be discoverable.
603 *
604 * This hook can be utilized by themes.
605 */
606 function hook_views_post_render(&$view, &$output, &$cache) {
607
608 }
609
610 /**
611 * Stub hook documentation
612 *
613 * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded.
614 * This must either be in the same directory as the .module file or in a subdirectory
615 * named 'includes'.
616 *
617 */
618 function hook_views_query_alter(&$view, &$query) {
619 // example code here
620 }
621
622 /**
623 * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded.
624 * This must either be in the same directory as the .module file or in a subdirectory
625 * named 'includes'.
626 *
627 * Alter the links that appear over a view. They are in a format suitable for
628 * theme('links').
629 *
630 * Warning: $view is not a reference in PHP4 and cannot be modified here. But it IS
631 * a reference in PHP5, and can be modified. Please be careful with it.
632 *
633 * @see theme_links
634 */
635 function hook_views_admin_links_alter(&$links, $view) {
636 // example code here
637 }
638
639 /**
640 * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded.
641 * This must either be in the same directory as the .module file or in a subdirectory
642 * named 'includes'.
643 *
644 * Alter the rows that appear with a view, which includes path and query information.
645 * The rows are suitable for theme('table').
646 *
647 * Warning: $view is not a reference in PHP4 and cannot be modified here. But it IS
648 * a reference in PHP5, and can be modified. Please be careful with it.
649 *
650 * @see theme_table
651 */
652 function hook_views_preview_info_alter(&$rows, $view) {
653 // example code here
654 }
655
656 /**
657 * @}
658 */

  ViewVC Help
Powered by ViewVC 1.1.2