When creating entities in Drupal, such as nodes, users, or taxonomy terms, one of the required fields is the label or title of the entity.
However, sometimes you might want to hide the title field in Drupal or don't want to manually enter a title for every entity you create. That's where the "Automatic Entity Label" module comes in handy.
This module automatically generates a title for your entity based on configurable patterns, saving you time and effort.
Install the Automatic Entity Label module
To install the "Automatic Entity Label" module, follow these steps:
-
Use composer to download the module with the below command
composer require 'drupal/auto_entitylabel:3.0'
-
Enable the module in the Drupal administration interface under the "Extend” menu or use the drush command to enable the module
drush en auto_entitylabel
Note: It is highly recommended to also install and enable the Token module to get full advantage of the “Automatic Entity Label” module by using entity tokens to generate titles.
How to configure the Automatic Entity Label module
Once the module is installed and enabled, you can configure it to generate labels for the entity type.
Here is an example of how to configure the module to generate article node titles automatically.
STEP 1: Automatic label config page for the Article content type
Edit the article content type and then click on the “Automatic label” tab to navigate to the configuration for this content type.
STEP 2: Choose how to generate the title
Now choose how the title will be generated. You will have 4 options.
- Disable
- Automatically generate the label and hide the label field
- Automatically generate the label if the label field is left empty
- Automatically prefill the label
We will choose to hide the node title field and generate it automatically. But you can choose any of the other options based on the use case.
STEP 3: Set the pattern to generate the title
Once one of the above options is selected, more fields will appear. Here set the pattern for the generated labels. The pattern can include tokens, which are replaced with values from the entity when it is created.
For example, the pattern "blog-[node:nid]" generates node titles like "blog-123" for the nodes.
STEP 4: More configuration
Once the pattern is set, then you can select to remove special characters from the auto-generated title. Already created titles can be preserved and will not be affected by any pattern updates.
The next two options “Re-save” and “Chunk size” help you automatically generate titles for existing content through the batch operation.
Once all configuration is set to generate the title automatically, hit the Save configuration button.
STEP 5: Testing
Now, when you create a new node for the article content type, the title will be automatically generated based on the configured pattern. For our case, the title field will be hidden on add content form.
Once the node is saved, check the node view and confirm the automatically generated title.
Conclusion
In conclusion, the "Automatic Entity Label" module is a useful tool for saving time and effort when creating entities in Drupal. By automating the title generation process, you can ensure consistency and uniqueness in your entity titles or totally get rid of the required title field.