1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Installation file for i18nblocks module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_install().
|
10 |
|
|
*/
|
11 |
|
|
function i18n_block_install() {
|
12 |
|
|
module_load_install('i18n');
|
13 |
|
|
i18n_install_create_fields('block', array('i18n_mode'));
|
14 |
|
|
// Set module weight for it to run after all block visibility modules have run
|
15 |
|
|
db_query("UPDATE {system} SET weight = 100 WHERE name = 'i18n_block' AND type = 'module'");
|
16 |
|
|
// If updating from D6, module changed name
|
17 |
|
|
if (variable_get('i18n_drupal6_update')) {
|
18 |
|
|
i18n_block_update_7000();
|
19 |
|
|
i18n_block_update_7001();
|
20 |
|
|
}
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* Implements hook_uninstall().
|
25 |
|
|
*/
|
26 |
|
|
function i18n_block_uninstall() {
|
27 |
|
|
db_drop_field('block', 'i18n_mode');
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
|
|
* Implements hook_schema().
|
32 |
|
|
*/
|
33 |
|
|
function i18n_block_schema() {
|
34 |
|
|
$schema['i18n_block_language'] = array(
|
35 |
|
|
'description' => 'Sets block visibility based on language',
|
36 |
|
|
'fields' => array(
|
37 |
|
|
'module' => array(
|
38 |
|
|
'type' => 'varchar',
|
39 |
|
|
'length' => 64,
|
40 |
|
|
'not null' => TRUE,
|
41 |
|
|
'description' => "The block's origin module, from {block}.module.",
|
42 |
|
|
),
|
43 |
|
|
'delta' => array(
|
44 |
|
|
'type' => 'varchar',
|
45 |
|
|
'length' => 32,
|
46 |
|
|
'not null' => TRUE,
|
47 |
|
|
'description' => "The block's unique delta within module, from {block}.delta.",
|
48 |
|
|
),
|
49 |
|
|
'language' => array(
|
50 |
|
|
'type' => 'varchar',
|
51 |
|
|
'length' => 12,
|
52 |
|
|
'not null' => TRUE,
|
53 |
|
|
'default' => '',
|
54 |
|
|
'description' => "Language code, e.g. 'de' or 'en-US'.",
|
55 |
|
|
),
|
56 |
|
|
),
|
57 |
|
|
'primary key' => array('module', 'delta', 'language'),
|
58 |
|
|
'indexes' => array(
|
59 |
|
|
'language' => array('language'),
|
60 |
|
|
),
|
61 |
|
|
);
|
62 |
|
|
return $schema;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Implements hook_schema_alter().
|
67 |
|
|
*
|
68 |
|
|
* Add block table i18n_mode field
|
69 |
|
|
*/
|
70 |
|
|
function i18n_block_schema_alter(&$schema) {
|
71 |
|
|
$schema['block']['fields']['i18n_mode'] = array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'Block multilingual mode.');
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
/**
|
75 |
|
|
* Drupal 6 update from old i18nblocks module.
|
76 |
|
|
*/
|
77 |
|
|
function i18n_block_update_7000() {
|
78 |
|
|
// D6-D7 updates, to be written
|
79 |
|
|
// move block language from i18n_blocks into i18n_block_language
|
80 |
|
|
// Move block type from i18n_blocks into block table (i18n_mode)
|
81 |
|
|
if (db_table_exists('i18n_blocks')) {
|
82 |
|
|
foreach (db_query("SELECT * FROM {i18n_blocks}")->fetchAll() as $block) {
|
83 |
|
|
if ($block->language) {
|
84 |
|
|
// Set language for block
|
85 |
|
|
db_merge('i18n_block_language')
|
86 |
|
|
->key(array('module' => $block->module, 'delta' => $block->delta))
|
87 |
|
|
->fields(array('language' => $block->language))
|
88 |
|
|
->execute();
|
89 |
|
|
}
|
90 |
|
|
else {
|
91 |
|
|
// Mark block as translatable
|
92 |
|
|
db_update('block')
|
93 |
|
|
->fields(array('i18n_mode' => 1))
|
94 |
|
|
->condition('module', $block->module)
|
95 |
|
|
->condition('delta', $block->delta)
|
96 |
|
|
->execute();
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
/**
|
103 |
|
|
* Drop Drupal 6 {i18n_blocks} table after migration.
|
104 |
|
|
*/
|
105 |
|
|
function i18n_block_update_7001() {
|
106 |
|
|
if (db_table_exists('i18n_blocks')) {
|
107 |
|
|
db_drop_table('i18n_blocks');
|
108 |
|
|
}
|
109 |
|
|
} |