You are here

function faqfield_field_settings_form in FAQ Field 7

Implements hook_field_settings_form().

File

./faqfield.module, line 120
FAQ Field Provides a field for frequently asked questions.

Code

function faqfield_field_settings_form($field, $instance, $has_data) {
  $form = array();

  // Input for the count of rows for the answer field.
  $form['answer_widget'] = array(
    '#type' => 'select',
    '#title' => t('Answer widget'),
    '#default_value' => @$field['settings']['answer_widget'],
    '#options' => array(
      'textarea' => t('Textarea'),
      'text_format' => t('Formatable textarea'),
      'textfield' => t('Textfield'),
    ),
    '#required' => TRUE,
    '#description' => t('What form widget to use for answer input. Formatable textarea is needed for WYSIWYG editors.'),
  );

  // Get a list of formats that the current user has access to.
  $formats = filter_formats();
  foreach ($formats as $format) {
    $options[$format->format] = $format->name;
  }

  // Format select input for field settings.
  $form['format'] = array(
    '#type' => 'select',
    '#title' => t('Text format'),
    '#default_value' => @$field['settings']['format'],
    '#options' => $options,
    '#access' => count($formats) > 1,
    '#required' => TRUE,
    '#description' => t('Format to filter FAQ field answer content.'),
    '#states' => array(
      'invisible' => array(
        ':input[id="edit-field-settings-answer-widget"]' => array(
          'value' => 'text_format',
        ),
      ),
    ),
  );

  // We put more advanced settings into a collapsed fieldset.
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Input for custom title of questions.
  $form['advanced']['question_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Question input title'),
    '#default_value' => @$field['settings']['advanced']['question_title'],
    '#description' => t('Custom title of question input.'),
    '#maxlength' => 50,
    '#size' => 20,
  );

  // Input for the maximum length of questions.
  $form['advanced']['question_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Question length'),
    '#default_value' => @$field['settings']['advanced']['question_length'],
    '#description' => t('Maximum length of questions (Between 10-255).'),
    '#element_validate' => array(
      '_faqfield_element_validate_question_length',
    ),
    '#maxlength' => 3,
    '#size' => 5,
  );

  // Input for the count of rows for the answer field.
  $form['advanced']['question_rows'] = array(
    '#type' => 'select',
    '#title' => t('Question rows'),
    '#default_value' => @$field['settings']['advanced']['question_rows'],
    '#options' => array(
      1 => '1 (Fieldset)',
      2 => '2 (Textarea)',
      3 => '3 (Textarea)',
      4 => '4 (Textarea)',
    ),
    '#required' => TRUE,
    '#description' => t('Number of rows used for the question textfield/textarea.'),
  );

  // Input for custom title of answers.
  $form['advanced']['answer_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Answer input title'),
    '#default_value' => @$field['settings']['advanced']['answer_title'],
    '#description' => t('Custom title of answer input.'),
    '#maxlength' => 50,
    '#size' => 20,
  );

  // Input for the count of rows for the answer field.
  $form['advanced']['answer_rows'] = array(
    '#type' => 'select',
    '#title' => t('Answer rows'),
    '#default_value' => @$field['settings']['advanced']['answer_rows'],
    '#options' => array(
      1 => '1',
      2 => '2',
      3 => '3',
      4 => '4',
      5 => '5',
    ),
    '#required' => TRUE,
    '#description' => t('Number of rows used for the answer textarea.'),
    '#states' => array(
      'invisible' => array(
        ':input[id="edit-field-settings-answer-widget"]' => array(
          'value' => 'textfield',
        ),
      ),
    ),
  );
  return $form;
}