2 * Implements hook_views_data_alter().
4 function {{ machine_name }}_views_data_alter(array &$data) {
5 // Alter the title of the node_field_data:nid field in the Views UI.
6 $data['node_field_data']['nid']['title'] = t('Node-Nid');
8 // Add an additional field to the users_field_data table.
9 $data['users_field_data']['example_field'] = [
10 'title' => t('Example field'),
11 'help' => t('Some example content that references a user'),
14 // ID of the field handler to use.
15 'id' => 'example_field',
19 // Change the handler of the node title field, presumably to a handler plugin
20 // you define in your module. Give the ID of this plugin.
21 $data['node_field_data']['title']['field']['id'] = 'node_title';
23 // Add a relationship that will allow a view whose base table is 'foo' (from
24 // another module) to have a relationship to 'example_table' (from my module),
25 // via joining foo.fid to example_table.eid.
27 // This relationship has to be added to the 'foo' Views data, which my module
28 // does not control, so it must be done in hook_views_data_alter(), not
31 // In Views data definitions, each field can have only one relationship. So
32 // rather than adding this relationship directly to the $data['foo']['fid']
33 // field entry, which could overwrite an existing relationship, we define
34 // a dummy field key to handle the relationship.
35 $data['foo']['unique_dummy_name'] = [
36 'title' => t('Title seen while adding relationship'),
37 'help' => t('More information about the relationship'),
40 // Views name of the table being joined to from foo.
41 'base' => 'example_table',
42 // Database field name in example_table for the join.
43 'base field' => 'eid',
44 // Real database field name in foo for the join, to override
45 // 'unique_dummy_name'.
47 // ID of relationship handler plugin to use.
49 'label' => t('Default label for relationship'),
53 // Note that the $data array is not returned – it is modified by reference.