yamaps.install in Yandex.Maps 7
Same filename and directory in other branches
Install, update, and uninstall functions for the yamaps module.
File
yamaps.installView source
<?php
/**
* @file
* Install, update, and uninstall functions for the yamaps module.
*/
/**
* Implements hook_field_schema().
*/
function yamaps_field_schema($field) {
return [
'columns' => [
'coords' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Coordinates for "Yandex Maps" object.',
],
'type' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'yandex#map',
'description' => 'Type of "Yandex Maps" object.',
],
'placemarks' => [
'type' => 'text',
'not null' => TRUE,
'description' => 'Settings and data for "Yandex Maps" placemark.',
],
'lines' => [
'type' => 'text',
'not null' => TRUE,
'description' => 'Settings and data for "Yandex Maps" lines.',
],
'polygons' => [
'type' => 'text',
'not null' => TRUE,
'description' => 'Settings and data for "Yandex Maps" polygons.',
],
'routes' => [
'type' => 'text',
'not null' => TRUE,
'description' => 'Settings and data for "Yandex Maps" route.',
],
'hide' => [
'type' => 'int',
'default' => 0,
'description' => 'Flag defining whether "Yandex Maps" field should be hidden for end user or not.',
],
],
'indexes' => [],
];
}
/**
* Implements hook_uninstall().
*/
function yamaps_uninstall() {
// Delete block's settings.
$blocks_amount = variable_get('yamaps_blocks_amount', 1);
$delta = 'yamaps';
for ($block_number = 1; $block_number <= $blocks_amount; $block_number++) {
if ($block_number > 1) {
$delta .= '_' . $block_number;
}
variable_del($delta . '_block_controls');
variable_del($delta . '_block_behaviors');
variable_del($delta . '_block_traffic');
variable_del($delta . '_block_clusterer');
variable_del($delta . '_block_auto_zoom');
variable_del($delta . '_block_width');
variable_del($delta . '_block_height');
variable_del($delta . '_block_coords');
variable_del($delta . '_block_type');
variable_del($delta . '_block_placemarks');
variable_del($delta . '_block_lines');
variable_del($delta . '_block_polygons');
variable_del($delta . '_block_routes');
variable_del($delta . '_block_enable_placemarks');
variable_del($delta . '_block_enable_lines');
variable_del($delta . '_block_enable_polygons');
variable_del($delta . '_block_enable_routes');
}
variable_del('yamaps_block_amount');
variable_del('yamaps_api_key');
}
/**
* Implements hook_update_N().
*
* Alters yamaps_field schema and adds 'hide' column.
*/
function yamaps_update_7000() {
$fields = field_info_fields();
foreach ($fields as $field_name => $field) {
if ($field['type'] == 'field_yamaps' && $field['storage']['type'] == 'field_sql_storage') {
$schema = yamaps_field_schema($field);
foreach ($field['storage']['details']['sql'] as $table_info) {
foreach ($table_info as $table_name => $columns) {
$column_name = _field_sql_storage_columnname($field_name, 'hide');
db_add_field($table_name, $column_name, $schema['columns']['hide']);
db_add_index($table_name, $column_name, [
$column_name,
]);
}
}
}
}
field_cache_clear();
}
/**
* Implements hook_update_N().
*
* Change type of the hide column.
*/
function yamaps_update_7001() {
$fields = db_select('field_config', 'c')
->fields('c', [
'field_name',
])
->condition('c.type', 'field_yamaps')
->execute()
->fetchCol();
$new_description = [
'type' => 'int',
'default' => 0,
'description' => 'Flag defining whether "Yandex Maps" field should be hidden for end user or not.',
];
foreach ($fields as $field_name) {
foreach ([
'field_data',
'field_revision',
] as $table_type) {
$table_name = $table_type . '_' . $field_name;
$column = $field_name . '_hide';
db_change_field($table_name, $column, $column, $new_description);
}
}
}
Functions
Name | Description |
---|---|
yamaps_field_schema | Implements hook_field_schema(). |
yamaps_uninstall | Implements hook_uninstall(). |
yamaps_update_7000 | Implements hook_update_N(). |
yamaps_update_7001 | Implements hook_update_N(). |