soundcloudfield.install in SoundCloud field 7
Same filename and directory in other branches
Install, update and uninstall functions for the SoundCloud field module.
@author Attila Fekete - http://drupal.org/user/762986
File
soundcloudfield.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the SoundCloud field module.
*
*
* @author Attila Fekete - http://drupal.org/user/762986
*/
/**
* Implements hook_field_schema().
*/
function soundcloudfield_field_schema($field) {
return array(
'columns' => array(
'url' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'sortable' => TRUE,
),
),
);
}
/**
* Update field instances to be in sync with the new instance settings.
*/
function soundcloudfield_update_7000() {
$instances = field_info_instances();
foreach ($instances as $entity_type => $entities) {
foreach ($entities as $bundle => $fields) {
foreach ($fields as $field_name => $instance) {
if (in_array($instance['widget']['type'], array(
'soundcloud_url',
))) {
$changed = FALSE;
if (!empty($instance['settings']['soundcloudplayer'])) {
if (empty($instance['settings']['soundcloudplayer']['flash_player']) || !isset($instance['settings']['soundcloudplayer']['flash_player']['height']) || !isset($instance['settings']['soundcloudplayer']['flash_player']['height_sets']) || !isset($instance['settings']['soundcloudplayer']['flash_player']['showcomments'])) {
$instance['settings']['soundcloudplayer']['flash_player'] = array(
'height' => 81,
'height_sets' => 305,
'showcomments' => 0,
);
$changed = TRUE;
}
if (empty($instance['settings']['soundcloudplayer']['html5_player']) || !isset($instance['settings']['soundcloudplayer']['html5_player']['html5_player_height']) || !isset($instance['settings']['soundcloudplayer']['html5_player']['html5_player_height_sets'])) {
$instance['settings']['soundcloudplayer']['html5_player'] = array(
'html5_player_height' => SOUNDCLOUDFIELD_DEFAULT_HTML5_PLAYER_HEIGHT,
'html5_player_height_sets' => SOUNDCLOUDFIELD_DEFAULT_HTML5_PLAYER_HEIGHT_SETS,
);
$changed = TRUE;
}
if (empty($instance['settings']['soundcloudplayer']['visual_player']) || !isset($instance['settings']['soundcloudplayer']['visual_player']['visual_player_height'])) {
$instance['settings']['soundcloudplayer']['visual_player'] = array(
'visual_player_height' => SOUNDCLOUDFIELD_DEFAULT_VISUAL_PLAYER_HEIGHT,
);
$changed = TRUE;
}
}
if ($changed) {
field_update_instance($instance);
}
}
}
}
}
field_cache_clear();
drupal_set_message(t('Field instances of type SoundCloud have been updated.'));
}
/**
* Remove Flash-player-specific settings from the field instances.
*/
function soundcloudfield_update_7001() {
$instances = field_info_instances();
foreach ($instances as $entity_type => $entities) {
foreach ($entities as $bundle => $fields) {
foreach ($fields as $field_name => $instance) {
$changed = FALSE;
if (in_array($instance['widget']['type'], array(
'soundcloud_url',
))) {
if (isset($instance['settings']['soundcloudplayer']['flash_player'])) {
unset($instance['settings']['soundcloudplayer']['flash_player']);
$changed = TRUE;
}
if (isset($instance['settings']['height'])) {
unset($instance['settings']['height']);
$changed = TRUE;
}
if (isset($instance['settings']['height_sets'])) {
unset($instance['settings']['height_sets']);
$changed = TRUE;
}
if (isset($instance['settings']['showcomments'])) {
unset($instance['settings']['showcomments']);
$changed = TRUE;
}
}
if ($changed) {
field_update_instance($instance);
}
}
}
}
field_cache_clear();
drupal_set_message(t('Field instances of type SoundCloud have been updated.'));
}
Functions
Name | Description |
---|---|
soundcloudfield_field_schema | Implements hook_field_schema(). |
soundcloudfield_update_7000 | Update field instances to be in sync with the new instance settings. |
soundcloudfield_update_7001 | Remove Flash-player-specific settings from the field instances. |