function termcase_form_alter in Termcase 6
Implementation of hook_form_alter().
File
- ./
termcase.module, line 21 - The Termcase module gives you the option to specify specific case-formatting on terms.
Code
function termcase_form_alter(&$form, $form_state, $form_id) {
$node_form = '';
if (isset($form['type']['#value'])) {
$node_form = $form['type']['#value'] . '_node_form';
}
switch ($form_id) {
case 'taxonomy_form_term':
$edit_link = t('You can change this setting on the <a href="@vocabulary_edit_link">vocabulary settings page</a>.', array(
'@vocabulary_edit_link' => url('admin/content/taxonomy/edit/vocabulary/' . $form['#vocabulary']['vid']),
));
switch ($form['#vocabulary']['termcase']) {
case TERMCASE_UCFIRST:
$form['identification']['#description'] = t('Please note: the first letter of this term will be converted to <em>Uppercase</em>.') . ' ' . $edit_link;
break;
case TERMCASE_LOWERCASE:
$form['identification']['#description'] = t('Please note: the term will be converted to <em>lowercase</em>.') . ' ' . $edit_link;
break;
case TERMCASE_UPPERCASE:
$form['identification']['#description'] = t('Please note: the term will be converted to <em>UPPERCASE</em>.') . ' ' . $edit_link;
break;
case TERMCASE_PROPERCASE:
$form['identification']['#description'] = t('Please note: the term will be converted to <em>Propercase</em>.') . ' ' . $edit_link;
break;
}
break;
case 'taxonomy_form_vocabulary':
$mode = empty($form['vid']['#value']) ? TERMCASE_NONE : _termcase_vocabulary_termcase($form['vid']['#value']);
$form['termcase'] = array(
'#title' => t('Term case settings'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#weight' => 2,
'termcase_options' => array(
'#title' => t('Convert terms to this case'),
'#type' => 'select',
'#options' => array(
TERMCASE_NONE => t('No conversion'),
TERMCASE_UCFIRST => t('Convert the first character to uppercase'),
TERMCASE_LOWERCASE => t('Convert all characters to lowercase'),
TERMCASE_UPPERCASE => t('Convert ALL CHARACTERS TO UPPERCASE'),
TERMCASE_PROPERCASE => t('Convert the first characters of all words to uppercase'),
),
'#default_value' => $mode,
'#description' => t('This applies to all terms that are added to this vocabulary.'),
),
);
$form['submit']['#weight'] = 4;
// These settings only apply on existing vocabularies
if (isset($form['vid'])) {
$form['delete']['#weight'] = 5;
$form['termcase']['termcase_options']['#description'] = t('Note: existing terms will not be changed.');
$form['termcase']['termcase_update_terms'] = array(
'#title' => t('Convert the existing terms in this vocabulary immediately'),
'#type' => 'checkbox',
);
$form['termcase']['termcase_affect_synonyms'] = array(
'#title' => t('Apply this formatting to synonyms too'),
'#type' => 'checkbox',
);
$form['termcase']['termcase_display_notice'] = array(
'#title' => t('Display a notice below the tagging field that the term will be converted'),
'#type' => 'checkbox',
);
if (_termcase_vocabulary_termcase_synonyms($form['vid']['#value'])) {
$form['termcase']['termcase_affect_synonyms']['#attributes'] = array(
'checked' => 'checked',
);
}
if (_termcase_vocabulary_termcase_display_notice($form['vid']['#value'])) {
$form['termcase']['termcase_display_notice']['#attributes'] = array(
'checked' => 'checked',
);
}
}
break;
// Add a notice to the node/add form
case $node_form:
// Only usable for free-tagging
if (is_array($form['taxonomy']['tags'])) {
foreach ($form['taxonomy']['tags'] as $vid => &$vocab) {
if (_termcase_vocabulary_termcase_display_notice($vid)) {
switch (_termcase_vocabulary_termcase($vid)) {
case TERMCASE_UCFIRST:
$vocab['#description'] .= ' ' . t('Note: the first letter of the term(s) will be converted to <em>Uppercase</em>.');
break;
case TERMCASE_LOWERCASE:
$vocab['#description'] .= ' ' . t('Note: the term(s) will be converted to <em>lowercase</em>.');
break;
case TERMCASE_UPPERCASE:
$vocab['#description'] .= ' ' . t('Note: the term(s) will be converted to <em>UPPERCASE</em>.');
break;
case TERMCASE_PROPERCASE:
$vocab['#description'] .= ' ' . t('Note: the term(s) will be converted to <em>Propercase</em>.');
break;
}
}
}
}
break;
}
}