Closed (fixed)
Project:
Entity Registration
Version:
3.0.0-beta1
Component:
Registration Views
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
10 Nov 2022 at 23:54 UTC
Updated:
4 Mar 2023 at 20:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
john.oltman commentedThe Host entity field in Views is a pseudo-field because the entity type of the target is unknown to the module, and thus cannot be used in a relationship. However, app builders know what the entity types are in their application, so you can extend your registration type with an "Event" entity reference field and use a presave hook in your custom code to set that extra field to the referencing Event when the registration is created. That field will then be available in views and you can use relationships to access fields on the Event and the Registration in the same listing. To add fields to your registration type, go to /admin/structure/registration-types/{machine_name_of_your_registration_type}/edit/fields. The code in the hook can use the host entity type ID and host entity ID on the registration to load the Event entity and update the registration entity with that reference. The hook_registration_presave() function in a .module would be a place you can do this.
Comment #3
john.oltman commentedComment #4
ericgsmith commentedYou can also define a relationship to the host entity without having to modify any existing data inside hook_views_data_alter.
For example, to relate a registration to a node you can use the following code:
There was a sub module in Drupal 7 that provided this and other functionality - @john.oltman would you be open to a patch that could determine what entity types have registrations and loop through them to add this information? Either as a sub module or as part of the existing views data alter.
Similar to https://git.drupalcode.org/project/registration/-/blob/7.x-2.x/modules/r...
Comment #5
john.oltman commentedYes @eric, I would take a look at a patch. My only concern is registration fields are attached to specific bundles and not an entire entity type (unless someone adds one as a base field, which would be rare probably). I'd be interested to see how a patch would handle that. Maybe it's not a problem though. If you post a patch I would definitely try it out.
Comment #6
ericgsmith commentedAttached is a patch to enable the relation for any enabled entity type.
To test (assuming a registration type is setup)
From the view user_registrations add a new relationship. Each entity type with a registration bundle should be available, e.g for nodes there will be "Host Entity: Content"
As long as you leave the relationship optional, it shouldn't care that the registrations can be associated to multiple entity types.
Comment #7
ericgsmith commentedComment #8
john.oltman commentedThanks @eric looks good, I will try this out locally within the next day or two and then most likely commit.
Comment #10
john.oltman commentedComment #11
john.oltman commentedCommitted and will be in next beta release. That should be within the next week.