2 // $Id: plugins.inc,v 1.152 2009/01/07 23:31:12 merlinofchaos Exp $
5 * Built in plugins for Views output handling.
10 * Implementation of hook_views_plugins
12 function views_views_plugins() {
13 $path = drupal_get_path('module', 'views') . '/js';
15 'module' => 'views', // This just tells our themes are elsewhere.
18 // this isn't really a display but is necessary so the file can
21 'handler' => 'views_plugin_display',
25 'title' => t('Defaults'),
26 'help' => t('Default settings for this view.'),
27 'handler' => 'views_plugin_display_default',
28 'theme' => 'views_view',
31 'js' => array('misc/collapse.js', 'misc/textarea.js', 'misc/tabledrag.js', 'misc/autocomplete.js', "$path/dependent.js"),
35 'accept attachments' => TRUE,
36 'help topic' => 'display-default',
40 'help' => t('Display the view as a page, with a URL and menu links.'),
41 'handler' => 'views_plugin_display_page',
42 'theme' => 'views_view',
43 'uses hook menu' => TRUE,
46 'accept attachments' => TRUE,
48 'help topic' => 'display-page',
51 'title' => t('Block'),
52 'help' => t('Display the view as a block.'),
53 'handler' => 'views_plugin_display_block',
54 'theme' => 'views_view',
55 'uses hook block' => TRUE,
59 'accept attachments' => TRUE,
60 'admin' => t('Block'),
61 'help topic' => 'display-block',
63 'attachment' => array(
64 'title' => t('Attachment'),
65 'help' => t('Attachments added to other displays to achieve multiple views in the same view.'),
66 'handler' => 'views_plugin_display_attachment',
67 'theme' => 'views_view',
69 'help topic' => 'display-attachment',
73 'help' => t('Display the view as a feed, such as an RSS feed.'),
74 'handler' => 'views_plugin_display_feed',
75 'parent' => 'page', // so it knows to load the page plugin .inc file
76 'uses hook menu' => TRUE,
79 'accept attachments' => FALSE,
81 'help topic' => 'display-feed',
86 // this isn't really a display but is necessary so the file can
89 'handler' => 'views_plugin_style',
93 'title' => t('Unformatted'),
94 'help' => t('Displays rows one after another.'),
95 'handler' => 'views_plugin_style_default',
96 'theme' => 'views_view_unformatted',
97 'uses row plugin' => TRUE,
98 'uses options' => TRUE,
99 'uses grouping' => TRUE,
101 'help topic' => 'style-unformatted',
104 'title' => t('HTML List'),
105 'help' => t('Displays rows as an HTML list.'),
106 'handler' => 'views_plugin_style_list',
107 'theme' => 'views_view_list',
108 'uses row plugin' => TRUE,
109 'uses options' => TRUE,
111 'help topic' => 'style-list',
114 'title' => t('Grid'),
115 'help' => t('Displays rows in a grid.'),
116 'handler' => 'views_plugin_style_grid',
117 'theme' => 'views_view_grid',
118 'uses row plugin' => TRUE,
119 'uses options' => TRUE,
121 'help topic' => 'style-grid',
124 'title' => t('Table'),
125 'help' => t('Displays rows in a table.'),
126 'handler' => 'views_plugin_style_table',
127 'theme' => 'views_view_table',
128 'uses row plugin' => FALSE,
129 'uses fields' => TRUE,
130 'uses options' => TRUE,
132 'help topic' => 'style-table',
134 'default_summary' => array(
135 'title' => t('List'),
136 'help' => t('Displays the default summary as a list.'),
137 'handler' => 'views_plugin_style_summary',
138 'theme' => 'views_view_summary',
139 'type' => 'summary', // only shows up as a summary style
140 'uses options' => TRUE,
141 'help topic' => 'style-summary',
143 'unformatted_summary' => array(
144 'title' => t('Unformatted'),
145 'help' => t('Displays the summary unformatted, with option for one after another or inline.'),
146 'handler' => 'views_plugin_style_summary_unformatted',
147 'parent' => 'default_summary',
148 'theme' => 'views_view_summary_unformatted',
149 'type' => 'summary', // only shows up as a summary style
150 'uses options' => TRUE,
151 'help topic' => 'style-summary-unformatted',
154 'title' => t('RSS Feed'),
155 'help' => t('Generates an RSS feed from a view.'),
156 'handler' => 'views_plugin_style_rss',
157 'theme' => 'views_view_rss',
158 'uses row plugin' => TRUE,
159 'uses options' => TRUE,
161 'help topic' => 'style-rss',
166 // this isn't really a display but is necessary so the file can
169 'handler' => 'views_plugin_row',
173 'title' => t('Fields'),
174 'help' => t('Displays the fields with an optional template.'),
175 'handler' => 'views_plugin_row_fields',
176 'theme' => 'views_view_fields',
177 'uses fields' => TRUE,
178 'uses options' => TRUE,
180 'help topic' => 'style-row-fields',
183 'argument default' => array(
184 // This type of plugin does not conform to the standard and
185 // uses 'fixed' as the parent rather than having a separate parent.
187 'title' => t('Fixed entry'),
188 'handler' => 'views_plugin_argument_default',
191 'title' => t('PHP Code'),
192 'handler' => 'views_plugin_argument_default_php',
196 'argument validator' => array(
199 'handler' => 'views_plugin_argument_validate',
203 'title' => t('PHP Code'),
204 'handler' => 'views_plugin_argument_validate_php',
207 'title' => t('Numeric'),
208 'handler' => 'views_plugin_argument_validate_numeric',
214 'handler' => 'views_plugin_access',
218 'title' => t('None'),
219 'help' => t('Will be available to all users.'),
220 'handler' => 'views_plugin_access_none',
221 'help topic' => 'access-none',
224 'title' => t('Role'),
225 'help' => t('Access will be granted to users with any of the specified roles.'),
226 'handler' => 'views_plugin_access_role',
227 'uses options' => TRUE,
228 'help topic' => 'access-role',
231 'title' => t('Permission'),
232 'help' => t('Access will be granted to users with the specified permission string.'),
233 'handler' => 'views_plugin_access_perm',
234 'uses options' => TRUE,
235 'help topic' => 'access-perm',
242 * Builds and return a list of all plugins available in the system.
244 * @return Nested array of plugins, grouped by type.
246 function views_discover_plugins() {
247 $cache = array('display' => array(), 'style' => array(), 'row' => array(), 'argument default' => array(), 'argument validator' => array(), 'access' => array());
248 // Get plugins from all mdoules.
249 foreach (module_implements('views_plugins') as $module) {
250 $function = $module . '_views_plugins';
251 $result = $function();
252 if (!is_array($result)) {
256 $module_dir = isset($result['module']) ? $result['module'] : $module;
257 // Setup automatic path/file finding for theme registration
258 if ($module_dir == 'views') {
259 $theme_path = drupal_get_path('module', $module_dir) . '/theme';
260 $theme_file = 'theme.inc';
261 $path = drupal_get_path('module', $module_dir) . '/plugins';
264 $theme_path = $path = drupal_get_path('module', $module_dir);
265 $theme_file = "$module.views.inc";
268 foreach ($result as $type => $info) {
269 if ($type == 'module') {
272 foreach ($info as $plugin => $def) {
273 $def['module'] = $module_dir;
274 if (!isset($def['theme path'])) {
275 $def['theme path'] = $theme_path;
277 if (!isset($def['theme file'])) {
278 $def['theme file'] = $theme_file;
280 if (!isset($def['path'])) {
281 $def['path'] = $path;
283 if (!isset($def['file'])) {
284 $def['file'] = $def['handler'] . '.inc';
286 if (!isset($def['parent'])) {
287 $def['parent'] = 'parent';
289 // merge the new data in
290 $cache[$type][$plugin] = $def;
298 * Abstract base class to provide interface common to all plugins.
300 class views_plugin extends views_object {
302 * Init will be called after construct, when the plugin is attached to a
303 * view and a display.
305 function init(&$view, &$display) {
306 $this->view = &$view;
307 $this->display = &$display;
311 * Provide a form to edit options for this plugin.
313 function options_form(&$form, &$form_state) { }
316 * Validate the options form.
318 function options_validate(&$form, &$form_state) { }
321 * Handle any special handling on the validate form.
323 function options_submit(&$form, &$form_state) { }
326 * Add anything to the query that we might need to.
331 * Provide a full list of possible theme templates used by this style.
333 function theme_functions() {
334 return views_theme_functions($this->definition['theme'], $this->view, $this->display);
338 * Provide a list of additional theme functions for the theme information page
340 function additional_theme_functions() {
342 if (!empty($this->definition['additional themes'])) {
343 foreach ($this->definition['additional themes'] as $theme => $type) {
344 $funcs[] = views_theme_functions($theme, $this->view, $this->display);
351 * Validate that the plugin is correct and can be saved.
354 * An array of error strings to tell the user what is wrong with this
357 function validate() { return array(); }
360 // @todo move all these defgroups into their respective .inc files.
363 * @defgroup views_style_plugins Views' style plugins
365 * Style plugins control how a view is rendered. For example, they
366 * can choose to display a collection of fields, node_view() output,
367 * table output, or any kind of crazy output they want.
369 * Many style plugins can have an optional 'row' plugin, that displays
370 * a single record. Not all style plugins can utilize this, so it is
371 * up to the plugin to set this up and call through to the row plugin.
373 * @see hook_views_plugins
382 * @defgroup views_row_plugins Views' row plugins
385 * Row plugins control how Views outputs an individual record. They are
386 * tightly coupled to style plugins, in that a style plugin is what calls
389 * @see hook_views_plugins
397 * @defgroup views_argument_default_plugins Views' argument default plugins
400 * Allow specialized methods of filling in arguments when they aren't
403 * @see hook_views_plugins
411 * @defgroup views_argument_validate_plugins Views' argument validate plugins
414 * Allow specialized methods of validating arguments.
416 * @see hook_views_plugins