在视图中使用Drupal7自定义实体

时间:2013-01-04 13:33:30

标签: drupal-7 entity drupal-views

我在drupal 7中使用hook_entity_info创建了两个自定义实体。为给定的数据库表创建了实体。 我可以分别为每个实体创建一个视图。但是想要一起创建两个实体的视图。视图中的“关系”选项显示“没有关系可用”。并且添加字段选项仅显示已切割实体的字段。

如何关联两个实体?

1 个答案:

答案 0 :(得分:1)

我能够提供两种解决方案:

1)使用关系,关系结束字段,关系UI

2)使用来自商业模块的hook_views_data_alter示例:

         Function hook_views_data_alter(){ 
             // Expose the uid as a relationship to users.
             $data['users']['uc_orders'] = array(
                 'title' => t('Orders'),
                 'help' => t('Relate a user to the orders they have placed. This relationship will create one record for each order placed by the user.'),
                 'relationship' => array(
                     'base' => 'uc_orders',
                     'base field' => 'uid',
                     'relationship field' => 'uid',
                     'handler' => 'views_handler_relationship',
                     'label' => t('orders'),
                 ),
             );
         }
相关问题