function auto_nodetitle_set_title in Automatic Nodetitles 8
Same name and namespace in other branches
- 5 auto_nodetitle.module \auto_nodetitle_set_title()
- 6 auto_nodetitle.module \auto_nodetitle_set_title()
- 7 auto_nodetitle.module \auto_nodetitle_set_title()
Sets the automatically generated nodetitle for the node
3 calls to auto_nodetitle_set_title()
- auto_nodetitle_node_presave in ./
auto_nodetitle.module - Implements hook_ENTITY_TYPE_presave().
- auto_nodetitle_node_submit in ./
auto_nodetitle.module - Implements hook_node_submit().
- auto_nodetitle_operations_update in ./
auto_nodetitle.module - Callback function for updating node titles.
File
- ./
auto_nodetitle.module, line 80 - Allows hiding of the node title field and automatic title creation.
Code
function auto_nodetitle_set_title(&$node) {
$types = \Drupal\node\Entity\NodeType::loadMultiple();
$type = $node
->getType();
$title = $node
->getTitle();
$pattern = \Drupal::config('auto_nodetitle.node.' . $type)
->get('pattern') ?: '';
if (trim($pattern)) {
$node->changed = REQUEST_TIME;
$title = _auto_nodetitle_patternprocessor($pattern, $node);
}
elseif ($node->nid) {
$title = t('@type @node-id', array(
'@type' => $types[$type]->name,
'@node-id' => $node->nid,
));
}
else {
$title = t('@type', array(
'@type' => $types[$type]->name,
));
}
// Ensure the generated title isn't too long.
$node
->set('title', substr($title, 0, 255));
// With that flag we ensure we don't apply the title two times to the same
// node. See auto_nodetitle_is_needed().
$node->auto_nodetitle_applied = TRUE;
}