function i18nblocks_form in Internationalization 5
Same name and namespace in other branches
- 5.3 i18nblocks/i18nblocks.module \i18nblocks_form()
- 5.2 i18nblocks/i18nblocks.module \i18nblocks_form()
Form for multilingual blocks
1 call to i18nblocks_form()
- i18nblocks_block in i18nblocks/
i18nblocks.module - Implementation of hook_block()
1 string reference to 'i18nblocks_form'
- i18nblocks_admin in i18nblocks/
i18nblocks.module - Add a new metablock and go to settings page
File
- i18nblocks/
i18nblocks.module, line 203
Code
function i18nblocks_form($metablock, $delta = NULL) {
$languages = i18n_supported_languages();
$modules = array_intersect(module_list(), module_implements('block'));
// Compile list of available blocks
$blocklist = array(
'' => t(' -- '),
);
foreach (module_implements('block') as $module) {
if ($module != 'i18nblocks') {
// Avoid this module's blocks, could be funny :-)
if (is_array($module_blocks = module_invoke($module, 'block', 'list'))) {
foreach ($module_blocks as $number => $block) {
$blocklist[$module . ':' . $number] = $block['info'] . "({$module})";
}
}
}
}
$form['info'] = array(
'#type' => 'textfield',
'#title' => t('Block description'),
'#default_value' => $metablock->info ? $metablock->info : t('Multilingual block !number', array(
'!number' => $delta,
)),
'#size' => 40,
'#maxlength' => 40,
);
$form['type'] = array(
'#type' => 'value',
'#value' => $metablock->type ? $metablock->type : '',
);
$form['i18nblocks'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#title' => t('Select the block to be displayed for each language'),
);
foreach ($languages as $lang => $langname) {
$block = isset($metablock->blocks[$lang]) ? $metablock->blocks[$lang] : NULL;
$form['i18nblocks'][$lang] = array(
'#type' => 'select',
'#title' => $langname,
'#default_value' => $block ? $block->module . ':' . $block->delta : '',
'#options' => $blocklist,
);
}
// Submit button only for new blocks
if ($delta) {
$form['delete'] = array(
'#value' => l(t('Delete this block'), 'admin/build/block/i18n/delete/' . $delta),
);
$form['type'] = array(
'#type' => 'radios',
'#default_value' => $metablock->type,
'#options' => array(
'' => t('Normal translation block'),
),
'#disabled' => TRUE,
);
if (module_exists('nodeasblock')) {
$form['type']['#options']['nodeasblock'] = t('Node as block with automatic synchronization');
$form['type']['#disabled'] = FALSE;
}
}
else {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Create block'),
);
}
return $form;
}