Issue #1808756 by xjm: Remove documentation of obsolete hooks.
parent
1d3f5d257e
commit
d5a3d14dc1
380
views.api.php
380
views.api.php
|
@ -5,31 +5,6 @@
|
|||
* Describe hooks provided by the Views module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @mainpage Views 3 API Manual
|
||||
*
|
||||
* Much of this information is actually stored in the advanced help; please
|
||||
* check the API topic. This help will primarily be aimed at documenting
|
||||
* classes and function calls.
|
||||
*
|
||||
* Topics:
|
||||
* - @link views_lifetime The life of a view @endlink
|
||||
* - @link views_hooks Views hooks @endlink
|
||||
* - @link views_handlers About Views handlers @endlink
|
||||
* - @link views_plugins About Views plugins @endlink
|
||||
* - @link views_templates Views template files @endlink
|
||||
* - @link views_module_handlers Views module handlers @endlink
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup views_lifetime The life of a view
|
||||
* @{
|
||||
* This page explains the basic cycle of a view and what processes happen.
|
||||
*
|
||||
* @todo.
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup views_handlers About Views handlers
|
||||
* @{
|
||||
|
@ -186,98 +161,16 @@
|
|||
* horizontally. This means that you can add options and do stuff on all
|
||||
* views displays. One theoretical example is metatags for views.
|
||||
*
|
||||
* Plugins are registered by implementing hook_views_plugins() in your
|
||||
* modulename.views.inc file and returning an array of data.
|
||||
* For examples please look at views_views_plugins() in
|
||||
* views/includes/plugins.inc as it has examples for all of them.
|
||||
* Plugins are registered by extending one of the Views base plugin classes
|
||||
* and defining settings in the plugin annotation.
|
||||
*
|
||||
* Similar to handlers, make sure that you add your plugin files to the
|
||||
* module.info file.
|
||||
* @todo Document how to use annotations and what goes in them.
|
||||
* @todo Add @ingroup to all the base plugins for this group.
|
||||
* @todo Add a separate @ingroup for all plugins?
|
||||
* @todo Document specific options on the appropriate plugin base classes.
|
||||
* @todo Add examples.
|
||||
*
|
||||
* The array defining plugins will look something like this:
|
||||
* @code
|
||||
* return array(
|
||||
* 'display' => array(
|
||||
* // ... list of display plugins,
|
||||
* ),
|
||||
* 'style' => array(
|
||||
* // ... list of style plugins,
|
||||
* ),
|
||||
* 'row' => array(
|
||||
* // ... list of row style plugins,
|
||||
* ),
|
||||
* 'argument default' => array(
|
||||
* // ... list of argument default plugins,
|
||||
* ),
|
||||
* 'argument validator' => array(
|
||||
* // ... list of argument validator plugins,
|
||||
* ),
|
||||
* 'access' => array(
|
||||
* // ... list of access plugins,
|
||||
* ),
|
||||
* 'query' => array(
|
||||
* // ... list of query plugins,
|
||||
* ),,
|
||||
* 'cache' => array(
|
||||
* // ... list of cache plugins,
|
||||
* ),,
|
||||
* 'pager' => array(
|
||||
* // ... list of pager plugins,
|
||||
* ),,
|
||||
* 'exposed_form' => array(
|
||||
* // ... list of exposed_form plugins,
|
||||
* ),,
|
||||
* 'localization' => array(
|
||||
* // ... list of localization plugins,
|
||||
* ),
|
||||
* 'display_extender' => array(
|
||||
* // ... list of display extender plugins,
|
||||
* ),
|
||||
* );
|
||||
* @endcode
|
||||
*
|
||||
* Each plugin will be registered with an identifier for the plugin, plus a
|
||||
* fairly lengthy list of items that can define how and where the plugin is
|
||||
* used. Here is an example of a row style plugin from Views core:
|
||||
* @code
|
||||
* 'node' => array(
|
||||
* 'title' => t('Node'),
|
||||
* 'help' => t('Display the node with standard node view.'),
|
||||
* 'handler' => 'views_plugin_row_node_view',
|
||||
* 'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
|
||||
* 'theme' => 'views_view_row_node',
|
||||
* 'base' => array('node'), // only works with 'node' as base.
|
||||
* 'type' => 'normal',
|
||||
* ),
|
||||
* @endcode
|
||||
*
|
||||
* Of particular interest is the *path* directive, which works a little
|
||||
* differently from handler registration; each plugin must define its own path,
|
||||
* rather than relying on a global info for the paths. For example:
|
||||
* @code
|
||||
* 'feed' => array(
|
||||
* 'title' => t('Feed'),
|
||||
* 'help' => t('Display the view as a feed, such as an RSS feed.'),
|
||||
* 'handler' => 'views_plugin_display_feed',
|
||||
* 'uses_hook_menu' => TRUE,
|
||||
* 'use_ajax' => FALSE,
|
||||
* 'use_pager' => FALSE,
|
||||
* 'accept_attachments' => FALSE,
|
||||
* 'admin' => t('Feed'),
|
||||
* ),
|
||||
* @endcode
|
||||
*
|
||||
* Please be sure to prefix your plugin identifiers with your module name to
|
||||
* ensure namespace safety; after all, two different modules could try to
|
||||
* implement the 'grid2' plugin, and that would cause one plugin to completely
|
||||
* fail.
|
||||
*
|
||||
* @todo Finish this document.
|
||||
*
|
||||
* See also:
|
||||
* - @link views_display_plugins Views display plugins @endlink
|
||||
* - @link views_style_plugins Views style plugins @endlink
|
||||
* - @link views_row_plugins Views row plugins @endlink
|
||||
* @see Drupal\views\Plugin\views\PluginBase
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -496,263 +389,6 @@ function hook_views_data_alter(array &$data) {
|
|||
// Note that the $data array is not returned – it is modified by reference.
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes plugins defined by the module.
|
||||
*
|
||||
* This hook should be placed in MODULENAME.views.inc and it will be
|
||||
* auto-loaded. MODULENAME.views.inc must be in the directory specified by the
|
||||
* 'path' key returned by MODULENAME_views_api(), or the same directory as the
|
||||
* .module file, if 'path' is unspecified.
|
||||
*
|
||||
* @return
|
||||
* An array on the form $plugins['PLUGIN TYPE']['PLUGIN NAME']. The plugin
|
||||
* must be one of row, display, display_extender, style, argument default,
|
||||
* argument validator, access, query, cache, pager, exposed_form or
|
||||
* localization. The plugin name should be prefixed with your module name.
|
||||
* The value for each entry is an associateive array that may contain the
|
||||
* following entries:
|
||||
* - Used by all plugin types:
|
||||
* - title (required): The name of the plugin, as shown in Views. Wrap in
|
||||
* t().
|
||||
* - handler (required): The name of the file containing the class
|
||||
* describing the handler, which must also be the name of the handler's
|
||||
* class.
|
||||
* - path: Path to the handler. Only required if the handler is not placed
|
||||
* in the same folder as the .module file or in the subfolder 'views'.
|
||||
* - parent: The name of the plugin this plugin extends. Since Drupal 7 this
|
||||
* is no longer required, but may still be useful from a code readability
|
||||
* perspective.
|
||||
* - no_ui: Set to TRUE to denote that the plugin doesn't appear to be
|
||||
* selectable in the ui, though on the api side they still exists.
|
||||
* - help: A short help text, wrapped in t() used as description on the plugin settings form.
|
||||
* - theme: The name of a theme suggestion to use for the display.
|
||||
* - js: An array with paths to js files that should be included for the
|
||||
* display. Note that the path should be relative Drupal root, not module
|
||||
* root.
|
||||
* - type: Each plugin can specify a type parameter to group certain
|
||||
* plugins together. For example all row plugins related to feeds are
|
||||
* grouped together, because a rss style plugin only accepts feed row
|
||||
* plugins.
|
||||
*
|
||||
* - Used by display plugins:
|
||||
* - admin: The administrative name of the display, as displayed on the
|
||||
* Views overview and also used as default name for new displays. Wrap in
|
||||
* t().
|
||||
* - no remove: Set to TRUE to make the display non-removable. (Basically
|
||||
* only used for the master/default display.)
|
||||
* - use_ajax: Set to TRUE to allow AJAX loads in the display. If it's
|
||||
* disabled there will be no ajax option in the ui.
|
||||
* - use_pager: Set to TRUE to allow paging in the display.
|
||||
* - use_more: Set to TRUE to allow the 'use_more' setting in the display.
|
||||
* - accept_attachments: Set to TRUE to allow attachment displays to be
|
||||
* attached to this display type.
|
||||
* - contextual_links_locations: An array with places where contextual links
|
||||
* should be added. Can for example be 'page' or 'block'. If you don't
|
||||
* specify it there will be contextual links around the rendered view.
|
||||
* - uses_hook_menu: Set to TRUE to have the display included by
|
||||
* views_menu_alter(). views_menu_alter executes then execute_hook_menu
|
||||
* on the display object.
|
||||
* - uses_hook_block: Set to TRUE to have the display included by
|
||||
* views_block_info().
|
||||
* - theme: The name of a theme suggestion to use for the display.
|
||||
* - js: An array with paths to js files that should be included for the
|
||||
* display. Note that the path should be relative Drupal root, not module
|
||||
* root.
|
||||
*
|
||||
* - Used by style plugins:
|
||||
* - uses_row_plugin: Set to TRUE to allow row plugins for this style.
|
||||
* - uses_row_class: Set to TRUE to allow the CSS class settings for rows.
|
||||
* - uses_fields: Set to TRUE to have the style plugin accept field
|
||||
* handlers.
|
||||
* - uses grouping: Set to TRUE to allow the grouping settings for rows.
|
||||
* - even empty: May have the value 'even empty' to tell Views that the style
|
||||
* should be rendered even if there are no results.
|
||||
*
|
||||
* - Used by row plugins:
|
||||
* - uses_fields: Set to TRUE to have the row plugin accept field handlers.
|
||||
*/
|
||||
function hook_views_plugins() {
|
||||
$plugins = array();
|
||||
$plugins['argument validator'] = array(
|
||||
'taxonomy_term' => array(
|
||||
'title' => t('Taxonomy term'),
|
||||
'handler' => 'views_plugin_argument_validate_taxonomy_term',
|
||||
// Declaring path explicitly not necessary for most modules.
|
||||
'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
|
||||
),
|
||||
);
|
||||
|
||||
return array(
|
||||
'module' => 'views', // This just tells our themes are elsewhere.
|
||||
'argument validator' => array(
|
||||
'taxonomy_term' => array(
|
||||
'title' => t('Taxonomy term'),
|
||||
'handler' => 'views_plugin_argument_validate_taxonomy_term',
|
||||
'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', // not necessary for most modules
|
||||
),
|
||||
),
|
||||
'argument default' => array(
|
||||
'taxonomy_tid' => array(
|
||||
'title' => t('Taxonomy term ID from URL'),
|
||||
'handler' => 'views_plugin_argument_default_taxonomy_tid',
|
||||
'path' => drupal_get_path('module', 'views') . '/modules/taxonomy',
|
||||
'parent' => 'fixed',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter existing plugins data, defined by modules.
|
||||
*
|
||||
* @see hook_views_plugins()
|
||||
*/
|
||||
function hook_views_plugins_alter(&$plugins) {
|
||||
// Add apachesolr to the base of the node row plugin.
|
||||
$plugins['row']['node']['base'][] = 'apachesolr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register View API information.
|
||||
*
|
||||
* This is required for your module to have its include files loaded; for
|
||||
* example, when implementing hook_views_default_views().
|
||||
*
|
||||
* @return
|
||||
* An array with the following possible keys:
|
||||
* - api: (required) The version of the Views API the module implements.
|
||||
* - path: (optional) If includes are stored somewhere other than within the
|
||||
* root module directory, specify its path here.
|
||||
* - template path: (optional) A path where the module has stored it's views
|
||||
* template files. When you have specificed this key views automatically
|
||||
* uses the template files for the views. You can use the same naming
|
||||
* conventions like for normal views template files.
|
||||
*/
|
||||
function hook_views_api() {
|
||||
return array(
|
||||
'api' => 3,
|
||||
'path' => drupal_get_path('module', 'example') . '/includes/views',
|
||||
'template path' => drupal_get_path('module', 'example') . '/themes',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This hook allows modules to provide their own views which can either be used
|
||||
* as-is or as a "starter" for users to build from.
|
||||
*
|
||||
* This hook should be placed in MODULENAME.views.inc and it will be
|
||||
* auto-loaded. MODULENAME.views.inc must be in the directory specified by the
|
||||
* 'path' key returned by MODULENAME_views_api(), or the same directory as the
|
||||
* .module file, if 'path' is unspecified.
|
||||
*
|
||||
* The $view->disabled boolean flag indicates whether the View should be
|
||||
* enabled (FALSE) or disabled (TRUE) by default.
|
||||
*
|
||||
* @return
|
||||
* An associative array containing the structures of views, as generated from
|
||||
* the Export tab, keyed by the view name. A best practice is to go through
|
||||
* and add t() to all title and label strings, with the exception of menu
|
||||
* strings.
|
||||
*/
|
||||
function hook_views_default_views() {
|
||||
// Begin copy and paste of output from the Export tab of a view.
|
||||
$view = new Drupal\views\ViewExecutable();
|
||||
$view->name = 'frontpage';
|
||||
$view->description = 'Emulates the default Drupal front page; you may set the default home page path to this view to make it your front page.';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'Front page';
|
||||
$view->core = 8;
|
||||
$view->api_version = '3.0';
|
||||
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
||||
|
||||
/* Display: Master */
|
||||
$handler = $view->newDisplay('default', 'Master', 'default');
|
||||
$handler->display['display_options']['access']['type'] = 'none';
|
||||
$handler->display['display_options']['cache']['type'] = 'none';
|
||||
$handler->display['display_options']['query']['type'] = 'views_query';
|
||||
$handler->display['display_options']['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display['display_options']['exposed_form']['type'] = 'basic';
|
||||
$handler->display['display_options']['pager']['type'] = 'full';
|
||||
$handler->display['display_options']['style_plugin'] = 'default';
|
||||
$handler->display['display_options']['row_plugin'] = 'node';
|
||||
/* Sort criterion: Content: Sticky */
|
||||
$handler->display['display_options']['sorts']['sticky']['id'] = 'sticky';
|
||||
$handler->display['display_options']['sorts']['sticky']['table'] = 'node';
|
||||
$handler->display['display_options']['sorts']['sticky']['field'] = 'sticky';
|
||||
$handler->display['display_options']['sorts']['sticky']['order'] = 'DESC';
|
||||
/* Sort criterion: Content: Post date */
|
||||
$handler->display['display_options']['sorts']['created']['id'] = 'created';
|
||||
$handler->display['display_options']['sorts']['created']['table'] = 'node';
|
||||
$handler->display['display_options']['sorts']['created']['field'] = 'created';
|
||||
$handler->display['display_options']['sorts']['created']['order'] = 'DESC';
|
||||
/* Filter criterion: Content: Promoted to front page */
|
||||
$handler->display['display_options']['filters']['promote']['id'] = 'promote';
|
||||
$handler->display['display_options']['filters']['promote']['table'] = 'node';
|
||||
$handler->display['display_options']['filters']['promote']['field'] = 'promote';
|
||||
$handler->display['display_options']['filters']['promote']['value'] = '1';
|
||||
$handler->display['display_options']['filters']['promote']['group'] = 0;
|
||||
$handler->display['display_options']['filters']['promote']['expose']['operator'] = FALSE;
|
||||
/* Filter criterion: Content: Published */
|
||||
$handler->display['display_options']['filters']['status']['id'] = 'status';
|
||||
$handler->display['display_options']['filters']['status']['table'] = 'node';
|
||||
$handler->display['display_options']['filters']['status']['field'] = 'status';
|
||||
$handler->display['display_options']['filters']['status']['value'] = '1';
|
||||
$handler->display['display_options']['filters']['status']['group'] = 0;
|
||||
$handler->display['display_options']['filters']['status']['expose']['operator'] = FALSE;
|
||||
|
||||
/* Display: Page */
|
||||
$handler = $view->newDisplay('page', 'Page', 'page');
|
||||
$handler->display['display_options']['path'] = 'frontpage';
|
||||
|
||||
/* Display: Feed */
|
||||
$handler = $view->newDisplay('feed', 'Feed', 'feed');
|
||||
$handler->display['display_options']['defaults']['title'] = FALSE;
|
||||
$handler->display['display_options']['title'] = 'Front page feed';
|
||||
$handler->display['display_options']['pager']['type'] = 'some';
|
||||
$handler->display['display_options']['style_plugin'] = 'rss';
|
||||
$handler->display['display_options']['row_plugin'] = 'node_rss';
|
||||
$handler->display['display_options']['path'] = 'rss.xml';
|
||||
$handler->display['display_options']['displays'] = array(
|
||||
'default' => 'default',
|
||||
'page' => 'page',
|
||||
);
|
||||
$handler->display['display_options']['sitename_title'] = '1';
|
||||
|
||||
// (Export ends here.)
|
||||
|
||||
// Add view to list of views to provide.
|
||||
$views[$view->name] = $view;
|
||||
|
||||
// ...Repeat all of the above for each view the module should provide.
|
||||
|
||||
// At the end, return array of default views.
|
||||
return $views;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter default views defined by other modules.
|
||||
*
|
||||
* This hook is called right before all default views are cached to the
|
||||
* database. It takes a keyed array of views by reference.
|
||||
*
|
||||
* Example usage to add a field to a view:
|
||||
* @code
|
||||
* $handler =& $view->display['DISPLAY_ID']->handler;
|
||||
* // Add the user name field to the view.
|
||||
* $handler->display['display_options']['fields']['name']['id'] = 'name';
|
||||
* $handler->display['display_options']['fields']['name']['table'] = 'users';
|
||||
* $handler->display['display_options']['fields']['name']['field'] = 'name';
|
||||
* $handler->display['display_options']['fields']['name']['label'] = 'Author';
|
||||
* $handler->display['display_options']['fields']['name']['link_to_user'] = 1;
|
||||
* @endcode
|
||||
*/
|
||||
function hook_views_default_views_alter(&$views) {
|
||||
if (isset($views['taxonomy_term'])) {
|
||||
$views['taxonomy_term']->display['default']['display_options']['title'] = 'Categories';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs replacements in the query before being performed.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue