Formats a default color field widget.

1 theme call to theme_color_field_default_widget()
color_field_element_info in ./color_field.field.inc
Implements hook_element_info().

File

./color_field.theme.inc, line 118

Code

function theme_color_field_default_widget($vars) {
    $element = $vars['element'];
    // Javascript settings.
    $settings = array();
    $settings['id'] = $element['rgb']['#id'];
    $settings['divid'] = 'div-' . $element['rgb']['#id'];
    $settings['value'] = isset($element['#value']['rgb']) ? $element['#value']['rgb'] : '';
    $default_colors = isset($element['#instance_settings']['default_colors']) ? $element['#instance_settings']['default_colors'] : '';
    preg_match_all("/#[0-9a-fA-F]{6}/", $default_colors, $default_colors, PREG_SET_ORDER);
    foreach ($default_colors as $color) {
        $settings['colors'][] = $color[0];
    }
    // Attach javascript and style.
    $element['rgb']['#attached'] = array(
        'js' => array(
            drupal_get_path('module', 'color_field') . '/color_field_default_widget/color_field.js',
            drupal_get_path('module', 'color_field') . '/color_field_default_widget/color_field.jquery.js',
            array(
                'data' => array(
                    'color_field' => array(
                        '#' . $settings['id'] => $settings,
                    ),
                ),
                'type' => 'setting',
            ),
        ),
        'css' => array(
            drupal_get_path('module', 'color_field') . '/color_field_default_widget/color_field.css',
        ),
    );
    $element['rgb']['#title'] = isset($element['rgb']['#title']) ? $element['rgb']['#title'] : '';
    $element['rgb']['#suffix'] = '<label> ' . $element['rgb']['#title'] . ' </label><div id=div-' . $settings['id'] . '></div><div class="description">' . $element['rgb']['#description'] . '</div>';
    unset($element['rgb']['#title']);
    unset($element['rgb']['#description']);
    // Hide the input field.
    $element['rgb']['#attributes']['class'] = array(
        'element-invisible',
    );
    $output = '';
    $output .= '<div class="link-field-subrow clearfix">';
    $output .= '<div class="link-field-title color-field-column">' . drupal_render($element['rgb']) . '</div>';
    if (isset($element['opacity'])) {
        $output .= '<div class="link-field-title color-field-column">' . drupal_render($element['opacity']) . '</div>';
    }
    $output .= '</div>';
    $output .= drupal_render_children($element);
    return $output;
}