locale.variable.inc 3.1 KB

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