One of our members wanted to automatically fill in Drupal fields from another node.
It took a little experimentation, but we managed to make it work using the Token, Token Filter and Entity Reference modules.
This technique works for nodes, but it should allow you to automatically popular field using data from users, comment or any other entity.
Before you begin, follow these steps to enable tokens in Drupal fields. You must allow tokens inside fields before this tutorial will work.
In this example, we have two content types: Presentations and Speakers.
Here's how it will work: when people add a Presentation, they choose a speaker and have the speaker details automatically fill into the Presentation field.
Here's our Speakers content type with the information fields:
- Here's how the speaker content type appears after publication:
Here's our Presentations content type. Note that we have an "Entity Reference" link to the speaker. This field is the key to the whole process.
- If you don't have Entity Reference, install it and make a field that links to the Speaker content type.
Now that we have out content types set up, let's use the Token module to link their data together.
- Go to Help > Token and you'll see a list of all the tokens available.
- Look down the list to find your Entity Reference field. Click "Nodes", then your field name.
Underneath your Entity Reference field, you'll see the tokens from your Speaker content type. These tokens contain the information that we want to pass on to Presentations.
- Go to Structure > Content type > Presentations.
- Put your tokens inside the "Default Value" for the field. Below we have the Speaker Bio field:
- Here we have the "How to Contact the Speaker" field:
- When you've saved the fields above, go to "Add content" and click "Presentation".
- The image below shows how the Presentation screen appears. The "Speaker Link" field is controlling where the information is being taken from.
- Save the Presentation.
- Your data will be automatically populated: