0

I am working on a site that is a directory of all track and field clubs (trackandfieldclubs.com). A user can create an account and add their club if it is not listed. However, nearly all the clubs have been listed by me to give the site some value. After all, what good would the site be if no track and field club were listed? The problem is that I want a user who's club is already listed to become the author of their club's node. Right now I have implemented a rather archaic system to do this where a user first creates an account, then fills out a web form (http://trackandfieldclubs.com/form/request-edit-existing-club) telling me their club name and username. I then login as an admin and change the node's author. Is there a better way to do this? Can this process be automated? Thanks in advanced!

1 Answer 1

1

You can create a simple module, implementing hook_form_alter, add additional form submit action which checks the submitted values on your form, looks up if there is node matching them and finally loads and updates the node accordingly.

Alternatively, you can add the Existing Club Name field to registration, implement hook_user_insert, and do the same logic as described above. This would save you unnecessary web form and improve the user experience greatly.

EDIT: Now that I think of it, it might be possible to achieve this using Rules module (https://drupal.org/project/rules) without coding. You add the field to the registration, create a rule, on event when user is created. Then iterate over all nodes of the Club content type (this should be possible with rules) and do a string comparison on each, to find the corresponding club. If the string comparison matches, you can easily change the node author. Please note that this solution is rather slow (and definitely not "right"), users could experience slow registration times.

Alternatively, you could change the rule event from user registration to form submission (which you have already) and therefore this (possibly) slow processing would not affect all users.

Also, I havent tried it, it's just an idea, but you should definitely try it.

6
  • Thank you for your reply m1n0. Unfortunately my strength is not in module development, so this task will be over my head. Would I be able to use view bulk operations to do this? The only other thing I can think of is maybe create content type with an entity reference of all nodes of the affected content type. The user would select their club and add their username to two fields. I can then export this as a csv and update the existing nodes via feeds. Still a lot of work though. Commented Jan 4, 2014 at 16:34
  • I edited my answer and I proposed alternative solution, please check it out.
    – m1n0
    Commented Jan 4, 2014 at 22:24
  • Ok let me know how it goes, also, please consider voting and accepting my answer :)
    – m1n0
    Commented Jan 5, 2014 at 17:52
  • Ok, so I tried the following rule without luck. Any advice? EVENT: After saving a new user account CONDITION: User has role(s) Parameter: User: [site:current-user], Roles: standard member AND Content is of type Parameter: Content: [account:field-existing..., Content types: Club AND Data comparison Parameter: Data to compare: [site:current-user:field-existing-club-name], Data value: [account:field-existing-club-name] ACTION: Set a data value Parameter: Data: [account:field-existing-club-name:author], Value: [site:current-user] Commented Jan 9, 2014 at 2:50
  • 1
    You are missing the node iteration - which node is compared? You need to load all nodes of specified content type(s) and do the comparison (which you already have) inside this loop for each node. The rest should be ok as you have it. Video about loops - drupalize.me/videos/lists-and-loops
    – m1n0
    Commented Jan 9, 2014 at 7:23

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.