You are here

function select2widget_taxonomy_term_reference_widget_settings_form in Select2 Field Widget 7.2

Implements hook_field_widget_settings_form().

File

./select2widget.taxonomy.inc, line 49

Code

function select2widget_taxonomy_term_reference_widget_settings_form($field, $instance) {
  $widget = $instance['widget'];
  $settings = array_replace_recursive(field_info_widget_settings($widget['type']), $widget['settings']);
  $form = array();
  if ($widget['type'] == 'select2widgetajax') {
    $form['select2widgetajax'] = array(
      '#type' => 'fieldset',
      '#title' => t('Select2Widget settings'),
      '#tree' => TRUE,
    );
    $form['select2widgetajax']['placeholder'] = array(
      '#type' => 'textfield',
      '#title' => t('Placeholder text'),
      '#description' => t('Type a text for the placeholder'),
      '#default_value' => $settings['select2widgetajax']['placeholder'],
    );
    $form['select2widgetajax']['match_operator'] = array(
      '#type' => 'select',
      '#title' => t('Search matching'),
      '#default_value' => $settings['select2widgetajax']['match_operator'],
      '#options' => array(
        'STARTS_WITH' => t('Starts with'),
        'CONTAINS' => t('Contains'),
      ),
      '#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'),
    );
    $form['select2widgetajax']['match_limit'] = array(
      '#type' => 'textfield',
      '#title' => t('Limit number of matches'),
      '#description' => t('Use 0 for no limit. Performance may be affected for a large number of matches.'),
      '#default_value' => $settings['select2widgetajax']['match_limit'],
      '#element_validate' => array(
        'element_validate_integer',
      ),
      '#required' => TRUE,
    );
    $form['select2widgetajax']['separator'] = array(
      '#type' => 'textfield',
      '#size' => 1,
      '#title' => t('Separator'),
      '#description' => t('Separator used'),
      '#default_value' => $settings['select2widgetajax']['separator'],
      '#maxlength' => 1,
    );
    $form['select2widgetajax']['allow_new'] = array(
      '#type' => 'radios',
      '#title' => 'Allow new terms',
      '#options' => array(
        1 => t('Allow and insert new terms'),
        2 => t('Allow new terms and insert them into a separate vocabulary'),
        0 => t('Deny any new terms'),
      ),
      '#default_value' => $settings['select2widgetajax']['allow_new'],
      '#description' => t('If option 2 is selected, re-save this settings form and afterwards select a second vocabulary for new terms in the field settings.'),
    );
    $form['select2widgetajax']['set_level'] = array(
      '#type' => 'checkbox',
      '#title' => t('Taxonomy term level'),
      '#description' => t('Show only terms from last level'),
      '#default_value' => $settings['select2widgetajax']['set_level'],
    );
    $form['select2widgetajax']['min_char'] = array(
      '#type' => 'select',
      '#title' => t('Number of minimum character'),
      '#description' => t('How many character must be typed before results is displayed'),
      '#options' => range(0, 5),
      '#default_value' => $settings['select2widgetajax']['min_char'],
    );
  }
  return $form;
}