Same name and namespace in other branches
  1. 7.x-2.x color_field.field.inc \color_field_field_settings_form()

Implements hook_field_settings_form().

Handle the parameters for a field.

File

./color_field.module, line 254

Code

function color_field_field_settings_form($field, $instance, $has_data) {
    $settings = $field['settings'];
    $form = array();
    switch ($instance['widget']['type']) {
        case 'color_field_simple_color':
        case 'color_field_simple_widget':
            $form['cell_width'] = array(
                '#type' => 'textfield',
                '#title' => t('Cell width'),
                '#default_value' => isset($settings['cell_width']) ? $settings['cell_width'] : 10,
                '#required' => TRUE,
                '#description' => t('Width of each individual color cell.'),
            );
            $form['cell_height'] = array(
                '#type' => 'textfield',
                '#title' => t('Height width'),
                '#default_value' => isset($settings['cell_height']) ? $settings['cell_height'] : 10,
                '#required' => TRUE,
                '#description' => t('Height of each individual color cell.'),
            );
            $form['cell_margin'] = array(
                '#type' => 'textfield',
                '#title' => t('Cell margin'),
                '#default_value' => isset($settings['cell_margin']) ? $settings['cell_margin'] : 1,
                '#required' => TRUE,
                '#description' => t('Margin of each individual color cell.'),
            );
            $form['box_width'] = array(
                '#type' => 'textfield',
                '#title' => t('Box width'),
                '#default_value' => isset($settings['box_width']) ? $settings['box_width'] : 115,
                '#required' => TRUE,
                '#description' => t('Width of the color display box.'),
            );
            $form['box_height'] = array(
                '#type' => 'textfield',
                '#title' => t('Box height'),
                '#default_value' => isset($settings['box_height']) ? $settings['box_height'] : 20,
                '#required' => TRUE,
                '#description' => t('Height of the color display box.'),
            );
            $form['columns'] = array(
                '#type' => 'textfield',
                '#title' => t('Columns number'),
                '#default_value' => isset($settings['columns']) ? $settings['columns'] : 16,
                '#required' => TRUE,
                '#description' => t('Number of columns to display. Color order may look strange if this is altered.'),
            );
            break;
        case 'color_field_default_widget':
            $form['default_colors'] = array(
                '#type' => 'textarea',
                '#title' => t('Default colors'),
                '#default_value' => isset($settings['default_colors']) ? $settings['default_colors'] : '
#AC725E,#D06B64,#F83A22,#FA573C,#FF7537,#FFAD46
#42D692,#16A765,#7BD148,#B3DC6C,#FBE983
#92E1C0,#9FE1E7,#9FC6E7,#4986E7,#9A9CFF
#B99AFF,#C2C2C2,#CABDBF,#CCA6AC,#F691B2
#CD74E6,#A47AE2
        ',
                '#required' => TRUE,
                '#description' => t('Default colors for pre-selected color boxes'),
            );
            break;
        case 'color_field_spectrum_widget':
            $form['show_input'] = array(
                '#type' => 'checkbox',
                '#title' => t('Show Input'),
                '#default_value' => isset($settings['show_input']) ? $settings['show_input'] : FALSE,
                '#description' => t('Allow free form typing.'),
            );
            $form['show_palette'] = array(
                '#type' => 'checkbox',
                '#title' => t('Show Palette'),
                '#default_value' => isset($settings['show_palette']) ? $settings['show_palette'] : FALSE,
                '#description' => t('Show or hide the palette in the widget.'),
            );
            $form['palette'] = array(
                '#type' => 'textarea',
                '#title' => t('Color Palette'),
                '#default_value' => isset($settings['palette']) ? $settings['palette'] : '',
                '#description' => t('Selectable color palette to accompany the widget.'),
                '#states' => array(
                    'visible' => array(
                        ':input[name="field[settings][show_palette]"]' => array(
                            'checked' => TRUE,
                        ),
                    ),
                ),
            );
            $form['show_palette_only'] = array(
                '#type' => 'checkbox',
                '#title' => t('Show Palette Only'),
                '#default_value' => isset($settings['show_palette_only']) ? $settings['show_palette_only'] : FALSE,
                '#description' => t('Only show the palette in the widget and nothing else.'),
                '#states' => array(
                    'visible' => array(
                        ':input[name="field[settings][show_palette]"]' => array(
                            'checked' => TRUE,
                        ),
                    ),
                ),
            );
            $form['show_buttons'] = array(
                '#type' => 'checkbox',
                '#title' => t('Show Buttons'),
                '#default_value' => isset($settings['show_buttons']) ? $settings['show_buttons'] : FALSE,
                '#description' => t('Add Cancel/Confirm Button.'),
            );
            $form['allow_empty'] = array(
                '#type' => 'checkbox',
                '#title' => t('Allow Empty'),
                '#default_value' => isset($settings['allow_empty']) ? $settings['allow_empty'] : FALSE,
                '#description' => t('Allow empty value.'),
            );
            break;
    }
    return $form;
}