1

我有一个只有一个基表的自定义实体,它被带有字段 field_a 的节点引用。现在我想创建这两个实体(节点和我的自定义实体)之间的关系。我可以得到结果,但我没有得到视图字段部分中列出的节点字段。

// 自定义实体的基表是“clinical_trial_research_sites”

function clinical_trial_views_data_alter(&$data) {
 $data['clinical_trial_research_sites']['node'] = array(
    'title' => t('Clinical Trial'),
    'help' => t('Field Reference Appear in Location Content type.'),
    // Information of the referenced table!!
    'relationship' => array(
      'handler' => 'views_handler_relationship',
      'label' => t('Location'),
      'base' => 'field_data_field_site_comp_code', // node field table name
      'base field' => 'field_site_comp_code_value', // field column name of node field
      'relationship field' => 'site_comp_code', // This is referencing field in my custom entity
    ),
  );
}

我可以让 sql 工作,内部连接工作,但视图没有列出节点的所有字段,因为我也想显示节点中的一些字段!!。我想我缺少一些信息来告诉视图关系不仅是字段表,而且是整个节点!

4

1 回答 1

0

我通过从实体引用中复制一些代码来修复它。我必须为这种关系使用不同的视图处理程序并向该关系添加其他属性

function clinical_trial_views_data_alter(&$data) {

  $data['clinical_trial_research']['clinical_trial_research_sites'] = array(
    'title' => t('Clinical Trial Research Sites'),
    'help' => t('Field Reference Appear in Clinical Trial Research Sites.'),
    'relationship' => array(
      'handler' => 'views_handler_relationship',
      'label' => t('Clinical Trial Research Sites'),
      'base' => 'clinical_trial_research_sites',
      'base field' => 'study_num',
      'relationship field' => 'study_num',
    ),
  );
  // The reference field in the node entity is not entity reference , its just a basic text field
  $data['clinical_trial_research_sites']['site_comp_code']['relationship'] = array(
    'handler' => 'views_handler_relationship_entity_reverse',
    'field_name' => 'field_site_comp_code',
    'field table' => 'field_data_field_site_comp_code',
    'field field' => "field_site_comp_code_value",
    'base' => 'node',
    'base field' => 'nid',
    'title' => t('Referencing entity'),
    'help' => t('Field Reference Appear in Location Content type.'),
    'title' => t('Location'),
  );
}
于 2014-11-21T17:15:42.913 回答