summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Reyero2009-07-05 14:43:41 (GMT)
committer Jose Reyero2009-07-05 14:43:41 (GMT)
commit3314df445d09f1ac0a62eb1bf712708770f814f0 (patch)
tree4cc1fe1b032c327f76d5e584f5b0e54f2edf2ab0
parent6f3bc6ca4dc2308a5d8228a738ff93144975ad66 (diff)
- Reworked content type settings, now in own fieldset
- Added node language options: - Default to current language - No language neutral - Lock language once created
-rw-r--r--i18n.module79
-rw-r--r--i18nsync/i18nsync.module10
2 files changed, 76 insertions, 13 deletions
diff --git a/i18n.module b/i18n.module
index 02be657..028d249 100644
--- a/i18n.module
+++ b/i18n.module
@@ -18,6 +18,7 @@ define('LANGUAGE_SUPPORT_NONE', 0);
define('LANGUAGE_SUPPORT_NORMAL', 1);
define('LANGUAGE_SUPPORT_EXTENDED', 2);
define('LANGUAGE_SUPPORT_EXTENDED_NOT_DISPLAYED', 3);
+
/**
* Implementation of hook_init().
*
@@ -119,6 +120,17 @@ function i18n_menu_alter(&$items) {
/**
* Implementation of hook_nodeapi().
*/
+function i18n_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+ global $language;
+
+ if (variable_get('language_content_type_' . $node->type, 0)) {
+ // Set current language for new nodes if option enabled
+ if ($op == 'prepare' && empty($node->nid) && empty($node->language) && variable_get('i18n_newnode_current_' . $node->type, 0)) {
+ $node->language = $language->language;
+ }
+ }
+}
+
/*
function i18n_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
if (variable_get("i18n_node_$node->type", 0)) {
@@ -347,6 +359,7 @@ function i18n_node_get_lang($nid, $default = '') {
function i18n_node_language_list($node, $translate = FALSE) {
// Check if the node module manages its own language list.
$languages = node_invoke($node, 'language_list', $translate);
+
if (!$languages) {
if (variable_get('i18n_node_'. $node->type, 0) >= LANGUAGE_SUPPORT_EXTENDED) {
$languages = locale_language_list('name', TRUE); // All defined languages
@@ -360,7 +373,14 @@ function i18n_node_language_list($node, $translate = FALSE) {
unset($languages[$langcode]);
}
}
- $languages = array('' => t('Language neutral')) + $languages;
+ // Language may be locked for this node type, restrict options to current one
+ if (variable_get('i18n_lock_node_' . $node->type, 0) && !empty($node->language) && !empty($languages[$node->language])) {
+ $languages = array($node->language => $languages[$node->language]);
+ }
+ // Check language required for this type (no language neutral)
+ elseif (!variable_get('i18n_required_node_' . $node->type, 0)) {
+ $languages = array('' => t('Language neutral')) + $languages;
+ }
}
return $languages;
@@ -536,15 +556,55 @@ function i18n_exit() {
* This is the place to add language fields to all forms.
*/
function i18n_form_alter(&$form, $form_state, $form_id) {
+ global $language;
+
switch ($form_id) {
case 'node_type_form':
+ $disabled = !variable_get('language_content_type_'. $form['#node_type']->type, 0);
+ $form['i18n'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Multilanguage options'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#description' => t('Extended multilingual options provided by Internationalization module.'),
+ '#disabled' => $disabled,
+ );
+ // Add disabled message
+ if ($disabled) {
+ $form['i18n']['#description'] .= ' <em>' . t('These will be available only when you enable Multilingual support in Workflow settings above.') . '</em>';
+ }
+ // Some settings about node languages
+ $form['i18n']['options'] = array(
+ '#title' => t('Options for node language'),
+ '#type' => 'fieldset',
+ '#disabled' => $disabled,
+ );
+ $form['i18n']['options']['i18n_newnode_current'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Set current language as default for new content.'),
+ '#default_value' => variable_get('i18n_newnode_current_' . $form['#node_type']->type, 0),
+ '#disabled' => $disabled,
+ );
+ $form['i18n']['options']['i18n_required_node'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Require language (Do not allow Language Neutral).'),
+ '#default_value' => variable_get('i18n_required_node_' . $form['#node_type']->type, 0),
+ '#disabled' => $disabled,
+ );
+ $form['i18n']['options']['i18n_lock_node'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Lock language (Cannot be changed).'),
+ '#default_value' => variable_get('i18n_lock_node_' . $form['#node_type']->type, 0),
+ '#disabled' => $disabled,
+ );
// Add extended language support option to content type form.
- $form['workflow']['i18n_node'] = array(
+ $form['i18n']['i18n_node'] = array(
'#type' => 'radios',
'#title' => t('Extended language support'),
'#default_value' => variable_get('i18n_node_'. $form['#node_type']->type, LANGUAGE_SUPPORT_NORMAL),
'#options' => _i18n_content_language_options(),
- '#description' => t('If enabled, all defined languages will be allowed for this content type in addition to only enabled ones. This is useful to have more languages for content than for the interface.')
+ '#description' => t('If enabled, all defined languages will be allowed for this content type in addition to only enabled ones. This is useful to have more languages for content than for the interface.'),
+ '#disabled' => $disabled,
);
break;
@@ -552,13 +612,14 @@ function i18n_form_alter(&$form, $form_state, $form_id) {
// Extensions for node edit forms
if (isset($form['#id']) && $form['#id'] == 'node-form') {
if (isset($form['#node']->type)) {
- // Set language to empty for not multilingual nodes when creating
- if (!isset($form['#node']->nid) && !variable_get('language_content_type_'. $form['#node']->type, 0)) {
- $form['language'] = array('#type' => 'value', '#value' => '');
+ if (variable_get('language_content_type_'. $form['#node']->type, 0)) {
+ if (!empty($form['language']['#options'])) {
+ $form['language']['#options'] = i18n_node_language_list($form['#node'], TRUE);
+ }
}
- // Extended language, add all languages to the list
- if (!empty($form['language']['#options']) && variable_get('language_content_type_'. $form['#node']->type, 0)) {
- $form['language']['#options'] = i18n_node_language_list($form['#node'], TRUE);
+ elseif (!isset($form['#node']->nid)) {
+ // Set language to empty for not multilingual nodes when creating
+ $form['language'] = array('#type' => 'value', '#value' => '');
}
}
}
diff --git a/i18nsync/i18nsync.module b/i18nsync/i18nsync.module
index bccf127..ad75bc0 100644
--- a/i18nsync/i18nsync.module
+++ b/i18nsync/i18nsync.module
@@ -59,14 +59,15 @@ function i18nsync_form_alter(&$form, $form_state, $form_id) {
case 'node_type_form':
$type = $form['#node_type']->type;
$current = i18nsync_node_fields($type);
-
- $form['workflow']['i18n']['i18nsync_nodeapi'] = array(
+ $disabled = $form['i18n']['#disabled'];
+ $form['i18n']['i18nsync_nodeapi'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('Synchronize translations'),
'#collapsible' => TRUE,
'#collapsed' => !count($current),
- '#description' => t('Select which fields to synchronize for all translations of this content type.')
+ '#description' => t('Select which fields to synchronize for all translations of this content type.'),
+ '#disabled' => $disabled,
);
// Each set provides title and options. We build a big checkboxes control for it to be
// saved as an array. Special themeing for group titles.
@@ -74,12 +75,13 @@ function i18nsync_form_alter(&$form, $form_state, $form_id) {
$title = $data['#title'];
if (!empty($data['#options'])) {
foreach ($data['#options'] as $field => $name) {
- $form['workflow']['i18n']['i18nsync_nodeapi'][$field] = array(
+ $form['i18n']['i18nsync_nodeapi'][$field] = array(
'#group_title' => $title,
'#title' => $name,
'#type' => 'checkbox',
'#default_value' => in_array($field, $current),
'#theme' => 'i18nsync_workflow_checkbox',
+ '#disabled' => $disabled,
);
$title = '';
}