0

I have a site where members can sign up and post an article (standard content type) which I'll call STYLE A. I now need to allow the members to create a different article (another content type) which I'll call STYLE B.

One of the fields within STYLE B will be a drop down list of all the article STYLE A's that this specific user has created. The user can then select one of the STYLE A's from the list.

I've tried using the reference and the entity reference modules but I can't quite get it. I've been able to create the reference field so that there is a dropdown of all STYLE A articles but these are not limited to that specific user.

Could anybody help me out. I've tried reading articles on relationships in views etc but it's not quite making sense.

thanks

1

some time ago, I created something similar. A drop down box (client profile) for the current user only - i.e. when creating a content type, the user would be able to choose a client profile, but only from a list of client profiles THEY authored.

I accomplished this using the following:

  • using a custom Node Reference Module, I created a field on the content type that used the node reference as a drop down box

  • added the following to the .module file, around line 878:

    global $user;

    if($user->uid != '1') $query->condition('n.uid', $user->uid, '=');

This creates a condition on the sql query that if the user isn't 1 (admin) it references the user id of the node creator, relative to the current logged in user, while Admin can override

If you going to go with this approach, be sure to rename the files and module into a CUSTOM module (I renamed mine custom_node_reference for simplicity).

| improve this answer | |
1

Install the entity reference module.

Create a view of Content of type STYLE A. Do not create a page or a block, just the base view. Add a Entity Reference Display to the view (click on +Add next to Master at the top). Make sure that in fields Title is displayed. Click on format settings, and select Title as the search field. Make sure you have no pager and are displaying all content. Add a Contextual filter of Content: Author uid, and in the top section of its config page under WHEN THE FILTER VALUE IS NOT AVAILABLE, select provide default value -> User Id from logged in user. This will ensure that you filter your results by the author of content of STYLE A, which is the user looking at the page.

Add an entity reference field to STYLE B. The target type must be Node, and in entity selection, Mode, select Views:Filter by an entity reference view. Then Select your view that you created above. It has a view argument input box, you can ignore that as we provided a default argument in the view, but if you need something more advanced in the future, you can look at this which will allow context to be passed in as tokens.

When you now create content of STYLE B it will have a box in which you can type titles, and it will search for content of TYPE A containing the search letters in its title, and authored by the person who is creating the new content of STYLE B.

Avoid using a drop down list at all costs as this might lead to performance issues

| improve this answer | |
  • Many thanks for the help. That seems to do the trick. – James Jul 13 '14 at 17:52
0

Have you managed to create this reference field manually or by using the References module ? If you custom built it, you can easily check uid of the node with the current logged in user, before this node title can gets populated in your drop down in STYLE B.

| improve this answer | |
  • Thanks for the reply, no I used references. I don't know how to do it manually. – James Jul 10 '14 at 14:14

Your Answer

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

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