Saving/Reading settings
Devis - December 18, 2007 - 09:27
| Project: | SWFObject API |
| Version: | 5.x-1.2-6 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
A modified swfobject_api_settings_form function that present the saved values. I've marked the modified lines, please check ;-)
function swfobject_api_settings_form() {
$form = array();
$settings=variable_get('swfobject_api_settings', array("swfoa_version"=>"6","swfoa_express"=>"")); /* <------------------ ADDED */
$form['swfobject_api_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Settings'),
'#tree' => TRUE
);
$form['swfobject_api_settings']['swfoa_version'] = array(
'#type' => 'textfield',
'#title' => t('Default minimum version required'),
'#description' => t('This value can be overridden via the theme call.'),
'#default_value' => $settings["swfoa_version"], /* <------------------ CORRECTED/MODIFIED */
'#required' => TRUE
);
$form['swfobject_api_settings']['swfoa_express'] = array(
'#type' => 'checkbox',
'#title' => t('Enable express install.'),
'#description' => t('Express install allows player upgrades without having to leave the site. Only versions 6.0.65 and above are supported.'),
'#default_value' => $settings["swfoa_express"], /* <------------------ MODIFIED */
);
$form['submit'] = array('#type' => 'submit', '#value' => t('Save settings'));
return system_settings_form($form);
}A modified theme_swfobject_api function that uses the saved values.
function theme_swfobject_api($url, $params = null, $vars = null, $id = null) {
static $id_count;
$settings=variable_get('swfobject_api_settings', array("swfoa_version"=>"6","swfoa_express"=>"")); /* <------------------ ADDED */
$path = drupal_get_path('module', 'swfobject_api');
drupal_add_js($path .'/swfobject.js');
$base_params = array(
'width' => '100%',
'height' => '100%',
'no_flash' => t('Sorry, you need to install flash to see this content.'),
'version' => $settings["swfoa_version"], /* <------------------ MODIFIED */
'type' => 'movie',
'bg_color' => '#FFFFFF'
);
$params = array_merge($base_params, $params);
// Express install redirect URL: as per the SWFObject docs, this should
// actually be xiRedirectUrl; variable name changed for simplicity.
if (isset($param['express_redirect'])) {
$redirect = $param['express_redirect'];
}
// create a unique id, use what's passed in, what has been saved locally
if ($id) { $id_count = $id; }
else {
$id_count = $id_count ? $id_count : 1;
}
// set the name of the swf file
$name = form_clean_id(str_replace('.swf', '', basename($url))) .'_'. $id_count;
// set the div id to the params
if ($params['div_id']) {
$div_id = $params['div_id'];
unset($params['div_id']);
}
else {
$div_id = 'flashcontent_'. $name;
}
// build the class
if ($params['class']) {
$class = ' class="'. $params['class'] .'"';
unset($params['class']);
}
// build the div structure
$html = '<div id="'. $div_id .'" '. $class .'>'. $base_params['no_flash'] ."</div>\n";
// build the javascript
$html .= "<script type=\"text/javascript\">var so$id_count = new SWFObject('$url', 'swf_$name', '". $params['width'] ."', '". $params['height'] ."', '". $params['version'] ."', '". $params['bg_color'] ."');\n";
// we can remove these all now since they
unset($params['width'], $params['height'], $params['no_flash'], $params['version'], $params['bg_color'], $params['express_redirect']);
if ($params) {
foreach ($params as $key => $value) {
$html .= " so$id_count.addParam('$key', '$value');\n";
}
}
if ($vars) {
foreach ($vars as $key => $value) {
$html .= " so$id_count.addVariable('$key', '$value');\n";
}
}
if ($settings["swfoa_version"]) { /* <------------------ MODIFIED */
$html .= " so$id_count.useExpressInstall('". $path ."/expressinstall.swf');\n";
if (isset($redirect)) {
$html .= " so$id_count.setAttribute('xiRedirectUrl', '". $redirect ."');\ns";
}
}
$html .= ' $(document).ready(function () { so'. $id_count .'.write("'. $div_id .'");}); </script>';
// increment the id count
$id_count ++;
return $html;
}
#1
Hi Devis-
Thanks for taking the time to do this. Generally Drupal folks prefer patch files (see: http://drupal.org/patch/create) which make it a bit easier to apply the changes that you're suggesting. I'll look this over and see if can integrate this.
thanks for your suggestions.
#2
Hi Arthuf, here it is the patch