1

I would like to allow user when creating new content (an event) to assign (from drop down) one of the locations defined in his profile (Profile2)... Is there a module which could help? If not any hint how to solve it in custom module?
Im thinking entity reference field could do if it was possible to create list of location for each user...
Maybe it is simple but beyond my drupal skills... ;)
Locations are nodes referenced with entity reference but not necessarily created by the same user

2
  • I suppose locations are stored as nodes? Do users create those locations by themselves? I'm thinking of some solutions but I need to be sure how your system works beforehand ;) Dec 27, 2014 at 23:26
  • use form_alter() to populate the dropdown
    – 2pha
    Dec 28, 2014 at 4:02

1 Answer 1

1

Install the references module, once you done that, you can enable the node_reference submodule and attach a "Node Reference" field to your "event" content type. Choose the "select list" widget and the user will be able to link any location to the event.

If you want to let the user choose only from locations he created, here's a way:

On the field configuration page, you can see a fieldset called "Views - Nodes that can be referenced". It says that options from the dropdown can be filtered based on a view using the "References" display type.

Just create a view listing location nodes and select the correct "display type" as shown below:

Create a view with References display type

And display nodes from the current logged-in user by adding a contextual filter "Content: Author uid"

Creation of contextual filter

Save all that and refresh the field configuration page. Select the view from the dropdown list that just appeared and you should be good to go ;).

4
  • im using entity reference on the site already... it makes little sense to install references too, dont you think? thanks for your help thou :)
    – oskar333
    Dec 29, 2014 at 6:35
  • Oh, I read the question thinking entity reference was only a suggestion, my bad. If you still need help, I'll take some time to update the answer ;) Dec 29, 2014 at 6:58
  • Entity reference can do it in a similar way. Not sure what the display type was called again, but you'll recognise it. Dec 29, 2014 at 23:37
  • Yep, I just saw that on a project I'm working for, it's pretty much the exact same thing. Dec 31, 2014 at 13:54

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.