Before custom text:
Say your client wants you to create a form to gather the favorite pets of their site's visitors. Easy enough:my_module.module
<?php
...
...
...
/**
* My form.
*/
function my_module_form($form, &$form_state) {
$form = array();
$form['favorite_pet'] = array(
'#type' => 'textfield',
'#title' => t('Favorite pet'),
'#description' => t('Please note that due to goverment regulations, we are required to report any person whose favorite pet is a Marsupial.'),
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
...
...
...
?>Which ends up looking like this:
But...
Client:
"... government requirements might change, and you have a spelling mistake there! I want to be independent, how do I change the description of the field without learning how to code?"
In comes Custom Text!
You implement Custom Text's hooks, and change the form's description to use Custom Text:my_module.module
<?php
...
...
...
/**
* Implements custom_text_group_info().
*/
function my_module_custom_text_group_info() {
return array(
'my_module_forms' => array(
'#title' => t('My Module, Form texts'),
),
);
}
/**
* Implements custom_text_info().
*/
function my_module_custom_text_info() {
return array(
'my_module_forms' => array(
'my_module_forms_favorite_pet_description' => array(
'#type' => 'text_format',
'#title' => t('Favorite Pet description'),
'#description' => t('The description of the Favorite Pet section.'),
),
),
);
}
/**
* My form.
*/
function my_module_form($form, &$form_state) {
$form = array();
$form['favorite_pet'] = array(
'#type' => 'textfield',
'#title' => t('Favorite pet'),
'#description' => custom_text_get('my_module_forms_favorite_pet_description'), // <-- CHANGED HERE
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
...
...
...
?>Now, the client can go to Admin > Structure > Custom Text, and easily change the text in all of the site's supported languages:
And voila!