diff --git a/auto_nodetitle.module b/auto_nodetitle.module index c35a271..c4d693f 100644 --- a/auto_nodetitle.module +++ b/auto_nodetitle.module @@ -8,6 +8,7 @@ define('AUTO_NODETITLE_DISABLED', 0); define('AUTO_NODETITLE_ENABLED', 1); define('AUTO_NODETITLE_OPTIONAL', 2); +define('AUTO_NODETITLE_OPTIONAL_FILLED', AUTO_NODETITLE_OPTIONAL << 1); /** * Implementation of hook_perm() @@ -33,10 +34,18 @@ function auto_nodetitle_form_alter(&$form, $form_state, $form_id) { $form['title']['#required'] = FALSE; $form['#submit'][] = 'auto_nodetitle_node_form_submit'; } - else if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_OPTIONAL) { + else if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_OPTIONAL | AUTO_NODETITLE_OPTIONAL_FILLED) { // we will make the title optional $form['title']['#required'] = FALSE; $form['#submit'][] = 'auto_nodetitle_node_form_submit'; + + // prefill the field ? + if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_OPTIONAL_FILLED) { + $pattern = variable_get('ant_pattern_'. $form['#node']->type, ''); + if (trim($pattern)) { + $form['title']['#default_value'] = _auto_nodetitle_patternprocessor($pattern, $form['#node']); + } + } } } } @@ -159,9 +168,10 @@ function auto_nodetitle_node_settings_form(&$form) { '#type' => 'radios', '#default_value' => $default_value, '#options' => array( - t('Disabled'), - t('Automatically generate the title and hide the title field'), - t('Automatically generate the title if the title field is left empty'), + AUTO_NODETITLE_DISABLED => t('Disabled'), + AUTO_NODETITLE_ENABLED => t('Automatically generate the title and hide the title field'), + AUTO_NODETITLE_OPTIONAL => t('Automatically generate the title if the title field is left empty'), + AUTO_NODETITLE_OPTIONAL_FILLED => t('Automatically prepopulate the title field'), ) );