Advanced Automatic Nodetitles configuration with Entity Tokens

To customize how date fields are displayed as part of automatic title generation, install the Entity API module and enable both Entity API and Entity Tokens. When you return to the automatic title generation screen, you’ll notice a number of new options:

Entity token browser

Every token option with an underscore (e.g. node:field_attributed_to) now has a variant with a hyphen (node:field-attributed-to), provided by the Entity Tokens module. Furthermore, you can now toggle down the token for the Date field to select your display format, and you can choose one that does not display hours/minutes/seconds, or define one using the “Custom format” option.

Once you have Entity Tokens installed, you can also access fields that are part of a content type referenced using a node reference field. For instance, if you wanted your generated titles to look like “Emily Dickinson (1830-1886) about Louisa May Alcott (1832-1888)”, you would need to access the birth and death dates for each person-- even though that data is not stored as part of the Quote content type. But because the Quote content type has a node reference field pointing to the Person content type where that data can be found, you can get to that data using the entity tokens available if you toggle down the node reference fields for “Attributed to” and “Source”. To get titles as described above, your pattern for the title would look like:

[node:field_attributed_to] ([node:field-attributed-to:field-birth:custom:Y]-[node:field-attributed-to:field-death:custom:Y]) about [node:field_subject] ([node:field-subject:field-birth:custom:Y]-[node:field-subject:field-death:custom:Y])

This uses a custom format for the date, assuming you don’t already have a date format set up that only shows the year. The “Y” in the custom format comes from the PHP conventions for representing dates; you can access the relevant page in the PHP documentation via a link under the entity token for a date in a custom format.

Currently, a bug in the Entity Tokens module (version 7.x-1.5) leads to problems when a field you’ve included in an automatically generated node title is left empty. Rather than showing nothing, the literal text of the token will appear as part of the automatically generated title (e.g. George [node:field-middle-name] Washington). For date fields that are left empty, Entity Tokens fills in the current date. As a result, it’s best to only use the entity token variant (with the hyphen; [node:field-middle-name]) for required fields, and stick with the token variant (with the underscore; [node:field_middle_name]) if you want to include optional fields.

Another bug with the Entity Tokens module that may lead you to adopt the regular token variant relates to some punctuation marks (including ampersands, quotation marks, greater-than and less-than signs, and many letters with diacritics). The token variant displays these without a problem, but the entity token variant transforms them into their equivalent HTML entities (so “John & Jane” displays as "John & Jane&quot if generated by an entity token). If you expect your token values to include some of these punctuation marks, you should use the token variant.