• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

docs/views.api.php

Go to the documentation of this file.
00001 <?php
00074 function hook_views_data() {
00075   // This example describes how to write hook_views_data() for the following
00076   // table:
00077   //
00078   // CREATE TABLE example_table (
00079   //   nid INT(11) NOT NULL         COMMENT 'Primary key; refers to {node}.nid.',
00080   //   plain_text_field VARCHAR(32) COMMENT 'Just a plain text field.',
00081   //   numeric_field INT(11)        COMMENT 'Just a numeric field.',
00082   //   boolean_field INT(1)         COMMENT 'Just an on/off field.',
00083   //   timestamp_field INT(8)       COMMENT 'Just a timestamp field.',
00084   //   PRIMARY KEY(nid)
00085   // );
00086 
00087   // The 'group' index will be used as a prefix in the UI for any of this
00088   // table's fields, sort criteria, etc. so it's easy to tell where they came
00089   // from.
00090   $data['example_table']['table']['group'] = t('Example table');
00091 
00092   // Define this as a base table. In reality this is not very useful for
00093   // this table, as it isn't really a distinct object of its own, but
00094   // it makes a good example.
00095   $data['example_table']['table']['base'] = array(
00096     'field' => 'nid',
00097     'title' => t('Example table'),
00098     'help' => t("Example table contains example content and can be related to nodes."),
00099     'weight' => -10,
00100   );
00101 
00102   // This table references the {node} table.
00103   // This creates an 'implicit' relationship to the node table, so that when 'Node'
00104   // is the base table, the fields are automatically available.
00105   $data['example_table']['table']['join'] = array(
00106     // Index this array by the table name to which this table refers.
00107     // 'left_field' is the primary key in the referenced table.
00108     // 'field' is the foreign key in this table.
00109     'node' => array(
00110       'left_field' => 'nid',
00111       'field' => 'nid',
00112     ),
00113   );
00114 
00115   // Next, describe each of the individual fields in this table to Views. For
00116   // each field, you may define what field, sort, argument, and/or filter
00117   // handlers it supports. This will determine where in the Views interface you
00118   // may use the field.
00119 
00120   // Node ID field.
00121   $data['example_table']['nid'] = array(
00122     'title' => t('Example content'),
00123     'help' => t('Some example content that references a node.'),
00124     // Because this is a foreign key to the {node} table. This allows us to
00125     // have, when the view is configured with this relationship, all the fields
00126     // for the related node available.
00127     'relationship' => array(
00128       'base' => 'node',
00129       'field' => 'nid',
00130       'handler' => 'views_handler_relationship',
00131       'label' => t('Example node'),
00132     ),
00133   );
00134 
00135   // Example plain text field.
00136   $data['example_table']['plain_text_field'] = array(
00137     'title' => t('Plain text field'),
00138     'help' => t('Just a plain text field.'),
00139     'field' => array(
00140       'handler' => 'views_handler_field',
00141       'click sortable' => TRUE,
00142     ),
00143     'sort' => array(
00144       'handler' => 'views_handler_sort',
00145     ),
00146     'filter' => array(
00147       'handler' => 'views_handler_filter_string',
00148     ),
00149     'argument' => array(
00150       'handler' => 'views_handler_argument_string',
00151     ),
00152   );
00153 
00154   // Example numeric text field.
00155   $data['example_table']['numeric_field'] = array(
00156     'title' => t('Numeric field'),
00157     'help' => t('Just a numeric field.'),
00158     'field' => array(
00159       'handler' => 'views_handler_field_numeric',
00160       'click sortable' => TRUE,
00161      ),
00162     'filter' => array(
00163       'handler' => 'views_handler_filter_numeric',
00164     ),
00165     'sort' => array(
00166       'handler' => 'views_handler_sort',
00167     ),
00168   );
00169 
00170   // Example boolean field.
00171   $data['example_table']['boolean_field'] = array(
00172     'title' => t('Boolean field'),
00173     'help' => t('Just an on/off field.'),
00174     'field' => array(
00175       'handler' => 'views_handler_field_boolean',
00176       'click sortable' => TRUE,
00177     ),
00178     'filter' => array(
00179       'handler' => 'views_handler_filter_boolean_operator',
00180       'label' => t('Published'),
00181       'type' => 'yes-no',
00182       // use boolean_field = 1 instead of boolean_field <> 0 in WHERE statment
00183       'use equal' => TRUE,
00184     ),
00185     'sort' => array(
00186       'handler' => 'views_handler_sort',
00187     ),
00188   );
00189 
00190   // Example timestamp field.
00191   $data['example_table']['timestamp_field'] = array(
00192     'title' => t('Timestamp field'),
00193     'help' => t('Just a timestamp field.'),
00194     'field' => array(
00195       'handler' => 'views_handler_field_date',
00196       'click sortable' => TRUE,
00197     ),
00198     'sort' => array(
00199       'handler' => 'views_handler_sort_date',
00200     ),
00201     'filter' => array(
00202       'handler' => 'views_handler_filter_date',
00203     ),
00204   );
00205 
00206   return $data;
00207 }
00208 
00222 function hook_views_data_alter(&$data) {
00223   // This example alters the title of the node: nid field for the admin.
00224   $data['node']['nid']['title'] = t('Node-Nid');
00225 
00226   // This example adds a example field to the users table
00227   $data['users']['example_field'] = array(
00228     'title' => t('Example field'),
00229     'help' => t('Some examüple content that references a user'),
00230     'handler' => 'hook_handlers_field_example_field',
00231   );
00232 
00233   // This example changes the handler of the node title field.
00234   // In this handler you could do stuff, like preview of the node, when clicking the node title.
00235 
00236   $data['node']['title']['handler'] = 'modulename_handlers_field_node_title';
00237 }
00238 
00239 
00252 function hook_views_plugins() {
00253   // example code here
00254 }
00255 
00259 function hook_views_plugins_alter(&$plugins) {
00260   // Add apachesolr to the base of the node row plugin.
00261   $plugins['row']['node']['base'][] = 'apachesolr';
00262 }
00263 
00278 function hook_views_api() {
00279   return array(
00280     'api' => 3,
00281     'path' => drupal_get_path('module', 'example') . '/includes/views',
00282     'template path' => drupal_get_path('module', 'example') . 'themes',
00283   );
00284 }
00285 
00304 function hook_views_default_views() {
00305   // Begin copy and paste of output from the Export tab of a view.
00306   $view = new view;
00307   $view->name = 'frontpage';
00308   $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.');
00309   $view->tag = t('default');
00310   $view->base_table = 'node';
00311   $view->api_version = 2;
00312   $view->disabled = FALSE; // Edit this to true to make a default view disabled initially
00313   $view->display = array();
00314     $display = new views_display;
00315     $display->id = 'default';
00316     $display->display_title = t('Master');
00317     $display->display_plugin = 'default';
00318     $display->position = '1';
00319     $display->display_options = array (
00320     'style_plugin' => 'default',
00321     'style_options' =>
00322     array (
00323     ),
00324     'row_plugin' => 'node',
00325     'row_options' =>
00326     array (
00327       'teaser' => 1,
00328       'links' => 1,
00329     ),
00330     'relationships' =>
00331     array (
00332     ),
00333     'fields' =>
00334     array (
00335     ),
00336     'sorts' =>
00337     array (
00338       'sticky' =>
00339       array (
00340         'id' => 'sticky',
00341         'table' => 'node',
00342         'field' => 'sticky',
00343         'order' => 'ASC',
00344       ),
00345       'created' =>
00346       array (
00347         'id' => 'created',
00348         'table' => 'node',
00349         'field' => 'created',
00350         'order' => 'ASC',
00351         'relationship' => 'none',
00352         'granularity' => 'second',
00353       ),
00354     ),
00355     'arguments' =>
00356     array (
00357     ),
00358     'filters' =>
00359     array (
00360       'promote' =>
00361       array (
00362         'id' => 'promote',
00363         'table' => 'node',
00364         'field' => 'promote',
00365         'operator' => '=',
00366         'value' => '1',
00367         'group' => 0,
00368         'exposed' => false,
00369         'expose' =>
00370         array (
00371           'operator' => false,
00372           'label' => '',
00373         ),
00374       ),
00375       'status' =>
00376       array (
00377         'id' => 'status',
00378         'table' => 'node',
00379         'field' => 'status',
00380         'operator' => '=',
00381         'value' => '1',
00382         'group' => 0,
00383         'exposed' => false,
00384         'expose' =>
00385         array (
00386           'operator' => false,
00387           'label' => '',
00388         ),
00389       ),
00390     ),
00391     'items_per_page' => 10,
00392     'use_pager' => '1',
00393     'pager_element' => 0,
00394     'title' => '',
00395     'header' => '',
00396     'header_format' => '1',
00397     'footer' => '',
00398     'footer_format' => '1',
00399     'empty' => '',
00400     'empty_format' => '1',
00401   );
00402   $view->display['default'] = $display;
00403     $display = new views_display;
00404     $display->id = 'page';
00405     $display->display_title = t('Page');
00406     $display->display_plugin = 'page';
00407     $display->position = '2';
00408     $display->display_options = array (
00409     'defaults' =>
00410     array (
00411       'access' => true,
00412       'title' => true,
00413       'header' => true,
00414       'header_format' => true,
00415       'header_empty' => true,
00416       'footer' => true,
00417       'footer_format' => true,
00418       'footer_empty' => true,
00419       'empty' => true,
00420       'empty_format' => true,
00421       'items_per_page' => true,
00422       'offset' => true,
00423       'use_pager' => true,
00424       'pager_element' => true,
00425       'link_display' => true,
00426       'php_arg_code' => true,
00427       'exposed_options' => true,
00428       'style_plugin' => true,
00429       'style_options' => true,
00430       'row_plugin' => true,
00431       'row_options' => true,
00432       'relationships' => true,
00433       'fields' => true,
00434       'sorts' => true,
00435       'arguments' => true,
00436       'filters' => true,
00437       'use_ajax' => true,
00438       'distinct' => true,
00439     ),
00440     'relationships' =>
00441     array (
00442     ),
00443     'fields' =>
00444     array (
00445     ),
00446     'sorts' =>
00447     array (
00448     ),
00449     'arguments' =>
00450     array (
00451     ),
00452     'filters' =>
00453     array (
00454     ),
00455     'path' => 'frontpage',
00456   );
00457   $view->display['page'] = $display;
00458     $display = new views_display;
00459     $display->id = 'feed';
00460     $display->display_title = t('Feed');
00461     $display->display_plugin = 'feed';
00462     $display->position = '3';
00463     $display->display_options = array (
00464     'defaults' =>
00465     array (
00466       'access' => true,
00467       'title' => false,
00468       'header' => true,
00469       'header_format' => true,
00470       'header_empty' => true,
00471       'footer' => true,
00472       'footer_format' => true,
00473       'footer_empty' => true,
00474       'empty' => true,
00475       'empty_format' => true,
00476       'use_ajax' => true,
00477       'items_per_page' => true,
00478       'offset' => true,
00479       'use_pager' => true,
00480       'pager_element' => true,
00481       'use_more' => true,
00482       'distinct' => true,
00483       'link_display' => true,
00484       'php_arg_code' => true,
00485       'exposed_options' => true,
00486       'style_plugin' => false,
00487       'style_options' => false,
00488       'row_plugin' => false,
00489       'row_options' => false,
00490       'relationships' => true,
00491       'fields' => true,
00492       'sorts' => true,
00493       'arguments' => true,
00494       'filters' => true,
00495     ),
00496     'relationships' =>
00497     array (
00498     ),
00499     'fields' =>
00500     array (
00501     ),
00502     'sorts' =>
00503     array (
00504     ),
00505     'arguments' =>
00506     array (
00507     ),
00508     'filters' =>
00509     array (
00510     ),
00511     'displays' =>
00512     array (
00513       'default' => 'default',
00514       'page' => 'page',
00515     ),
00516     'style_plugin' => 'rss',
00517     'style_options' =>
00518     array (
00519       'description' => '',
00520     ),
00521     'row_plugin' => 'node_rss',
00522     'row_options' =>
00523     array (
00524       'item_length' => 'default',
00525     ),
00526     'path' => 'rss.xml',
00527     'title' => t('Front page feed'),
00528   );
00529   $view->display['feed'] = $display;
00530   // End copy and paste of Export tab output.
00531 
00532   // Add view to list of views to provide.
00533   $views[$view->name] = $view;
00534 
00535   // ...Repeat all of the above for each view the module should provide.
00536 
00537   // At the end, return array of default views.
00538   return $views;
00539 }
00540 
00558 function hook_views_default_views_alter(&$views) {
00559   if (isset($views['taxonomy_term'])) {
00560     $views['taxonomy_term']->display['default']->display_options['title'] = 'Categories';
00561   }
00562 }
00563 
00567 function hook_views_query_substitutions() {
00568   // example code here
00569 }
00570 
00575 function hook_views_form_substitutions() {
00576   return array(
00577     '<!--views-form-example-substitutions-->' => 'Example Substitution',
00578   );
00579 }
00580 
00585 function hook_views_form_validate($form, &$form_state) {
00586   // example code here
00587 }
00588 
00593 function hook_views_form_submit($form, &$form_state) {
00594   // example code here
00595 }
00596 
00604 function hook_views_pre_view(&$view, &$display_id, &$args) {
00605   // example code here
00606 }
00607 
00615 function hook_views_pre_build(&$view) {
00616   // example code here
00617 }
00618 
00626 function hook_views_post_build(&$view) {
00627   // example code here
00628 }
00629 
00637 function hook_views_pre_execute(&$view) {
00638   // example code here
00639 }
00640 
00650 function hook_views_post_execute(&$view) {
00651   // example code here
00652 }
00653 
00665 function hook_views_pre_render(&$view) {
00666   // example code here
00667 }
00668 
00691 function hook_views_post_render(&$view, &$output, &$cache) {
00692 
00693 }
00694 
00704 function hook_views_query_alter(&$view, &$query) {
00705   // example code here
00706 }
00707 
00726 function hook_views_preview_info_alter(&$rows, $view) {
00727   // example code here
00728 }
00729 
00741 function hook_views_ui_display_top_links_alter(&$links, $view, $display_id) {
00742   // example code here
00743 }
00744 
00754 function hook_views_ajax_data_alter(&$commands, $view) {
00755 }
00756 
00757 
00758 

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1