function cf_settings_register in Common Functionality 7.2
Add a variable name and type to the variables registry.
For variable types that can be added, this will add/initialize the variable in the database. This add operation will only happen if other modules have registered the variable.
Parameters
string $variable_name: A string representing the variable name.
string $variable_type: A string representing the variable type.
string $module_name: A string representing the module name.
$value: (optional) The value to set. This can be any PHP data type; these functions take care of serialization as necessary. If NULL is passed, then variable_set() is not called.
Return value
bool TRUE if registration was successfull, FALSE otherwise.
See also
Related topics
7 calls to cf_settings_register()
- cf_error_install in modules/
cf_error/ cf_error.install - Implementation of hook_install().
- cf_error_update_7200 in modules/
cf_error/ cf_error.install - Upgrade module from 7.x-1.x to 7.x-2.x.
- cf_menu_install in modules/
cf_menu/ cf_menu.install - Implementation of hook_install().
- cf_menu_update_7200 in modules/
cf_menu/ cf_menu.install - Upgrade module from 7.x-1.x to 7.x-2.x.
- cf_menu_update_7201 in modules/
cf_menu/ cf_menu.install - Register the new management_admin_page drupal variable.
3 string references to 'cf_settings_register'
- cf_settings_get_registered in modules/
cf_settings/ cf_settings.module - Obtains the registered variables based on the given conditions.
- cf_settings_modules_uninstalled in modules/
cf_settings/ cf_settings.module - Implements hook_modules_uninstalled().
- cf_settings_unregister in modules/
cf_settings/ cf_settings.module - Remove a registered variable from the variables registry.
File
- modules/
cf_settings/ cf_settings.module, line 199 - Common Functionality - PHP INI module.
Code
function cf_settings_register($variable_name, $variable_type, $module_name, $value = NULL) {
if (!is_string($variable_name) || empty($variable_name)) {
return FALSE;
}
if (!is_string($variable_type) || empty($variable_type)) {
return FALSE;
}
if (!is_string($module_name) || empty($module_name)) {
return FALSE;
}
$setting = cf_db_options_get_options('cf_settings', 'variable_type', $variable_type);
if (empty($setting)) {
return FALSE;
}
$existing = cf_settings_get_registered(array(
'variable_name' => $variable_name,
'variable_type' => $setting->id,
'module_name' => $module_name,
));
if (!empty($existing)) {
return FALSE;
}
if ($variable_type == 'drupal_variables' && $value !== NULL) {
if (!cf_settings_is_registered($variable_name, $variable_type)) {
variable_set($variable_name, $value);
}
}
$record = array();
$record['variable_name'] = $variable_name;
$record['variable_type'] = $setting->id;
$record['module_name'] = $module_name;
$query = db_insert('cf_settings_register');
$query
->fields($record);
$query
->execute();
watchdog('register', "The module %module_name has registered the %variable_type: %variable_name.", array(
'%variable_name' => $variable_name,
'%variable_type' => $variable_type,
'%module_name' => $module_name,
));
return TRUE;
}