TRUE, '#process' => array('colorpicker_textfield_process'), '#element_validate' => array('colorpicker_textfield_validate') ); return $type; } /** * Register our theme functions */ function colorpicker_theme() { return array( 'colorpicker_textfield' => array( 'arguments' => array('element' => NULL) ) ); } /** * Format our colorpicker textfield. * * @param $element * An associative array containing the properties of the element. * Properties used: title, value, description, required, attributes * @return * A themed HTML string representing the textfield. */ function theme_colorpicker_textfield($element) { $path = drupal_get_path('module', 'colorpicker'); // Add Farbtastic color picker drupal_add_css('misc/farbtastic/farbtastic.css'); drupal_add_js('misc/farbtastic/farbtastic.js'); // Add our custom js and css for our colorpicker drupal_add_js("$path/js/colorpicker.js"); drupal_add_css("$path/css/colorpicker.css"); if (isset($element['#field_prefix'])) { $output[] = ''. $element['#field_prefix'] .' '; } // Add the required classname to the input element $class = array('colorpicker_textfield','uniform-processed'); _form_set_class($element, $class); $output[] = ''; if (isset($element['#field_suffix'])) { $output[] = ' '. $element['#field_suffix'] .''; } // Add a wrapper div. Only when if Javascript is enabled, a button is added inside this wrapper. // If the button is clicked, the colorpicker will be added to this wrapper too. $output[] = '
'; return theme('form_element', $element, join("\n", $output)); } /** * Preprocess color fields to scrub for bad values */ function colorpicker_textfield_process($element, $edit, &$form_state, $complete_form) { if ($element['#value'] == '#') { $element['#value'] = ''; } return $element; } /** * Check to make sure the user has entered a valid 3 or 6 digit hex color. */ function colorpicker_textfield_validate($element, &$form_values) { if (!preg_match('/^(#(?:(?:[a-f\d]{3}){0,2}))?$/i', $element['#value'])) { form_error($element, "'". check_plain($element['#value']) ."'". t(' is not a valid hex color')); } } function colorpicker_2_or_later() { }