Search code examples
drupal-7entitydrupal-views

Using Drupal7 custom entities in views


I have created two custom entities using hook_entity_info in drupal 7.The entities is created for the given database tables. I am able to create a view for each of the entities separately.But want to create a view of both entities together.The "relationship" option in view displays "no relationship available". And add fields option displays only the field of the secleted entity.

How do I relate both entities?


Solution

  • I was able to come with two solutions:

    1)using relation ,relation end field,relation UI

    2)using hook_views_data_alter example from commerce module:

             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'),
                     ),
                 );
             }