function hook_variable_type_info in Variable 6
Same name and namespace in other branches
- 7.2 variable.api.php \hook_variable_type_info()
- 7 variable.api.php \hook_variable_type_info()
Define types of variables or list of values used by a module.
These subtypes can be used to provide defaults for all properties of variables of this type or to provide a list of options either for variable options (selectable values) or for children variables in the case of multiple variables.
Example, three usages of variable type:
// Use variable type 'weekday' to provide a selector for a day of the week
$variables['date_first_day'] = array(
'type' => 'weekday',
'title' => t('First day of week'),
'default' => 0,
);
// Use 'options' with value 'weekday' for any other variable that needs to provide a selectable
// list of days of the week. In this example you can select one or more days.
$variables['working_days'] = array(
'type' => 'options',
'options' => 'weekday',
'title' => t('Select working days from the list.'),
);
// Use 'multiple' with value 'weekday' to create a subset of variables, one for each day of the week.
// In fact, using '[weekday]' in the variable name will set these properties ('type' and 'multiple') automatically.
$variables['daily_greeting_[weekday]'] = array(
'type' => 'multiple',
'multiple' => 'weekday',
'repeat' => array(
'type' => 'string',
),
'title' => t('Greeting to display each day of the week'),
);
Return value
An array of information defining variable types. The array contains a sub-array for each variable type, with the variable type as the key.
The possible attributes are the same as for hook_variable_info(), with the type attributes being added on top of the variable attributes.
A special attribute:
- "type": Variable subtype, the properties for the subtype will be added to these ones.
1 function implements hook_variable_type_info()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- variable_variable_type_info in ./
variable.variable.inc - Implements hook_variable_type_info().
File
- ./
variable.api.php, line 148 - Hooks provided by the Variable module.
Code
function hook_variable_type_info() {
$type['mail_address'] = array(
'title' => t('E-mail address'),
'element' => array(
'#type' => 'textfield',
),
'token' => TRUE,
);
$type['mail_text'] = array(
'title' => t('Mail text'),
'multiple' => array(
'subject' => t('Subject'),
'body' => t('Body'),
),
'build callback' => 'variable_build_mail_text',
'localize' => TRUE,
'type' => 'multiple',
);
return $type;
}