You are here

function synonyms_field_widget_settings_form in Synonyms 7

Implements hook_field_widget_settings_form().

File

./synonyms.module, line 239
Provide synonyms feature for Drupal entities.

Code

function synonyms_field_widget_settings_form($field, $instance) {
  $widget = $instance['widget'];
  $settings = $widget['settings'] + field_info_widget_settings($widget['type']);
  $form = array();
  switch ($widget['type']) {
    case 'synonyms_autocomplete_taxonomy_term':
    case 'synonyms_autocomplete_entity':
      if ($widget['type'] == 'synonyms_autocomplete_taxonomy_term') {
        $form['auto_creation'] = array(
          '#type' => 'checkbox',
          '#title' => t('Allow auto-creation?'),
          '#description' => t('Whether users may create a new term by typing in a non-existing name into this field.'),
          '#default_value' => $settings['auto_creation'],
        );
      }
      $form['suggestion_size'] = array(
        '#type' => 'textfield',
        '#title' => t('Suggestions Size'),
        '#description' => t('Please, enter how many suggested entities to show in the autocomplete textfield.'),
        '#required' => TRUE,
        '#element_validate' => array(
          'element_validate_integer_positive',
        ),
        '#default_value' => $settings['suggestion_size'],
      );
      $form['suggest_only_unique'] = array(
        '#type' => 'checkbox',
        '#title' => t('Suggest only one entry per term'),
        '#description' => t('If you want to include only term name or a single synonym, suggesting a particular term, while disregarding all ongoing ones, please, tick this checkbox on.'),
        '#default_value' => $settings['suggest_only_unique'],
      );
      break;
    case 'synonyms_select_taxonomy_term':
      $form['sort'] = array(
        '#type' => 'radios',
        '#title' => t('Sort'),
        '#description' => t('Choose by what criterion the items within select should be sorted.'),
        '#options' => array(
          'weight' => t('As in taxonomy vocabulary (by weight)'),
          'name' => t('By name of terms and their synonyms'),
        ),
        '#default_value' => $settings['sort'],
      );
      break;
  }
  return $form;
}