Automatically Generating Node Titles in Drupal
It’s fairly common to replace the title field in Drupal.
There are many possible reasons to replace the title, but most of them come down to this … the title field is not very flexible.
To take just one example, imagine that you’re adding a directory of your staff members to your site. Presumably, you’d like the person’s name to be the title of each page. However, because the title field only consists of a text field with 255 characters, you can’t have close control over what people enter. The solution is to replace the default title with specific “First Name” and “Last Name” fields.
So, here’s how to automatically generate titles in Drupal 7.
Step 1: Install
Install these two modules:
Step 2: Set Up Each Content Type
- Go to Structure > Content types
- Look for the automatic title generation area as in the image below
- You’ll be able to use tokens to automatically replace the title
- In the example below, we’re completely hiding the title field. If we choose the bottom radio button, the title field would be available to users and our tokens would only work if the title field isn’t used.
- In the image below, we’re automatically replacing the title with the First name and Last name fields.
Step 3: Create the Content
- Click Add content and create an example of your content type
- Notice that the title field is completely missing
- Save the content and your title will be automatically generated:
Auto Entity Label is the newer version of auto node title, so that is the prefered module to use:
[url=http://drupal.org/project/auto_entitylabel]http://drupal.org/project/a…[/url]
That works great. I was able to create a new rule through the interface and it worked when I tested it. I just put dummy data in the title field so I could submit since it was a required field. Once the product was saved, my dummy data had been overwritten with the SKU on mys site: [url=http://www.kamagra.com.mx]http://www.kamagra.com.mx[/url] . I will deal with the hook_form_alter and the concatenation of the SKU and the other field tomorrow. The other filed is a taxonomy term. This is all so new to me, but I am beginning to recognize how powerful it is. Thank you so much for your help.
Thanks for the tutorial however I used the random number “[random:number]” token and whenever I edit the node the title regenerates again how would i fix this as i want the title to remain the same no matter what changes of updates I perform on the node?