You are here

function shs_field_widget_settings_form in Simple hierarchical select 7

Implements hook_field_widget_settings_form().

File

./shs.module, line 360
Provides an additional widget for term fields to create hierarchical selects.

Code

function shs_field_widget_settings_form($field, $instance) {
  $widget = $instance['widget'];
  $settings = $widget['settings'];
  $form = array();
  $form['shs'] = array(
    '#type' => 'fieldset',
    '#title' => 'Simple hierarchical select settings',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#tree' => TRUE,
  );
  if ($field['type'] != 'entityreference' || $field['type'] == 'entityreference' && !empty($field['settings']['handler_settings']['target_bundles']) && count($field['settings']['handler_settings']['target_bundles']) == 1) {
    $form['shs']['create_new_terms'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow creating new terms'),
      '#description' => t('If checked the user will be able to create new terms (permission to edit terms in this vocabulary must be set).'),
      '#default_value' => empty($settings['shs']['create_new_terms']) ? FALSE : $settings['shs']['create_new_terms'],
    );
    $form['shs']['create_new_levels'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow creating new levels'),
      '#description' => t('If checked the user will be able to create new children for items which do not have any children yet (permission to edit terms in this vocabulary must be set).'),
      '#default_value' => empty($settings['shs']['create_new_levels']) ? FALSE : $settings['shs']['create_new_levels'],
      '#states' => array(
        'visible' => array(
          ':input[name="instance[widget][settings][shs][create_new_terms]"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
  }
  $form['shs']['force_deepest'] = array(
    '#type' => 'checkbox',
    '#title' => t('Force selection of deepest level'),
    '#description' => t('If checked the user will be forced to select terms from the deepest level.'),
    '#default_value' => empty($settings['shs']['force_deepest']) ? FALSE : $settings['shs']['force_deepest'],
  );

  // "Chosen" integration.
  if (module_exists('chosen')) {
    $form['shs']['use_chosen'] = array(
      '#type' => 'select',
      '#title' => t('Output this field with !chosen', array(
        '!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'),
      )),
      '#description' => t('Select in which cases the element will use the !chosen module for the term selection of each level.', array(
        '!chosen' => l(t('Chosen'), 'http://drupal.org/project/chosen'),
      )),
      '#default_value' => empty($settings['shs']['use_chosen']) ? 'chosen' : $settings['shs']['use_chosen'],
      '#options' => array(
        'chosen' => t('let chosen decide'),
        'always' => t('always'),
        'never' => t('never'),
      ),
    );
  }
  return $form;
}