values.install in Values 7
Same filename and directory in other branches
Install file for Values module.
File
values.installView source
<?php
/**
* @file
* Install file for Values module.
*/
/**
* Implements hook_schema().
*/
function values_schema() {
$schema['values_sets'] = array(
'description' => 'List of configured value sets.',
'export' => array(
'key' => 'name',
'identifier' => 'values',
'default hook' => 'default_values_values',
'load callback' => 'values_load',
'load all callback' => 'values_load_all',
'save callback' => 'values_save',
'delete callback' => 'values_delete',
'export callback' => 'values_export',
'api' => array(
'owner' => 'values',
'api' => 'default_values_sets',
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'name' => array(
'description' => 'Unique ID for value sets.',
'type' => 'varchar',
'length' => 255,
),
'title' => array(
'description' => 'Title of the value set',
'type' => 'varchar',
'length' => 255,
),
'description' => array(
'description' => 'A description of the value set',
'type' => 'varchar',
'length' => 255,
),
'data' => array(
'description' => 'Configured list of values.',
'type' => 'text',
'size' => 'big',
'serialize' => TRUE,
),
),
'unique keys' => array(
'name' => array(
'name',
),
),
'primary key' => array(
'name',
),
);
return $schema;
}
/**
* Grant new permissions to roles with the 'administer values' permission
*/
function values_update_7102(&$sandbox) {
foreach (user_role_permissions(user_roles()) as $rid => $permissions) {
// If the user previously had "administer values" we grant them all
// permissions
if (!empty($permissions['administer values'])) {
user_role_change_permissions($rid, array(
'create value sets' => TRUE,
'edit value sets' => TRUE,
'delete value sets' => TRUE,
'import value sets' => TRUE,
'export value sets' => TRUE,
));
}
}
}
/**
* Reformat values stored in database
*/
function values_update_7101(&$sandbox) {
foreach (values_load_all() as $value_set) {
foreach ($value_set->data as $delta => $value) {
if (!empty($value['label'])) {
$value_set->data[$delta] = array(
'key' => $value['value'],
'value' => $value['label'],
'weight' => $value['weight'],
);
}
}
$num_updated = db_update('values_sets')
->fields(array(
'data' => serialize($value_set->data),
))
->condition('name', $value_set->name, '=')
->execute();
}
return;
}
/**
* Rename values_list table to values_sets. Add title column. Copy descriptions
* to new title column
*/
function values_update_7100(&$sandbox) {
db_rename_table('values_list', 'values_sets');
$spec = array(
'description' => 'Title of the value set',
'type' => 'varchar',
'length' => 255,
);
db_add_field('values_sets', 'title', $spec);
// Move the title column (on mysql only - pgsql doesn't have a way to do this
// without creating new columns in a specific order and deleting the old ones)
if (Database::getConnection()
->driver() == 'mysql') {
db_query("ALTER table {values_sets} MODIFY COLUMN title varchar(255) AFTER name");
}
// Update the new title field with whatever was in description
db_query("UPDATE {values_sets} SET title = description");
return;
}
Functions
Name![]() |
Description |
---|---|
values_schema | Implements hook_schema(). |
values_update_7100 | Rename values_list table to values_sets. Add title column. Copy descriptions to new title column |
values_update_7101 | Reformat values stored in database |
values_update_7102 | Grant new permissions to roles with the 'administer values' permission |