title: Exposing a module's data to Views2 using its API
body: <p>I'm forking the <a href="http://drupal.org/project/filefield_stats" rel="nofollow noreferrer">filefield_stats</a> module to provide it with the ability of exposing data into the <a href="http://drupal.org/project/views" rel="nofollow noreferrer">Views</a> module via the <a href="http://views2.logrus.com/doc/html/index.html" rel="nofollow noreferrer">API</a>.
  The filefield_stats schema is as follow:</p>
  
  <pre><code>function filefield_stats_schema() {
    $schema['filefield_stats'] = array(
      'fields' =&gt; array(      
        'fid'       =&gt; array('type' =&gt; 'int', 'unsigned' =&gt; TRUE, 'not null' =&gt; TRUE, 'description' =&gt; 'Primary Key: the {files}.fid'),
        'vid'       =&gt; array('type' =&gt; 'int', 'unsigned' =&gt; TRUE, 'not null' =&gt; TRUE, 'description' =&gt; 'Primary Key: the {node}.vid'),      
        'uid'       =&gt; array('type' =&gt; 'int', 'unsigned' =&gt; TRUE, 'not null' =&gt; TRUE, 'description' =&gt; 'The {users}.uid of the downloader'),
        'timestamp' =&gt; array('type' =&gt; 'int', 'unsigned' =&gt; TRUE, 'not null' =&gt; TRUE, 'description' =&gt; 'The timestamp of the download'),
        'hostname'  =&gt; array('type' =&gt; 'varchar', 'length' =&gt; 128, 'not null' =&gt; TRUE, 'default' =&gt; '', 'description' =&gt; 'The hostname downloading the file (usually IP)'),
        'referer'   =&gt; array('type' =&gt; 'text', 'not null' =&gt; FALSE, 'description' =&gt; 'Referer for the download'),   
      ),
      'indexes' =&gt; array('fid_vid' =&gt; array('fid', 'vid')),
    );
    return $schema;
  }
  </code></pre>
  
  <p>Well, so I implemented the <strong>hook_views_api()</strong> in <em>filefield_stats.module</em> &amp; added a <em>filefield_stats.views.inc</em> file in the module's root directory, here it is:</p>
  
  <pre><code>// $Id$
  
  /**
   * @file
   * Provide the ability of exposing data to Views2, for filefield_stats module.
   */
  
  function filefield_stats_views_data() {
      $data = array();
      $data['filefield_stats']['table']['group'] = t('FilefieldStats');
  
      // Referencing the {node_revisions} table.
      $data['filefield_stats']['table']['join'] = array(
          'node_revisions' =&gt; array(
              'left_field' =&gt; 'vid',
              'field' =&gt; 'vid',
          ),
          'files' =&gt; array(
              'left_field' =&gt; 'fid',
              'field' =&gt; 'fid',
          ),
          'users' =&gt; array(
              'left_field' =&gt; 'uid',
              'field' =&gt; 'uid',
          ),
      );
  
      // Introducing filefield_stats table fields to Views2.
      // vid: The node's revision ID which wrapped the downloaded file
      $data['filefield_stats']['vid'] = array(
          'title' =&gt; t('Node revision ID'),
          'help' =&gt; t('The node\'s revision ID which wrapped the downloaded file'),
          'relationship' =&gt; array(
              'base' =&gt; 'node_revisions',
              'field' =&gt; 'vid',
              'handler' =&gt; 'views_handler_relationship',
              'label' =&gt; t('Node Revision Reference.'),
          ),
      );
  
      // uid: The ID of the user who downloaded the file.
      $data['filefield_stats']['uid'] = array(
          'title' =&gt; t('User ID'),
          'help' =&gt; t('The ID of the user who downloaded the file.'),
          'relationship' =&gt; array(
              'base' =&gt; 'users',
              'field' =&gt; 'uid',
              'handler' =&gt; 'views_handler_relationship',
              'label' =&gt; t('User Reference.'),
          ),
      );
  
      // fid: The ID of the downloaded file.
      $data['filefield_stats']['fid'] = array(
          'title' =&gt; t('File ID'),
          'help' =&gt; t('The ID of the downloaded file.'),
          'relationship' =&gt; array(
              'base' =&gt; 'files',
              'field' =&gt; 'fid',
              'handler' =&gt; 'views_handler_relationship',
              'label' =&gt; t('File Reference.'),
          ),
      );
  
      // hostname: The hostname which the file has been downloaded from.
      $data['filefield_stats']['hostname'] = array(
          'title' =&gt; t('The Hostname'),
          'help' =&gt; t('The hostname which the file has been downloaded from.'),
          'field' =&gt; array(
              'handler' =&gt; 'views_handler_field',
              'click sortable' =&gt; TRUE,
          ),
          'sort' =&gt; array(
              'handler' =&gt; 'views_handler_sort',
          ),
          'filter' =&gt; array(
              'handler' =&gt; 'views_handler_filter_string',
          ),
          'argument' =&gt; array(
              'handler' =&gt; 'views_handler_argument_string',
          ),
      );
  
      // referer: The referer address which the file download link has been triggered from.
      $data['filefield_stats']['referer'] = array(
          'title' =&gt; t('The Referer'),
          'help' =&gt; t('The referer which the file download link has been triggered from.'),
          'field' =&gt; array(
              'handler' =&gt; 'views_handler_field',
              'click sortable' =&gt; TRUE,
          ),
          'sort' =&gt; array(
              'handler' =&gt; 'views_handler_sort',
          ),
          'filter' =&gt; array(
              'handler' =&gt; 'views_handler_filter_string',
          ),
          'argument' =&gt; array(
              'handler' =&gt; 'views_handler_argument_string',
          ),
      );
  
      // timestamp: The time of the download.
      $data['filefield_stats']['timestamp'] = array(
          'title' =&gt; t('Download Time'),
          'help' =&gt; t('The time of the download.'),
          'field' =&gt; array(
              'handler' =&gt; 'views_handler_field_date',
              'click sortable' =&gt; TRUE,
          ),
          'sort' =&gt; array(
              'handler' =&gt; 'views_handler_sort_date',
          ),
          'filter' =&gt; array(
              'handler' =&gt; 'views_handler_filter_date',
          ),
      );
  
      return $data;
  } // filefield_stats_views_data()
  </code></pre>
  
  <p>According to the Views2 documentations this should work as a minimum, I think. But it doesn't! Also there is no error of any kind, when I come through the views UI, there's nothing about filefield_stats data. Any idea?</p>