1

I am new to Drupal and I need to create a relationship between user and content type.

There is a content type called 'Property'. The user who creates a property page ​must specify either:

  • I am an owner, OR
  • I am a tenant.

And I need to show this relationship on the property detail page.

How can I achieve this?

Note: I want to keep record of this, it mean the property detail page would always shows the previous tenant and owner information. And later that I want to show the reviews of user under owner and tenant tabs.

3 Answers 3

1

but I want to keep record of this, it mean the property detail page would always shows the previous tenant and owner information. And later that I want to show the reviews of user under owner and tenant tabs.

  • The initial question sounds simple but the added comment turns it into a fairly complicated site build which I believe is outside the scope of StackExchange questions. I'm just going to give the OP a brief overview of what I would do. Mods, feel free to edit or whatever you need to do.

So along with normal fields like images, locations etc., you need a place to store all of the information relating to each owner or tenant in each property.. The screenshot below gives a basic example of this.

Basic Field Collection

Field Collection will let you store this information. You should have one field collection for owners and another for tenants. All reviews etc. of each person will have to be inside a field collection. Or reference a field collection using the module below.

Entity Reference will let you reference the people and vice versa. You'll use this a massive amount on a site like this for almost everything.

Entity Forms + Rules should allow tenants / owners to create property and also add themselves to a property by creating field collections from form data. You don't want to give them the ability to change other people's data so forms are essential.

Entity Reference Prepopulate will be essential for pre-filling form data and then disabling or hiding fields. This way, people can't view the workings of your site and more importantly, add and edit whatever they like. (for a regular end-user anyway).

Etc. Etc. Etc.

Anyways, that should be enough for you to look at for a couple of months. Good luck!

1

This really seems like a perfect usecase for the Flag module. Just create 2 (non global) flags to be used for flagging content of type "Property" (only) with labels something like this:

  • (flag 1): I am an owner
  • (flag 2): I am a tenant

When configuring these flag(s), you can also attach fields to each of them. You can use those fields to have a use enter a start date and possibly also an end date (since you seem to also "want to keep record (track?) of this". However to be able to attach fields (actually for users to enter date for those fields), make sure to also be aware about (and do) what is described in Attaching fields to flags, i.e.:

By default, Flags use the "JavaScript toggle" link-type. While this allows entities to be flagged without reloading the page, users cannot set any field values with the Flag. In order for users to set a Flag's field values, you must use the "Form" link type.

Navigate to Administration > Structure > Flags page. Click the Edit link for the Flag. Scroll down to the Display Options box and select the Confirmation Form radio button.

To "show this relationship on the property detail page" (as in your question also), just create an appropriate views (using the Views module) about users who flagged a node, format it as a block, and display the block on a property page.

But wait, there is more: the Flag module has great integrations with the Rules module. So pretty sure you'll find additional cases where you'll want to take advantage of these integrations also.

0

I'm not sure what is the ultimate goal but you could just create a new List field for the content type named "Author is" and set it's options to: Owner, Tenant.

Author/creator could then select suitable option and when Property page is viewed it shows the author's "status".

1
  • but I want to keep record of this, it mean the property detail page would always shows the previous tenant and owner information. And later that I want to show the reviews of user under owner and tenant tabs. Commented Jul 14, 2016 at 9:53

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.