0

I'm working on a site that has a Field created through the Field API on the user that defines what district the user is in. The field stores the ID of the district, which is a custom entity in the district table.

In the admin/people view, I need to display the district's name. I can do this if the user would have the district_id on its table. But I can't figure out how to get the district name (from the district table) in the view if the district_id is on a field associated with the user.

This is similar to Views joining/relating a custom table entity to users through a field? but I need to do the opposite. The field is on the user and I need to grab district table values.

5
  • in the view, when you edit the district field, do you should see a formatter pulldown with several options for how to render the field? what happens if you select "rendered entity"? Feb 28 '18 at 1:02
  • I see Services Raw, Default, Plain Text, and Trimmed under the formatter. The district field seems to be added directly on the user as a string field and not through the district entity. Is there some way to connect them?
    – Tom Mertz
    Feb 28 '18 at 1:14
  • services raw? which module is adding this field? Feb 28 '18 at 22:05
  • From what I can tell the field was added through the control panel on the user. Config -> People -> Account Settings -> Manage Fields. Possibly I need to define its relationship to the district table in hook_views_data[_alter]?
    – Tom Mertz
    Feb 28 '18 at 23:59
  • sounds like somehow whoever created the user field didn't associate that field with the district entity. the field should be an entity reference, not a text field. you can test it by adding a test field which is an entity reference to the district entity and confirm that works properly (on a sandbox site of course). if that is the case, you'd probably need to create some migration script to transform the text field values already in the database into an entity reference. Mar 1 '18 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.