You are here

function textformatter_field_formatter_settings_form in Text list formatter 7

Implements hook_field_formatter_Settings_form().

File

./textformatter.module, line 59
Provide a field formatter to render values as HTML or comma-separated lists.

Code

function textformatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $form = array();
  if ($display['type'] == 'textformatter_list') {
    $form['textformatter_type'] = array(
      '#title' => t("List type"),
      '#type' => 'select',
      '#options' => array(
        'ul' => t("Unordered HTML list (ul)"),
        'ol' => t("Ordered HTML list (ol)"),
        'comma' => t("Comma separated list"),
      ),
      '#default_value' => $settings['textformatter_type'],
      '#required' => TRUE,
    );
    $form['textformatter_comma_and'] = array(
      '#type' => 'checkbox',
      '#title' => t("Include 'and' before the last item"),
      '#default_value' => $settings['textformatter_comma_and'],
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_type]"]' => array(
            'value' => 'comma',
          ),
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_comma_override]"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );
    $form['textformatter_comma_full_stop'] = array(
      '#type' => 'checkbox',
      '#title' => t("Append comma separated list with '.'"),
      '#default_value' => $settings['textformatter_comma_full_stop'],
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_type]"]' => array(
            'value' => 'comma',
          ),
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_comma_override]"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );

    //Override Comma with custom separator.
    $form['textformatter_comma_override'] = array(
      '#type' => 'checkbox',
      '#title' => t("Override comma separator"),
      '#description' => t("Override the default comma separator with a custom separator string."),
      '#default_value' => $settings['textformatter_comma_override'],
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_type]"]' => array(
            'value' => 'comma',
          ),
        ),
      ),
    );
    $form['textformatter_separator_custom'] = array(
      '#type' => 'textfield',
      '#title' => t("Custom separator"),
      '#description' => t("Override default comma separator with a custom separator string. You must add your own spaces in this string if you want them. @example", array(
        '@example' => "E.g. ' + ', or ' => '",
      )),
      '#size' => 40,
      '#default_value' => $settings['textformatter_separator_custom'],
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_comma_override]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['textformatter_separator_custom_tag'] = array(
      '#type' => 'select',
      '#title' => t("separator HTML wrapper"),
      '#description' => t("An HTML tag to wrap the separator in."),
      '#options' => _textformatter_wrapper_options(),
      '#default_value' => $settings['textformatter_separator_custom_tag'],
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_comma_override]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['textformatter_separator_custom_class'] = array(
      '#title' => t("Separator classes"),
      '#type' => 'textfield',
      '#description' => t("A CSS class to use in the wrapper tag for the separator."),
      '#default_value' => $settings['textformatter_separator_custom_class'],
      '#element_validate' => array(
        '_textformatter_validate_class',
      ),
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_comma_override]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $form['textformatter_comma_tag'] = array(
      '#type' => 'select',
      '#title' => t("HTML wrapper"),
      '#description' => t("An HTML tag to wrap the list in. The CSS class below will be added to this tag."),
      '#options' => _textformatter_wrapper_options(),
      '#default_value' => $settings['textformatter_comma_tag'],
      '#states' => array(
        'visible' => array(
          ':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][textformatter_type]"]' => array(
            'value' => 'comma',
          ),
        ),
      ),
    );
    $form['textformatter_class'] = array(
      '#title' => t("List classes"),
      '#type' => 'textfield',
      '#size' => 40,
      '#description' => t("A CSS class to use in the markup for the field list."),
      '#default_value' => $settings['textformatter_class'],
      '#required' => FALSE,
      '#element_validate' => array(
        '_textformatter_validate_class',
      ),
    );
  }

  // Taxonomy term ref fields only.
  if ($field['type'] == 'taxonomy_term_reference') {
    $form['textformatter_term_plain'] = array(
      '#type' => 'checkbox',
      '#title' => t("Display taxonomy terms as plain text (Not term links)."),
      '#default_value' => $settings['textformatter_term_plain'],
    );
  }
  $context = array(
    'field' => $field,
    'instance' => $instance,
    'view_mode' => $view_mode,
  );
  drupal_alter('textformatter_field_formatter_settings_form', $form, $form_state, $context);
  return $form;
}