views_json style plugin

  1. /**
  2.  *  Implementation of hook_views_plugins
  3.  */
  4. function views_json_views_plugins() {
  5.   return array(
  6.     'style' => array(
  7.       'views_json' => array(
  8.         'title' => t('JSON data document'),
  9.         'theme' => 'views_json',
  10.         'help' => t('Renders nodes in the JSON data format.'),
  11.         'handler' => 'views_json_plugin_style',
  12.         'uses row plugin' => TRUE,
  13.         'uses fields' => TRUE,
  14.         'uses options' => TRUE,
  15.         'type' => 'normal',      
  16.       ),
  17.     ),
  18.   );
  19. }
  20.  
  21. class views_json_plugin_style extends views_plugin_style {
  22.   /**
  23.    * Set default options
  24.    */
  25.   function options(&$options) {
  26.     $options['format'] = 'Exhibit';
  27.   }
  28.  
  29.   /**
  30.    * Render the given style.
  31.    */
  32.   function options_form(&$form, &$form_state) {
  33.     $form['format'] = array(
  34.       '#type' => 'radios',
  35.       '#title' => t('JSON data format'),
  36.       '#options' => array('Exhibit' => t('MIT Simile/Exhibit'), 'Canonical' => t('Canonical'), 'JSONP' => t('JSONP')),
  37.       '#default_value' => $this->options['format'],
  38.     );
  39.   }
  40. }
  41.  
  42. function template_preprocess_views_json(&$vars) {
  43.   $view     = &$vars['view'];
  44.   $result   = &$view->result;
  45.   $options  = &$view->style_handler->options;
  46.   $handler  = &$view->style_handler;
  47. }
  48.  
  49. //views-json.tpl.php
  50. <?php
  51. print ('hello views');
  52. ?>