Score:0

Best practice for user specific data related to specific nodes

in flag

I have a content type travel_locations wich contains multiple fields (such as title, body, geolocation, etcetera). Now I would like the user to reference nodes of this content type when for example he has visited this location, together with specific data about this visit (traveldate, rating, textfield for travelnotes etcetera). The specific travel data will probably be collected trough paragraphs module. But I’m unsure which approach is best. Do I: a) Add the paragraphs reference field to the content type travel_locations? But is seems that in this usecase other users can edit/tamper other users data because every other (privileged) user is able to add his own travel data to the same node (via the node edit form)?

b) Add the paragraphs reference field to the user account to make the relation between the user and the travel_locations for that specific user. If this is the best approach, what will happen when the user adds for example 200 different travel locations? Will they all be loaded on every page request when the user is logged in (and thus consuming unnecessary large resources)

Or is there a different and better approach? Any suggestions and help will be appreciated! Thanks. (Use Case for Drupal 9/10).

berliner avatar
bd flag
You create a new entity type/node type (depends on your needs) that relates users and locations. This also allows you to easily store additional data for that location visit (think travel time, pictures, recommendations, ...) without bloating your base entities.
in flag
Ok, so if I understand you correctly, you would create two different nodetypes (let’s say travel_location and travel_data) and they would contain for example: travel_location: (name_of_location, description_of_location, geolocation_data, …) travel_data: (reference_to_travel_location (a node reference), travel_time, rating, travel_notes, …) So in this use case the author of a node of the “travel_data” type would be the reference between himself and the traveldata/location. And also; paragraphs would simply not be used, right? Thank you very much!
Score:0
de flag

You are using content types, which will work and is fine, but this can be done with custom entity types as well. For the case of this explanation, I'll move forward with the assumption that the data types are all nodes (content types).

You can do the following:

  1. Create two content types:
    • Travel Location
    • Trip
  2. Create an entity reference field in the Trip content type, titled 'Travel Location(s)', referencing the Travel Location content type.
  3. Add fields to the Trip content type for the various trip fields; date, rating, notes
  4. Create an entity reference on the user to the Trip content type, allowing for unlimited values

This will set up the back-end information architecture for the system whereby a user can have multiple trips assigned to them, and each trip can have a travel location assigned to it.

As for how to structure the front-end with good UX for entering trips, that's more of an opinion-based question, better addressed on Drupal.org than Drupal Answers, as Drupal Answers does not allow for opinion-based questions.

in flag
Thank you for the clarification! One small follow-up question however. what is in this case the added value of step 4? Isn't the user's Trip already related to the Travel Location via the author field? Can't I, as of step 3, not simply setup a block view on the users profile which selects all the Trip-content types of wich that user is the author? Or am I missing something? What would an extra reference from the User account to unlimited Trip-content types do exacly?
Jaypan avatar
de flag
Yes, you can do it the way you said. Having an entity reference off the user for all their trips will make it easier to create Views though.
Score:-1
ng flag

What @berliner said:

You create a new entity type/node type (depends on your needs) that relates users and locations. This also allows you to easily store additional data for that location visit (think travel time, pictures, recommendations, ...) without bloating your base entities.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.