Display table in views

I have a table created by a module. I need to include some of its fields in an existing view.

I tried using the table wizard module , but all it does is create a separate view for this table. I would like to be able to select fields from this table to add to the existing view as additional fields or through relationships or something like that. Is there a way to do what I'm trying to do?

+3
source share
4 answers

Oh. Views He took me at the same time. This answer is for Drupal 6, and in the abstract shows how to define fields and also use a relationship so that the fields can refer to the node table.

Inside modulename.module you need a function that goes:

function modulename_views_api() {
  return array(
    'api' => 2,
  );
}

Then you want to create a file called modulename.views.inc and define a function like this:

function modulename_views_data () {
    $ data ['modulename_table'] = array (
        'table' => array (
            'group' => 'ModuleName',
            'title' => 'Module name title',
        ),
        'join' => array (
            // to join to node, we'll use a field in modulename_table called 'nid'
            'node' => array (
                'left_field' => 'nid',
                'field'         =>  'nid',
            ),
        ),
    );

    // now we define the fields in the table like this
    // check out modules/views/handlers to see more specific handlers

    $data['modulename_table']['fieldname'] = array(
        'title'     => 'fieldname',
        'help'      => 'fieldname description',
        'field'    => array(
            'handler' => 'views_handler_field',
        ),
    );

    $data['modulename_table']['nid'] = array(
        'title'     => 'related node',
        'help'      => 'the field that relates back to {node}',
        // here we implement a relationship to nid
        'relationship'  => array(
            'base'      => 'node',
            'field'     => 'nid',
            'handler'   => 'views_handler_relationship',
            'label'     => 'modulename row node',
        ),
        // this relationship can be turned on in views
    );

    return $data;
}
+4

hook_views_data . , , , API-.

+1

, Views Custom Field , , oddball . , ..

+1
source

Source: https://habr.com/ru/post/1761038/


All Articles