function i18n_sync_form_node_type_form_alter in Internationalization 7
Implements hook_form_FORM_ID_alter().
File
- i18n_sync/
i18n_sync.module, line 75 - Internationalization (i18n) package. Synchronization of translations
Code
function i18n_sync_form_node_type_form_alter(&$form, &$form_state) {
if (isset($form['type'])) {
$type = $form['#node_type']->type;
$disabled = !translation_supported_type($type);
$form['i18n_sync'] = array(
'#type' => 'fieldset',
'#title' => t('Synchronize translations'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#attributes' => array(
'class' => array(
'i18n-node-type-settings-form',
),
),
'#description' => t('Select which fields to synchronize for all translations of this content type.'),
'#disabled' => $disabled,
);
$form['i18n_sync']['i18n_sync_node_type'] = array(
'#tree' => TRUE,
'#weight' => 1,
);
// Each set provides title and options. We build a big checkboxes control for it to be
// saved as an array.
$current = i18n_sync_node_fields($type);
// Group options, group fields by type.
$groups = array(
'node' => t('Standard node fields'),
'fields' => t('Configurable fields'),
);
$fields = array();
foreach (i18n_sync_node_options($type) as $field => $info) {
$group = isset($info['group']) && isset($groups[$info['group']]) ? $info['group'] : 'node';
$fields[$group][$field] = $info;
}
foreach ($fields as $group => $group_fields) {
$form['i18n_sync']['i18n_sync_node_type']['i18n_sync_group_' . $group] = array(
'#prefix' => '<strong>',
'#suffix' => '</strong>',
'#markup' => $groups[$group],
);
foreach ($group_fields as $field => $info) {
$form['i18n_sync']['i18n_sync_node_type'][$field] = array(
'#title' => $info['title'],
'#type' => 'checkbox',
'#default_value' => in_array($field, $current),
'#disabled' => $disabled,
'#description' => isset($info['description']) ? $info['description'] : '',
);
}
}
// Add option to restrict syncing only when editing the translation source.
$form['i18n_sync']['i18n_sync_source_description'] = array(
'#prefix' => '<div>',
'#suffix' => '</div>',
'#markup' => t('Restrict synchronization to the translation source.'),
'#weight' => 2,
);
$form['i18n_sync']['i18n_sync_source'] = array(
'#type' => 'checkbox',
'#title' => t('Synchronize translations only when saving the translation source'),
'#default_value' => variable_get('i18n_sync_source_' . $type, FALSE),
'#disabled' => $disabled,
'#weight' => 3,
'#description' => t('If not checked each node will trigger the synchronization, whether it\'s the source or not.'),
);
}
}