6.x-3.x docs.php hook_views_data_alter(&$data)
7.x-3.x views.api.php hook_views_data_alter(&$data)

Alter table structure.

You can add/edit/remove existing tables defined by hook_views_data().

This hook should be placed in MODULENAME.views.inc and it will be auto-loaded. MODULENAME.views.inc must be in the directory specified by the 'path' key returned by MODULENAME_views_api(), or the same directory as the .module file, if 'path' is unspecified.


array $data: An array of all Views data, passed by reference. See hook_views_data() for structure.

See also


Related topics

10 functions implement hook_views_data_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

comment_views_data_alter in modules/comment.views.inc
Implements hook_views_data_alter() on behalf of comment.module.
contact_views_data_alter in modules/contact.views.inc
Implements hook_views_data_alter().
field_views_data_alter in modules/field.views.inc
Implements hook_views_data_alter().
file_field_views_data_views_data_alter in modules/file.views.inc
Implements hook_field_views_data_views_data_alter().
image_field_views_data_views_data_alter in modules/image.views.inc
Implements hook_field_views_data_views_data_alter().

... See full list


./views.api.php, line 480
Describe hooks provided by the Views module.


function hook_views_data_alter(&$data) {

  // This example alters the title of the node:nid field in the Views UI.
  $data['node']['nid']['title'] = t('Node-Nid');

  // This example adds an example field to the users table.
  $data['users']['example_field'] = array(
    'title' => t('Example field'),
    'help' => t('Some example content that references a user'),
    'field' => array(
      'handler' => 'modulename_handler_field_example_field',

  // This example changes the handler of the node title field.
  // In this handler you could do stuff, like preview of the node when clicking
  // the node title.
  $data['node']['title']['field']['handler'] = 'modulename_handler_field_node_title';

  // This example adds a relationship to table {foo}, so that 'foo' views can
  // add this table using a relationship. Because we don't want to write over
  // the primary key field definition for the {foo}.fid field, we use a dummy
  // field name as the key.
  $data['foo']['dummy_name'] = array(
    'title' => t('Example relationship'),
    'help' => t('Example help'),
    'relationship' => array(
      // Table we're joining to.
      'base' => 'example_table',
      // Field on the joined table.
      'base field' => 'eid',
      // Real field name on the 'foo' table.
      'field' => 'fid',
      'handler' => 'views_handler_relationship',
      'label' => t('Default label for relationship'),
      'title' => t('Title seen when adding relationship'),
      'help' => t('More information about relationship.'),

  // Note that the $data array is not returned – it is modified by reference.


ShaneOnABike’s picture

I was wracking my brain on how to properly implement relationships along side hook_views_data for customization. The example above helps but there really isn't that much documentation to explain this...

I found this example super SUPER helpful http://alvinalexander.com/drupal-code-examples/drupal-7-votingapi-projec...

tygbiten’s picture

Is there any way to control in what order the implementation of this hook by different modules is called?

I want my module to be the last module to be called but other modules I have installed override my changes by being called after.

mortona2k’s picture

You can change the order of hook implementation via module weight: https://drupal.org/node/110238

But I don't think that's what you want. Look at $data['foo']['dummy_name'], they use dummy_name here to avoid conflict with an existing definition.