function termcase_form_taxonomy_vocabulary_form_alter in Termcase 8
Implements hook_form_FORM_ID_alter().
Adds the termcase selection dropdown to the vocabulary form.
File
- ./
termcase.module, line 57 - The Termcase module gives you the option to specify specific case-formatting on terms.
Code
function termcase_form_taxonomy_vocabulary_form_alter(&$form, FormStateInterface $form_state) {
$config = \Drupal::config('termcase.settings');
$vocab_machine_name = $form['vid']['#default_value'];
$form['termcase']['termcase_settings'] = [
'#title' => t('Term case settings'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#weight' => 2,
'termcase_options' => [
'#title' => t('Convert terms to this case'),
'#type' => 'select',
'#options' => [
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 character of each word to uppercase'),
],
'#default_value' => $config
->get('termcase_options_' . $vocab_machine_name),
'#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_settings']['termcase_options']['#description'] = t('Note: existing terms will not be changed.');
$form['termcase']['termcase_settings']['termcase_update_terms'] = [
'#title' => t('Convert the existing terms in this vocabulary immediately'),
'#type' => 'checkbox',
'#default_value' => $config
->get('termcase_update_terms_' . $vocab_machine_name),
];
}
// Defining custom submit handler.
$form['actions']['submit']['#submit'][] = 'termcase_custom_form_submit';
}