Same name and namespace in other branches
  1. 7.x-1.x color_field.module \color_field_field_formatter_settings_form() 1 comment

Implements hook_field_formatter_settings_form().

File

./color_field.field.inc, line 461

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.'),
            );
            if ($field['settings']['opacity'] === 1) {
                $element['opacity_disabled'] = array(
                    '#title' => t('Disable opacity'),
                    '#type' => 'checkbox',
                    '#default_value' => $settings['opacity_disabled'],
                    '#description' => t('Disable the color opacity.'),
                );
            }
            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;
}