function hook_views_data_alter

Same name and namespace in other branches
  1. 7.x-3.x views.api.php \hook_views_data_alter()

Alter table structure.

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

This hook should be placed in MODULENAME.views.inc and it will be auto-loaded. This must either be in the same directory as the .module file or in a subdirectory named 'includes'.

The full documentation for this hook is in the advanced help. http://views-help.doc.logrus.com/help/views/api-tables

Related topics

14 functions implement hook_views_data_alter()

Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.

CommentViewsHooks::viewsDataAlter in core/modules/comment/src/Hook/CommentViewsHooks.php
Implements hook_views_data_alter().
comment_views_data_alter in modules/comment.views.inc
Use views_data_alter to add items to the node table that are relevant to comments.
ContactViewsHooks::viewsDataAlter in core/modules/contact/src/Hook/ContactViewsHooks.php
Implements hook_views_data_alter().
ContentModerationTestViewsHooks::viewsDataAlter in core/modules/content_moderation/tests/modules/content_moderation_test_views/src/Hook/ContentModerationTestViewsHooks.php
Implements hook_views_data_alter().
ContentTranslationHooks::viewsDataAlter in core/modules/content_translation/src/Hook/ContentTranslationHooks.php
Implements hook_views_data_alter().

... See full list

1 invocation of hook_views_data_alter()
_views_fetch_data in includes/cache.inc
Fetch Views' data from the cache

File

docs/docs.php, line 220

Code

function hook_views_data_alter(&$data) {
    // This example alters the title of the node: nid field for the admin.
    $data['node']['nid']['title'] = t('Node-Nid');
    // This example adds a example field to the users table
    $data['users']['example_field'] = array(
        'title' => t('Example field'),
        'help' => t('Some examüple content that references a user'),
        'handler' => 'hook_handlers_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']['handler'] = 'modulename_handlers_field_node_title';
}