You are here

function color_field_field_widget_info in Color Field 7.2

Same name and namespace in other branches
  1. 7 color_field.module \color_field_field_widget_info()

Implements hook_field_widget_info().

Enable the different field widgets.

See also

color_field_field_settings_form()

color_field_field_instance_settings_form

color_field_field_widget_form()

File

./color_field.field.inc, line 286
Field hooks to implement a color field.

Code

function color_field_field_widget_info() {

  // If jquery-simple-color is enable so widget can be used.
  $jquery_simple_color_picker_enable = TRUE;
  $color_field_library_jquery_simple_color = drupal_get_library('color_field', 'jquery-simple-color');
  foreach ($color_field_library_jquery_simple_color['js'] as $path => $js) {
    if (!file_exists($path)) {
      $jquery_simple_color_picker_enable = FALSE;
    }
  }

  // If jquery_dematte_color_picker_enable is enable so widget can be used.
  $jquery_dematte_color_picker_enable = TRUE;
  $color_field_library_dematte_color = drupal_get_library('color_field', 'dematte-color-picker');
  foreach ($color_field_library_dematte_color['js'] as $path => $js) {
    if (!file_exists($path)) {
      $jquery_dematte_color_picker_enable = FALSE;
    }
  }

  // If jquery_eyecon_color_picker_enable is enable so widget can be used.
  $jquery_eyecon_color_picker_enable = TRUE;
  $color_field_library_eyecon_color = drupal_get_library('color_field', 'eyecon-color-picker');
  foreach ($color_field_library_eyecon_color['js'] as $path => $js) {
    if (!file_exists($path)) {
      $jquery_eyecon_color_picker_enable = FALSE;
    }
  }

  // If jquery_spectrum_color_picker_enable is enable so widget can be used.
  $jquery_spectrum_color_picker_enable = TRUE;
  $color_field_library_spectrum_color = drupal_get_library('color_field', 'bgrins-spectrum');
  foreach ($color_field_library_spectrum_color['js'] as $path => $js) {
    if (!file_exists($path)) {
      $jquery_spectrum_color_picker_enable = FALSE;
    }
  }
  foreach ($color_field_library_spectrum_color['css'] as $path => $js) {
    if (!file_exists($path)) {
      $jquery_spectrum_color_picker_enable = FALSE;
    }
  }
  $widgets = array();
  $widgets['color_field_default_widget'] = array(
    'label' => t('Pre-selected Color Boxes'),
    'field types' => array(
      'color_field_rgb',
    ),
    'weight' => 2,
  );

  // Color_field_farbtastic_widget need more work before release.

  /*$widgets['color_field_farbtastic_widget'] = array(
      'label' => t('Farbtastic Color-Picker'),
      'field types' => array('color_field_rgb'),
    );*/

  // Check if color_field_simple_color can become color_field_simple_widget
  if ($jquery_simple_color_picker_enable) {
    $widgets['color_field_simple_widget'] = array(
      'label' => t('Simple Color-Picker'),
      'field types' => array(
        'color_field_rgb',
      ),
      'weight' => 3,
    );
  }

  // Color_field_dematte_widget need more work before release.

  /*if ($jquery_dematte_color_picker_enable) {
      $widgets['color_field_dematte_widget'] = array(
        'label' => t('Dematte Color-Picker'),
        'field types' => array('color_field_rgb'),
      );
    }*/

  // color_field_eyecon_widget need more work before release.

  /*if ($jquery_eyecon_color_picker_enable) {
      $widgets['color_field_eyecon_widget'] = array(
        'label' => t('Eyecon Color-Picker'),
        'field types' => array('color_field_rgb'),
      );
    }*/

  // Dematte colorPicker.
  if ($jquery_spectrum_color_picker_enable) {
    $widgets['color_field_spectrum_widget'] = array(
      'label' => t('Spectrum Color-Picker'),
      'field types' => array(
        'color_field_rgb',
      ),
      'weight' => 4,
    );
  }

  // Textfield.
  $widgets['color_field_plain_text'] = array(
    'label' => t('Plain text (RGB value as #ffffff)'),
    'field types' => array(
      'color_field_rgb',
    ),
    'weight' => 1,
  );
  return $widgets;
}