You are here

function theme_fivestar_color_form in Fivestar 6

Same name and namespace in other branches
  1. 5 fivestar_color.inc \theme_fivestar_color_form()
  2. 6.2 includes/fivestar.color.inc \theme_fivestar_color_form()

Theme color form.

1 theme call to theme_fivestar_color_form()
fivestar_color_form in ./fivestar_color.inc
Form callback. Returns the configuration form.

File

./fivestar_color.inc, line 102
File containing functions relating to the color widget.

Code

function theme_fivestar_color_form($form) {
  if (isset($form['#access']) && $form['#access'] == FALSE) {
    return '';
  }

  // Add Farbtastic color picker.
  drupal_add_css('misc/farbtastic/farbtastic.css', 'module', 'all', FALSE);
  drupal_add_js(drupal_get_path('module', 'fivestar') . '/js/fivestar-color.js');
  drupal_add_js('misc/farbtastic/farbtastic.js');

  // Add custom CSS/JS.
  $default_colors = array();
  foreach (element_children($form['fivestar_colors']) as $key) {
    $default_colors[$key] = $form['fivestar_colors'][$key]['#value'];
  }
  drupal_add_js(array(
    'fivestar' => array(
      'reference' => $default_colors,
      'transparent' => t('none'),
      'colorPreview' => url('fivestar/preview/color'),
    ),
  ), 'setting');

  // Wrapper.
  $output .= '<div class="color-form clear-block">';

  // Color schemes.
  $output .= drupal_render($form['fivestar_color_type']);
  $output .= drupal_render($form['scheme']);

  // Palette.
  $output .= '<div id="fivestar-palette" class="clear-block">';
  foreach (element_children($form['fivestar_colors']) as $key => $name) {

    // Render pairs on a single line inside a new form element.
    if (strpos($name, '1')) {
      $name2 = str_replace('1', '2', $name);
      $title = $form['fivestar_colors'][$name]['#title'];
      unset($form['fivestar_colors'][$name]['#title']);
      $element = array(
        '#type' => 'element',
        '#title' => $title,
        '#children' => drupal_render($form['fivestar_colors'][$name]) . drupal_render($form['fivestar_colors'][$name2]),
      );
      $output .= theme('form_element', $element, $element['#children']);
    }
    $output .= drupal_render($form['fivestar_colors'][$name]);
  }
  $output .= '</div>';

  // Render the form.
  $output .= drupal_render($form);

  // Close wrapper.
  $output .= '</div>';
  return $output;
}