'extra' field in hook_views_data()?

Events happening in the community are now at Drupal community events on www.drupal.org.
somebodysysop's picture

In hook_views_tables, I used the 'extra' field to make sure that when my table was used in a view,it ony used records which matched the current group. i.e.:

<?php
  $tables
['og_users_roles'] = array(
   
'name' => 'og_users_roles',
   
'provider' => 'internal', // won't show up in external list.
   
'join' => array(
     
'left' => array(
       
'table' => 'node',
       
'field' => 'uid'
     
),
     
'right' => array(
       
'field' => 'uid'
     
),
     
'extra' => array(
       
'gid' => '<strong><em>CURRENT_GID</em></strong>'
     
),
    ),
?>

How do I implement this using hook_views_data()?:
<?php
  $data
['og_users_roles']['table']['group']  = t('OGUR Groups');
 
$data['og_users_roles']['table']['join'] = array(
   
'node' => array(
     
'left_field' => 'nid',
     
'field' => 'gid',
    ),
   
'users' => array(
     
'left_field' => 'uid',
     
'field' => 'uid',
    ),
   
'role' => array(
     
'left_field' => 'rid',
     
'field' => 'rid',
    ),
  );
?>

I've been searching for an example, but so far no luck. Thanks for any info anyone can provide.

Comments

<?php 

Scott Reynolds's picture

<?php
  $data
['og_users_roles']['table']['group']  = t('OGUR Groups');
 
$data['og_users_roles']['table']['join'] = array(
   
'node' => array(
     
'left_field' => 'nid',
     
'field' => 'gid',
     
'extra' => 'gid = <strong><em>CURRENT_GID</em></strong>',
    ),
   
'users' => array(
     
'left_field' => 'uid',
     
'field' => 'uid',
     
'extra' => 'gid = <strong><em>CURRENT_GID</em></strong>',
    ),
   
'role' => array(
     
'left_field' => 'rid',
     
'field' => 'rid',
     
'extra' => 'gid = <strong><em>CURRENT_GID</em></strong>',
    ),
  );
?>

If that doesn't work (i didn't test it) look at the views_join class. You will see how extra is used right there.

Thanks!

somebodysysop's picture

Thank you for that assist.

Just implemented one of

Scott Reynolds's picture

Just implemented one of these today figured i would document it. This is going into the new Activity module 2.x branch probably today

<?php
  
// add in the activity message table
 
$data['activity_messages']['table']['group'] = t('Activity');
 
$data['activity_messages']['table']['join'] = array(
   
'activity' => array(
     
'type' => 'INNER',
     
'left_field' => 'amid',
     
'field' => 'amid',
     
'extra' => array(
        array(
         
'value' => 0, // grab the everyone message
         
'numeric' => TRUE,
         
'field' => 'uid',
        ),
      ),
    ),
  );
 
 
// create a faux table, that is really activity messages
 
$data['activity_personal_messages']['table']['join'] = array(
   
'activity' => array(
     
'type' => 'LEFT', // allow this to to have null values
     
'left_field' => 'amid',
     
'field' => 'amid',
     
'extra' => array(
        array(
         
'value' => '<strong><em>CURRENT_USER</em></strong>', // grab the personal message for this user
         
'numeric' => TRUE,
         
'field' => 'uid',
        ),
      ),
     
'table' => 'activity_messages',
    ),
  );
?>

Seems like that this the best way to go. To really define this properly.

'extra' is documented here:

How on earth did you figure

mpaler's picture

@Scott Reynolds. How on earth did you figure out to use a "faux" table. I would have never thought of that. I'm so glad you shared.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week