Newer
Older
<?php
/**
* @file
* Installation file for i18nblocks module.
*/
/**
* Implements hook_install()
*/
function i18n_block_install() {
module_load_install('i18n');
i18n_install_create_fields('block', array('i18n_mode'));
// Set module weight for it to run after all block visibility modules have run
db_query("UPDATE {system} SET weight = 100 WHERE name = 'i18n_block' AND type = 'module'");
// If updating from D6, module changed name
if (variable_get('i18n_drupal6_update')) {
i18n_block_update_7000();
}
}
/**
* Implements hook_uninstall()
*/
function i18n_block_uninstall() {
db_drop_field('block', 'i18n_mode');
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
}
/**
* Implements hook_schema().
*/
function i18n_block_schema() {
$schema['i18n_block_language'] = array(
'description' => 'Sets block visibility based on language',
'fields' => array(
'module' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'description' => "The block's origin module, from {block}.module.",
),
'delta' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'description' => "The block's unique delta within module, from {block}.delta.",
),
'language' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
'description' => "Language code, e.g. 'de' or 'en-US'.",
),
),
'primary key' => array('module', 'delta', 'language'),
'indexes' => array(
'language' => array('language'),
),
);
return $schema;
}
/**
* Implements hook_schema_alter().
*
* Add block table i18n_mode field
*/
function i18n_block_schema_alter(&$schema) {
$schema['block']['fields']['i18n_mode'] = array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'Block multilingual mode.');
}
/**
* Implements hook i18n_update_drupal6()
*/
function i18n_block_update_7000() {
// D6-D7 updates, to be written
// move block language from i18n_blocks into i18n_block_language
// Move block type from i18n_blocks into block table (i18n_mode)
if (db_table_exists('i18n_blocks')) {
foreach (db_query("SELECT * FROM {i18n_blocks}")->fetchAll() as $block) {
if ($block->language) {
// Set language for block
db_merge('i18n_block_language')
->key(array('module' => $block->module, 'delta' => $block->delta))
->fields(array('language' => $block->language))
->execute();
}
else {
// Mark block as translatable
db_update('block')
->fields(array('i18n_mode' => 1))
->condition('module', $block->module)
->condition('delata', $block->delta)
->execute();
}
}
// @todo Drop table if everything is ok