ds.install in Display Suite 6.2
Same filename and directory in other branches
Display suite install file.
File
ds.installView source
<?php
/**
* @file
* Display suite install file.
*/
/**
* Implements hook_schema().
*/
function ds_schema() {
$schema = array();
$schema['ds_settings'] = array(
'description' => 'The settings for Display Suite',
'fields' => array(
'module' => array(
'description' => 'The name of the module',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'type' => array(
'description' => 'The name of the type',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'build_mode' => array(
'description' => 'The name of the build mode',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'settings' => array(
'description' => 'The settings of for this record.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'default' => '',
),
'fields' => array(
'description' => 'The fields of for this record.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'default' => '',
),
),
'indexes' => array(
'module' => array(
'module',
),
'build_mode' => array(
'build_mode',
),
'type' => array(
'type',
),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function ds_install() {
drupal_install_schema('ds');
}
/**
* Implements hook_uninstall().
*/
function ds_uninstall() {
drupal_uninstall_schema('ds');
db_query("DELETE FROM {variable} WHERE name LIKE 'ds_%%'");
cache_clear_all('variables', 'cache');
}
/**
* Implements hook_update_N().
*
* We simply return an array here. We want the people to
* run update.php because new theming functions got introduced.
*/
function ds_update_1() {
return array();
}
/**
* Implements hook_update_N().
*/
function ds_update_2() {
// Enable the UI module, not everyone knows that the module UI
// and core are separated now.
module_enable(array(
'ds_ui',
));
return array();
}
/**
* Implements hook_update_N().
*/
function ds_update_3() {
// Needs menu rebuild.
return array();
}
/**
* Implements hook_update_N().
*/
function ds_update_4() {
$ret = array();
// Create schema.
$schema = ds_schema();
foreach ($schema as $name => $spec) {
db_create_table($ret, $name, $spec);
}
// Refresh static cache.
drupal_get_schema('ds_settings', TRUE);
$all_build_modes = ds_get_build_modes(NULL, TRUE);
// Take the 'module'_display_settings and store them in the table.
foreach (module_implements('ds_api') as $module) {
$api_info = ds_api_info($module);
$module = $api_info['module'];
// Get all types.
foreach ($api_info['types']() as $type) {
// Get the display settings.
$display_settings = variable_get($module . '_display_settings_' . $type->type, array());
if (!empty($display_settings)) {
// Iterate over known build modes and save them.
$build_modes = $all_build_modes[$module];
foreach (array_keys($build_modes) as $build_mode) {
if (isset($display_settings[$build_mode])) {
$settings = $display_settings[$build_mode];
// Iterate over fields and ditch those which are hidden.
foreach ($settings['fields'] as $field_key => $field_value) {
if ($field_value['region'] == 'disabled') {
unset($settings['fields'][$field_key]);
}
}
// Save the record.
$record = new stdClass();
$record->module = $module;
$record->type = $type->type;
$record->build_mode = $build_mode;
$record->settings = serialize($settings);
drupal_write_record('ds_settings', $record);
}
}
}
// Delete variable.
variable_del($module . '_display_settings_' . $type->type);
}
// Remove the fields cached.
variable_del('ds_fields_cached');
}
return $ret;
}
/**
* Update the settings table.
*/
function ds_update_6201() {
$ret = array();
db_change_field($ret, 'ds_settings', 'settings', 'settings', array(
'description' => 'The settings for this record.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'default' => '',
));
db_change_field($ret, 'ds_settings', 'fields', 'fields', array(
'description' => 'The fields for this record.',
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'default' => '',
));
return $ret;
}
/**
* Update the settings table.
*/
function ds_update_6202() {
$ret = array();
db_drop_index($ret, 'ds_settings', 'type');
db_change_field($ret, 'ds_settings', 'type', 'type', array(
'description' => 'The name of the type',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
));
db_add_index($ret, 'ds_settings', 'type', array(
'type',
));
db_drop_index($ret, 'ds_settings', 'build_mode');
db_change_field($ret, 'ds_settings', 'build_mode', 'build_mode', array(
'description' => 'The name of the build mode',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
));
db_add_index($ret, 'ds_settings', 'build_mode', array(
'build_mode',
));
return $ret;
}
Functions
Name | Description |
---|---|
ds_install | Implements hook_install(). |
ds_schema | Implements hook_schema(). |
ds_uninstall | Implements hook_uninstall(). |
ds_update_1 | Implements hook_update_N(). |
ds_update_2 | Implements hook_update_N(). |
ds_update_3 | Implements hook_update_N(). |
ds_update_4 | Implements hook_update_N(). |
ds_update_6201 | Update the settings table. |
ds_update_6202 | Update the settings table. |