Commit 45e87bfa authored by attila.fekete's avatar attila.fekete
Browse files

Update field instances to be in sync with the new instance settings (update hook)

parent 28f6cd60
<?php
/**
* @file
* Install file for the SoundCloud field module.
* Install, update and uninstall functions for the SoundCloud field module.
*
*
* @author Attila Fekete - http://drupal.org/user/762986
......@@ -22,3 +22,49 @@ function soundcloudfield_field_schema($field) {
),
);
}
/**
* 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' => SOUNDCLOUDFIELD_DEFAULT_HEIGHT,
'height_sets' => SOUNDCLOUDFIELD_DEFAULT_HEIGHT_SETS,
'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.'));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment