1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Variable API module. Definition for Drupal core variables
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Implements hook_variable_info().
|
9
|
*/
|
10
|
function locale_variable_info($options) {
|
11
|
// This variable will be altered by translation module. See translation.variable.inc
|
12
|
$variables['language_content_type_[node_type]'] = array(
|
13
|
'type' => 'multiple',
|
14
|
'title' => t('Multilingual support'),
|
15
|
'repeat' => array(
|
16
|
'type' => 'enable',
|
17
|
// Set options here so translation module can add some more
|
18
|
'options' => array(t('Disabled'), t('Enabled')),
|
19
|
),
|
20
|
'description' => t('Enable multilingual support for this content type. If enabled, a language selection field will be added to the editing form, allowing you to select from one of the <a href="!languages">enabled languages</a>. If disabled, new posts are saved with the default language. Existing content will not be affected by changing this option.', array('!languages' => url('admin/config/regional/language', $options)), $options),
|
21
|
'group' => 'node_type_settings',
|
22
|
);
|
23
|
$variables['language_default'] = array(
|
24
|
'title' => t('Site default language'),
|
25
|
'type' => 'select',
|
26
|
'group' => 'regional_settings',
|
27
|
'options callback' => 'locale_variable_options_language',
|
28
|
'format callback' => 'locale_variable_language_default_format',
|
29
|
'element callback' => 'locale_variable_language_default_element',
|
30
|
'default callback' => 'locale_variable_language_default',
|
31
|
);
|
32
|
return $variables;
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* Implements hook_variable_type_info().
|
37
|
*/
|
38
|
function locale_variable_type_info() {
|
39
|
// Language code
|
40
|
$type['language'] = array(
|
41
|
'title' => t('Language'),
|
42
|
'options callback' => 'locale_variable_options_language',
|
43
|
'type' => 'select',
|
44
|
);
|
45
|
return $type;
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Callback for all languages
|
50
|
*/
|
51
|
function locale_variable_options_language($variable, $options) {
|
52
|
return locale_language_list('name', TRUE);
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* Form element for site default language
|
57
|
*/
|
58
|
function locale_variable_language_default_element($variable, $options) {
|
59
|
$element = variable_form_element_options($variable, $options);
|
60
|
// Default needs to be language code for the radios to work.
|
61
|
$element['#default_value'] = $element['#default_value']->language;
|
62
|
// Since 'value callback' is useless as it is run before validation, we use validate
|
63
|
// callback to transform language code into an object.
|
64
|
$element['#element_validate'][] = 'locale_variable_language_element_validate';
|
65
|
return $element;
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* Get language default.
|
70
|
*/
|
71
|
function locale_variable_language_default($variable, $options) {
|
72
|
return language_default();
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Format language object variable
|
77
|
*/
|
78
|
function locale_variable_language_default_format($variable, $options = array()) {
|
79
|
return !empty($variable['value']) ? check_plain($variable['value']->name) : t('None');
|
80
|
}
|
81
|
|
82
|
|
83
|
/**
|
84
|
* Replace language code by language object on submission.
|
85
|
*
|
86
|
* This runs alter default element validation so we know it is a valid checkbox option.
|
87
|
*/
|
88
|
function locale_variable_language_element_validate($element, &$form_state, $form) {
|
89
|
$languages = language_list();
|
90
|
$language = $languages[$element['#value']];
|
91
|
form_set_value($element, $language, $form_state);
|
92
|
}
|