array( 'description' => 'The RGB hex values prefix with #', 'type' => 'varchar', 'length' => 7, 'not null' => FALSE, ), 'opacity' => array( 'description' => 'The opacity/alphavalue property', 'type' => 'float', 'size' => 'tiny', 'not null' => FALSE, 'default' => 1, ), ); $indexes = array( 'rgb' => array('rgb'), ); return array( 'columns' => $columns, 'indexes' => $indexes, ); } /** * Implements hook_requirements(). */ function color_field_requirements($phase) { $requirements = array(); if ($phase == 'runtime') { $t = get_t(); $color_field_library = drupal_get_library('color_field', 'jquery-simple-color'); foreach ($color_field_library['js'] as $path => $js) { if (!file_exists($path)) { $requirements['jquery-simple-color'] = array( 'severity' => REQUIREMENT_WARNING, 'title' => $t('Color Field (jquery simple color)'), 'value' => $t('Missing'), 'description' => $t('The jquery simple color library isn\'t available so this Color Field Module will not support the jQuery Simple Color widget. Please download the plugin (%version) from !website.', array( '!website' => l($color_field_library['website'], $color_field_library['website']), '%version' => $color_field_library['version'], ) ), ); break; } } if (!isset($requirements['jquery-simple-color'])) { $requirements['jquery-simple-color'] = array( 'severity' => REQUIREMENT_OK, 'title' => $color_field_library['title'], 'value' => $color_field_library['version'], ); } } return $requirements; } /** * Add opacity column to color field schema and populate with a default value of 1. */ function color_field_update_7000(array &$sandbox) { $fields = _update_7000_field_read_fields(array( 'module' => 'color_field', 'storage_type' => 'field_sql_storage', 'deleted' => 0, )); foreach ($fields as $field) { $tables = array( _field_sql_storage_tablename($field), _field_sql_storage_revision_tablename($field), ); foreach ($tables as $table) { // Add the opacity column to the table. _color_field_update_7000_add_opacity_column($table, $field['field_name']); _color_field_update_7000_populate_opacity($table, $field['field_name']); } } } /** * Add opacity column to a specific table. * * @param string $table * The name of the database table to be updated. * @param string $field_name * Keyed array of columns this table is supposed to have. */ function _color_field_update_7000_add_opacity_column($table, $field_name) { $spec = array( 'description' => 'The opacity/alphavalue property', 'type' => 'float', 'size' => 'tiny', 'not null' => FALSE, 'default' => 1, ); $spec['description'] = 'The width of the image in pixels.'; // Make sure the field does not exist yet. if (!db_field_exists($table, $field_name . '_opacity')) { db_add_field($table, $field_name . '_opacity', $spec); } } /** * Populate color field opacity in a specific table. * * @param string $table * The name of the database table to be updated. * @param string $field_name * Keyed array of columns this table is supposed to have. */ function _color_field_update_7000_populate_opacity($table, $field_name) { db_update($table) ->fields(array( $field_name . '_opacity' => 1, )) ->isNull($field_name . '_opacity') ->execute(); }