Wrap web widget embed code in a collapsible fieldset

EvanDonovan - August 19, 2009 - 15:48
Project:Web Widgets
Version:6.x-1.0
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

For improved look-and-feel on a page with multiple web widget embeds, I wrote a theming function that wraps the widget code in a collapsible fieldset. I think this might be a good addition to the module itself:

<?php
function theme_web_widgets_embed_code($code, $style) {
   
$styles = web_widgets_get_styles();
 
$style_name = $styles[$style];

  static
$num = 0;
 
$form['embed_code'] = array(
       
'#type' => 'fieldset',
   
'#title' => t('Embed this on your website', array('@style' => $style_name)),
       
'#collapsible' => TRUE,
   
'#collapsed' => TRUE,
  );
   
$form['embed_code']['js'] = array(
   
'#type' => 'textfield',
   
'#title' => t('@style embed code', array('@style' => $style_name)),
   
'#description' => t('Copy and paste this code to your web site to embed a dynamic view of this page.'),
   
'#id' => 'web_widgets_'. $num++,
   
'#name' => 'web_widgets',
   
'#value' => $code,
   
'#parents' => array('none'),
   
'#maxlength' => FALSE,
  );
  if (
$style == 'uwa') {
   
$form['embed_code']['js']['#type'] = 'item';
   
$form['embed_code']['js']['#value'] = l($code, $code);
   
$form['embed_code']['js']['#title'] = t('@style widget', array('@style' => $style_name));
   
$form['embed_code']['js']['#description'] = t('Embed your widget on NetVibes or iGoogle.');
  }
  else if (
$style == 'google_gadget') {
   
$form['embed_code']['js']['#title'] = t('@style widget', array('@style' => $style_name));
   
$form['embed_code']['js']['#description'] = t('Copy and paste this code to your iGoogle page.');
  }
  return
drupal_render($form);
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.