- πΊπΈUnited States lpeabody
I'm running into this, but not because I've removed a relationship, but rather the Bundle filter is trying to access relationship information before I've had a chance to tell it what relationship to use through the UI. This happens because the Bundle filter invokes
::getEntityType
in theinit
function, which fires as soon as you add the filter and before you're prompted with the configuration screen, which is where you would typically specify the relationship.Below is my
hook_views_data
implementation. I'm just exposing a simple table called user_entity_visits with uid, entity_id (currently assumed to be only nodes), entity_type (again, hardcoded to node right now), and timestamp columns.The table itself is not a base table for an entity type, it's just a tracking table which denotes the latest point in time a user has visited a node page.
function harborlife_user_tracking_views_data() { $data = []; $data['user_entity_visits'] = []; $data['user_entity_visits']['table'] = [ 'group' => t('User Tracking'), 'provider' => 'harborlife_user_tracking', ]; $data['user_entity_visits']['table']['join']['node_field_data'] = [ 'left_field' => 'nid', 'field' => 'entity_id', ]; $data['user_entity_visits']['table']['join']['users_field_data'] = [ 'left_field' => 'uid', 'field' => 'uid', ]; $data['user_entity_visits']['entity_id'] = [ 'title' => t('Node ID'), 'help' => t('Node ID visited by a user.'), 'relationship' => [ // Views name of the table to join to for the relationship. 'base' => 'node_field_data', // Database field name in the other table to join on. 'base field' => 'nid', // ID of relationship handler plugin to use. 'id' => 'standard', // Default label for relationship in the UI. 'label' => t('Visited node'), ], ]; $data['user_entity_visits']['uid'] = [ 'title' => t('User ID'), 'help' => t('User that visited a node.'), 'relationship' => [ // Views name of the table to join to for the relationship. 'base' => 'users_field_data', // Database field name in the other table to join on. 'base field' => 'uid', // ID of relationship handler plugin to use. 'id' => 'standard', // Default label for relationship in the UI. 'label' => t('User who visited node'), ], ]; $data['user_entity_visits']['timestamp'] = [ 'title' => t('Timestamp'), 'help' => t('Timestamp of when a user visited a node.'), 'field' => [ 'id' => 'date', 'granularity' => 'second', ], 'sort' => [ // ID of sort handler plugin to use. 'id' => 'date', ], ]; return $data; }
- Status changed to Active
over 1 year ago 9:34pm 16 March 2023 - πΊπΈUnited States smustgrave
Got bit by this today. Similar to what others have said seems to only be with the Content Type field and when adding a filter. I can add the content type field no issue.
- πΊπΈUnited States smustgrave
For me I'm using event_log_track which has a views_data hook.
Very possible I got that setup wrong
https://git.drupalcode.org/project/events_log_track/-/blob/4.0.x/modules...
https://git.drupalcode.org/project/events_log_track/-/blob/4.0.x/event_l...But whenever I add the relationship to NodeID and try and use the Content type filter it fails and I have to do some hacky workaround of deleting the view and config importing again to recover.