Welcome to another Daily Dose of Drupal, today we’re on Episode Number 29 and if you look back on Episode 27 we discussed the Automatic Node Titles module. Today we’re going to look at the Automatic Entity Labels Module, thanks to a comment on the Code Karate site, I was not aware of this module however after I have looked it over and used it a few times, it seems like a really good replacement for the Automatic Node Titles Module, however instead of just working on Nodes, this module works on all different types of entities.
So I’m just going to take a few minutes to go over to this module which is very similar to the Automatic Node Titles Module, a few extra things it can do and we’ll go ahead and get started. As always I’m Shane, you can contact me on Twitter @smthomas3 or go to codekarate.com and sign up for the newsletter.
So the first step is going to be to download this module; I have the Token Module downloaded and installed which I would recommend if you want to make it a little easier to add patterns and increase number of patterns you can use when automatically generating the title field.
So I’m also going to enable this module so I just did a Drush download and a Drush enable and it is enabled. So we will come back to our test site here and it’s just a simple Drupal 7 test site; the first thing I’m going to do is build a simple content type and I’ll call this Hide Title, similar to what I did to Automatic Mode Titles Module so you can see the differences, we’ll leave all this stuff the same and then I’m also going to add a field here, I’ll just call this Test Field 1 Work and we can just leave it a text field. So now if I come back to the Content Type’s page and I come into click Edit on my Hide Title Content Type you’ll see there’s now two options; one for Node Auto Label and one for Comment Auto Label and this also works with I think Profile … I think it says Profile 2 or Text on the midterms, Profile 2 Labels, Comments and Node Titles.
So you can see that it does a lot more than just the Automatic Node Titles Module. But what we’ll do is we’ll click on Node Auto Label, we’ll also open up this Add Content here and add a Hide Title, you can see that there’s a Title Field, a Body Field and a Test Field 1.
What we want to do is we want to automatically generate the Label and hide the Label Field, we’re also going to come in here in our little token browser under Nodes, we’re going to scroll down until we find our Test Field 1, we’re going to go ahead and grab that and we’re going to paste that in here and we’ll just leave it at that so whatever I put in to Test Field1 will be the Title, we can also go ahead and add the current date or any of these different tokens that you can see in here.
So we’ll add the current date in a long format, so if we save this … you can see this is almost identical to the Automatic Node Titles Module so nothing really new here, if I refresh the age the title field is gone, you can add some text to the test field and save it and you’ll notice that the title is Test Node- the current date. Pretty simple; if you look down we’ll also going to go over just so how you can hide the subject field on comments.
So you can see there’s a Subject field and a Comment field; let’s just go ahead and look at how you can hide the Comment Label; let’s say we want to automatically hide this and just have it default to comment by the current user name, so just copy that from the token browser blow and paste it in the text area here, click save, now if we refresh this page you’ll notice there’s no subject field, you can save this and the title ends up being Comment by Beginner which is the user name of this user.
So incredibly easy, works just like the Automatic Node Titles Module but after using it I’m probably going to be moving all new development that I do that needs this functionality to this module just because it works with all entities, just makes sense. So if you have any questions about this go ahead and contact me on Twitter or codekarate.com and I will see you next time for another episode of the Daily Dose of Drupal, thanks for watching.