You are here

function color_field_field_formatter_settings_form in Color Field 7

Same name and namespace in other branches
  1. 7.2 color_field.field.inc \color_field_field_formatter_settings_form()

Implements hook_field_formatter_settings_form().

File

./color_field.module, line 406
An color field with a custom color picker using the Field Types API.

Code

function color_field_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $element = array();
  switch ($display['type']) {
    case 'color_field_css_declaration':
      $element['selector'] = array(
        '#title' => t('Selector'),
        '#type' => 'textarea',
        '#default_value' => $settings['selector'],
        '#required' => TRUE,
        '#description' => t('A valid CSS selector such as <code>.links > li > a, #logo</code>.'),
      );
      $element['token'] = array(
        '#theme' => 'token_tree',
        '#token_types' => array(
          $instance['entity_type'],
        ),
        '#dialog' => TRUE,
      );
      $element['property'] = array(
        '#title' => t('Property'),
        '#type' => 'select',
        '#default_value' => $settings['property'],
        '#required' => TRUE,
        '#options' => array(
          'background-color' => t('Background color'),
          'color' => t('Text color'),
        ),
      );
      $element['important'] = array(
        '#title' => t('Important'),
        '#type' => 'checkbox',
        '#default_value' => $settings['important'],
        '#description' => t('Whenever this declaration is more important than others.'),
      );
      break;
    case 'color_field_swatch':
      $element['width'] = array(
        '#title' => t('Width'),
        '#type' => 'textfield',
        '#default_value' => $settings['width'],
        '#description' => t('Enter desired pixel width for the color swatch as a number only.'),
        '#required' => TRUE,
        "#element_validate" => array(
          '_color_field_validate_number',
        ),
      );
      $element['height'] = array(
        '#title' => t('Height'),
        '#type' => 'textfield',
        '#default_value' => $settings['height'],
        '#description' => t('Enter desired pixel height for the color swatch as a number only.'),
        '#required' => TRUE,
        "#element_validate" => array(
          '_color_field_validate_number',
        ),
      );
      break;
  }
  return $element;
}