Please add to documentation as an example.
I wanted the title to be field_company and then field_person_name, separated by "/".
The 1st field is mandatory, the 2nd is sometimes empty.
That's the PHP code I've come up with, to put in the content type's auto-nodetitle definitions tab (when the PHP checkbox is checked).
$language = $node->language;
if (!in_array($language, $node->field_company)) $language = LANGUAGE_NONE;
$title = $node->field_company[$language][0]['value'];
$pname = '';
if (count ($node->field_person_name[$language]) ) :
$pname = $node->field_person_name[$language][0]['value'];
endif;
if (strlen($pname) > 0):
return $title . ' / ' . $pname;
else:
return $title;
endif;
Comments
Comment #1
Utkarsh_Mishra commentedI reviewed this code and it's the simple example, working fine for me.
Comment #2
Utkarsh_Mishra commentedComment #3
gaurav.kapoor commentedIt is very clear that $node variable is available in custom PHP to add code for automatic node title. This example is great as a help but not generic enough to be pushed into the documentation. I'll prepare another and add it to documentation.