Alright, I’ve hacked it up myself.
I changed the
In CMB2_Field.php, I changed the replace_hash function to be:
public function replace_hash($value)
{
if (!$this->options('group_title_callback')) {
// Replace hash with 1 based count
return str_ireplace('{#}', ($this->count() + 1) , $value);
}
else {
$fields = array();
foreach(array_values($this->args('fields')) as $field_args) {
$field = new CMB2_Field(array(
'field_args' => $field_args,
'group_field' => $this,
));
$fields[$field_args['id']] = $field->value;
}
return call_user_func($this->options('group_title_callback') , $fields);
}
}
Then in my metabox setup, I set:
'group_title' => 'New Widget',
'group_title_callback' => array($this, 'format_group_title'),
and finally my formatting callback that sets the title based off the field values:
public function format_group_title($fields) {
return $fields['time'] . ' ' . $fields['name'];
}
This results in new items having the title “New Widget”, and existing groups getting an informative title based off two fields.
It’s a bit of a hack, is there a way to do this without editing CMB2? I’d rather not break automatic updates and maintain my own fork.
Edit: improved slightly