2

So, this is my first question on Stack Exchange! So, I'm currently working on a project in which users of my Drupal site are playing a game as art collectors, and have a collection of artworks, which they can trade and sell during the game. Since my users will need to be able to reassign ownership of works (which would be stored in a database, as each work has several fields attached to it (artist, date, value, material, size, etc.)

And while I want them to be able to change ownership, it'd be preferable if I could let them do this in some kind of GUI, where I could limit control of what fields they could edit. In an idyllic scenario, they would have a drop-down menu they could select from to choose the new owner of the work, but I'm not sure how realistic that is.

Any modules that could assist in this would be fantastic, or if you have a different approach (other than a database), I'm more than happy to hear. This Drupal site is currently running on Ubuntu 16.04 LTS with the latest Drupal 7.5 installed.

I hope I was concise enough in my first question, and that somebody can help!

1 Answer 1

1

In a nutshell, you could do this with a user reference field, but you would be exposing everyone in the system (assuming all of these people are Drupal users). Maybe that isn't a big deal, maybe it is. I would create a view reference for the user reference field to only show users who are of a given role only, which should limit results. Furthermore, they would have to know the Drupal username - but you can get around that by installing RealName which swaps usernames for a realname field.

A reason for tying nodes to user accounts would be built-in permissions. "Owner" as just a Drupal textfield wouldn't really cut it in terms of true ownership.

I have done this in the past, similar scenario, different circumstance, where the system would create listings for businesses in the local area, and the business owners would come, register, and 'claim ownership' of their listing node by contacting us (webform). After vetting, we would change the node author (owner) from the admin to their Drupal account. Since they could have multiple, their user account dashboard listed all nodes that belong to them, free to edit and update.

I would also advise using a revision workflow so admins can track the history of a node and revert mistakes (as they are bound to happen from time to time).

Note, I am assuming your game pieces are custom entities or content types. It will work in either case.

You would need to give users enough permission to 'edit own ____' entity, and be able to update the user reference field. On submit, you could fire a custom rule with Rules that looks at the user reference field value, and updates the entity owner to that value (uid). Alternatively, you could implement a custom submit handler via hook_form_alter on specific forms, and do the logic yourself. The referenced UID value gets set as the owner, and once that happens, that user will no longer have access to edit or anything.

See:

5
  • . So would I as admin have to reassign modes every time? Is there any form of automation for this process, because theoretically that means I, and any future admin of the project, will be responsible for reassigning ~75 different nodes, which seems like a doozy. I made a simplified version of this game before using WordPress, and I created the artworks as blog posts, and tagged them by owner, and created a page displaying all posts tagged with a specific tag. While crude it did work, but I figured this time around using a database would be more efficient. Commented Oct 5, 2016 at 14:37
  • No, you can add the user reference field, give users 'edit own' node permission, and let them edit that field. Once the value of the field is entered, or changed, you could implement a rule with Rules or a form alter submit handler to look at the value, and change the node owner to that. This would remove it from their control.
    – Kevin
    Commented Oct 5, 2016 at 14:38
  • And yes, they will be custom entities, my plan was to make a base table defining the 'artwork entity' and model each individual artwork off of that thereafer Commented Oct 5, 2016 at 14:39
  • And oh, okay, that makes more sense, for some reason I wasn't making that connection first time I read your initial reply. This definitely clears up my question, I appreciate the quick / detailed response! Commented Oct 5, 2016 at 14:40
  • You might want to abstract the process down to 'change owner' form, and only present that field... in which case you would be implementing your own form and form submit. Not a lot of code, but results in a better UX for your users.
    – Kevin
    Commented Oct 5, 2016 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.