1

drupal 7 - ビュー 3.0 API に関して、カスタム コンテンツ タイプと ID を表示するフィールドの 1 つからデータを取得するように (UI から) ビューを構成しました。私のカスタムテーブルへの結合を作成し(プログラムで希望)、ビューのIDにマップするテキストを表示したいと思います。私が抱えている問題は、結合するテーブルとフィールドをどのように見つけるかです。私のコンテンツ タイプでは、field_game フィールドを作成しました。私のカスタム テーブルには、主キーとして gameid があります。

たぶん、このようなものですか?

$data['MYCUSTOMTABLE']['table']['join'] = array(
// Index this array by the table name to which this table refers.
// 'left_field' is the primary key in the referenced table.
// 'field' is the foreign key in this table.
'node' => array(
  'left_table' => '??????'
  'left_field' => 'field_game', 
  'field' => 'gameid',
),
);

私は高低を検索しましたが、実際に近づくものはありません。どんな助けでも大歓迎です。

4

2 に答える 2

3

同様の問題を探しているときに、この投稿を見つけました。しかし、私はすでにあなたの問題を解決しました。

これを hook_views_query_alter($view, $query) に入れました:

if ($view->name == "kompasses") {

$ga_join = new views_join();
$ga_join->table = 'field_data_group_audience';
$ga_join->field = 'entity_id';
$ga_join->left_table = 'node';
$ga_join->left_field = 'nid';
$ga_join->type = 'inner';

$query->add_relationship('audience_node', $ga_join, 'node', null);
}

ここで結合するテーブルは、field_data_group_audience とベース テーブル (「kompasses」という名前の既存のビューから取得) です。Audience_node は、結合のテーブル エイリアスになります。

詳細については、http: //api.drupal.org/api/views/plugins%21views_plugin_query_default.inc/class/views_plugin_query_default/7を参照してください。

于 2012-08-28T14:21:02.333 に答える
0

あなたは近いですが、これをチェックしてください: Views には、モジュール コードでこれを行う方法に関するドキュメントがあります。views/docs/views.api.php をチェックして読んでください!

http://drupalcontrib.org/api/drupal/contributions%21views%21views.api.php/7はそこにあるソース コードで、役立つコメントがたくさんあります (下部のソースを表示)。

基本的には、hook_views_data_alter を実装して、ビューにテーブルについて伝える必要があります。これで参加できるようになります。結合されたフィールドを表示するには、hook_views_data_alter に渡される配列に正しいハンドラーを設定する必要があります。views.api.php の 343 行目あたりを見てください。

<?php
// This table references the {node} table. The declaration below creates an
// 'implicit' relationship to the node table, so that when 'node' is the base
// table, the fields are automatically available.
$data['example_table']['table']['join'] = array(
  // Index this array by the table name to which this table refers.
  // 'left_field' is the primary key in the referenced table.
  // 'field' is the foreign key in this table.
  'node' => array(
    'left_field' => 'nid',
    'field' => 'nid',
  ),
);

// Next, describe each of the individual fields in this table to Views. This
// is done by describing $data['example_table']['FIELD_NAME']. This part of
// the array may then have further entries:
//   - title: The label for the table field, as presented in Views.
//   - help: The description text for the table field.
//   - relation: A description of any relation handler for the table field.
//   - field: A description of any field handler for the table field.
//   - sort: A description of any sort handler for the table field.
//   - filter: A description of any filter handler for the table field.
//   - argument: A description of any argument handler for the table field.
//   - area: A description of any handler for adding content to header,
//     footer or as no result behaviour.
//
// The handler descriptions are described with examples below.

// Node ID table field.
$data['example_table']['nid'] = array(
  'title' => t('Example content'),
  'help' => t('Some example content that references a node.'),
  // The nid is a foreign key to the {node} table. This allows us to (easily)
  // add a relationship handler for this table field, making all the table
  // fields for the related node available.
  'relationship' => array(
    'base' => 'node', // The name of the table to join with
    'field' => 'nid', // The name of the field to join with
    'handler' => 'views_handler_relationship',
    'label' => t('Example node'),
  ),
);
于 2012-06-19T14:42:50.750 に答える