function i18nblocks_form_alter in Internationalization 5
Same name and namespace in other branches
- 5.3 i18nblocks/i18nblocks.module \i18nblocks_form_alter()
- 5.2 i18nblocks/i18nblocks.module \i18nblocks_form_alter()
- 6 i18nblocks/i18nblocks.module \i18nblocks_form_alter()
Implementation of block form_alter().
Remove block title for multilingual blocks.
File
- i18nblocks/
i18nblocks.module, line 67
Code
function i18nblocks_form_alter($form_id, &$form) {
if ($form_id == 'block_admin_configure' && isset($form['block_settings']['i18nblocks'])) {
unset($form['block_settings']['title']);
$form['block_settings']['title'] = array(
'#type' => 'value',
'#value' => '',
);
}
elseif (module_exists('nodeasblock') && $form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['workflow']['nodeasblockset']['i18n_nodeasblock'] = array(
'#type' => 'radios',
'#title' => t('Create translation blocks automatically'),
'#default_value' => variable_get('i18n_nodeasblock_' . $form['#node_type']->type, 0),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
'#description' => t('Automatic synchronization with blocks generated by nodeasblock module.'),
);
}
elseif (isset($form['type']) && ($node = $form['#node']) && $form['type']['#value'] . '_node_form' == $form_id && variable_get("i18n_nodeasblock_{$node->type}", 0) && isset($form['nodeasblockset'])) {
if ($i18nblock = _i18nblocks_nodeasblock($node)) {
$block = i18nblocks_get_metablock($i18nblock['delta']);
// Override form default values, but not block title
foreach (array(
'block_settings',
'user_vis_settings',
'role_vis_settings',
'page_vis_settings',
) as $category) {
if (isset($form['nodeasblockset'][$category])) {
foreach (element_children($form['nodeasblockset'][$category]) as $field) {
if (isset($block->{$field}) && $field != 'title') {
$form['nodeasblockset'][$category][$field]['#default_value'] = $block->{$field};
}
}
}
}
// Override first level value
foreach (array(
'status',
'region',
'weight',
'visibility',
'pages',
'custom',
) as $field) {
if ($form['nodeasblockset'][$field]['#type'] == 'value') {
$form['nodeasblockset'][$field]['#value'] = $block->{$field};
}
elseif (isset($form['nodeasblockset'][$field]['#default_value'])) {
$form['nodeasblockset'][$field]['#default_value'] = $block->{$field};
}
}
$form['nodeasblockset']['i18ntxt'] = array(
'#value' => t('Some block settings have been overridden by the translation block'),
);
}
else {
// Prepare a new block
$i18nblock = array(
'type' => 'nodeasblock',
'info' => '',
'i18nblocks' => array(),
'delta' => '',
'new' => TRUE,
);
}
$form['i18nblock'] = array(
'#type' => 'value',
'#value' => $i18nblock,
);
}
}