I've been battering my head against this for hours now, clearing caches, stopping and starting web server, etc. This is just not working and it makes no sense. =(

I have even tried editing an item already visible on the views page to see if it changes - nothing! So frustrating! Could someone tell me what's wrong with this picture? This test item simply will *not* appear as an option under Views:

function whattalent_alpha_views_tables() {
  $tables['node'] = array(
    'name' => 'node',
    'fields' => array(
      'all_images' => array(
        'name' => t('WhatTalent: Test field'),
        'notafield' => true,
        'help' => t('Display all node images in one field.'),
      ),
    ),    
  );
  return $tables;
}

Comments

greg.harvey’s picture

Ok, trying to find out more. I'm expecting the hook_views_tables hook to expose a new item on the Fields select list when I Add/Edit a view. The reason I'm expecting this is I can't really find in the documentation specifically how it says you do this, but I chose a module (node_images) and searched for a string exposed through the Views interface.

So, I searched site-wide for the string "Node Images:", as it appears in the Fields: Add Field form item on the Add view page. This string only appears in ONE PLACE ... in _node_images_views_tables() within node_images.views.inc (which is called by node_images_views_table() in the actual module):

in the include:

function _node_images_views_tables() {
  $tables['node_images'] = array(
    'name' => 'node_images',
    'join' => array(
      'left' => array(
        'table' => 'node',
        'field' => 'nid',
      ),
      'right' => array(
        'field' => 'nid'
      ),
    ),
    
    'fields' => array(
      'all_images' => array(
        'name' => t('Node Images: Display node images'),
        'notafield' => true,
        'query_handler' => 'views_query_handler_node_images',
        'handler' => array(
          'views_handler_node_images' => t('All images'),
        ),
        'option' => array(
          '#type' => 'select',
          '#options' => array(
            'thumbs' => t('Thumbnails'),
            'fullsize' => t('Full size images'),
          )),
        'sortable' => false,
        'help' => t('Display all node images in one field.'),
      ),
    ),
    
    'filters' => array(
      'nid' => array(
        'name' => t('Node images: Has node images'),
        'operator' => array('=' => t('Exists')),
        'list' => 'views_handler_operator_yesno',
        'list-type' => 'select',
        'handler' => 'node_images_handler_images_exist',
        'help' => t('Filter whether the node has node images.'),
      ),
    ),  
  );
  return $tables;
}

and in the module:

/**
 * Implementation of hook_views_default_tables().
 */
function node_images_views_tables() {
  require_once './'. drupal_get_path('module', 'node_images') .'/node_images.views.inc';
  return _node_images_views_tables();
}

Now, since this is THE ONLY PLACE THIS APPEARS IN THE CODE, I altered the string to something else, but nothing - it stayed the same. So I commented it out completely. Still appears.

Cleared the caches, truncating every cache table in the database. It's still there!

So I restarted my computer! Still it is the same! This is an evil issue.

Has anyone experienced this before? I can't believe I'm the only one, but this is driving me nuts.

merlinofchaos’s picture

Status: Active » Closed (works as designed)

Your problem is that you're trying to define a table that already exists. hook_views_tables is for defining new tables, not attempting to override old ones. The 'node' table is already defined.

If you really need to modify an existing table -- and it doesn't appear that you do -- try hook_views_tables_alter

But really, you should be using your own table name. Or a dummy table name.

greg.harvey’s picture

Status: Closed (works as designed) » Active

Thanks for the reply. Ok - that explains why my "test" example doesn't work.

However, I just edited post #1 - if you have time, I'd love to know what you think of that....

merlinofchaos’s picture

Status: Active » Closed (works as designed)

You probably didn't truncate cache_views

And -- one issue per issue, please. It's way too difficult to follow multiple issues in the same thread.

greg.harvey’s picture

Rats, you're right. I have a script, but it was open in MySQL Query Browser and I accidently only ran one of the six lines. =(

Sorry about the issues, but this was my main problem - the other one was a spin-off from it...!