You are here

function hierarchical_select_common_config_form in Hierarchical Select 5.3

Same name and namespace in other branches
  1. 6.3 includes/common.inc \hierarchical_select_common_config_form()
  2. 7.3 includes/common.inc \hierarchical_select_common_config_form()

Form definition of the hierarchical_select_common_config_form form.

4 calls to hierarchical_select_common_config_form()
hs_content_taxonomy_config_form in modules/hs_content_taxonomy.module
Form definition; configuration form for Hierarchical Select as the widget for a content_taxonomy field.
hs_content_taxonomy_views_config_form in modules/hs_content_taxonomy_views.module
Form definition; configuration form for Hierarchical Select as the widget for a Taxonomy exposed filter.
hs_taxonomy_form_alter in modules/hs_taxonomy.module
Implementation of hook_form_alter().
hs_taxonomy_views_config_form in modules/hs_taxonomy_views.module
Form definition; configuration form for Hierarchical Select as the widget for a Taxonomy exposed filter.

File

includes/common.inc, line 69
Functions used by more than one Hierarchical Select implementation.

Code

function hierarchical_select_common_config_form($module, $params, $config_id, $defaults_override, $strings, $max_hierarchy_depth, $preview_is_required) {
  static $js_added;
  if (!isset($js_added)) {
    $js_added = TRUE;
    drupal_add_css(drupal_get_path('module', 'hierarchical_select') . '/includes/common_config_form.css', 'module');
    drupal_add_js(drupal_get_path('module', 'hierarchical_select') . '/includes/common_config_form.js', 'module', 'header');
    drupal_add_js(array(
      'HierarchicalSelect' => array(
        'configForm' => array(
          $config_id,
        ),
      ),
    ), 'setting');
  }
  $config = hierarchical_select_common_config_get($config_id, $defaults_override);
  $args = array(
    '!item' => $strings['item'],
    '!items' => $strings['items'],
    '!entity' => $strings['entity'],
    '!entities' => $strings['entities'],
    '!hierarchy' => $strings['hierarchy'],
    '!hierarchies' => $strings['hierarchies'],
  );
  $form = array(
    '#tree' => TRUE,
    '#type' => 'fieldset',
    '#title' => t('Hierarchical Select configuration'),
    '#attributes' => array(
      'class' => 'hierarchical-select-config-form',
      'id' => 'hierarchical-select-config-form-' . $config_id,
    ),
  );
  $form['config_id'] = array(
    '#type' => 'value',
    '#value' => $config_id,
  );

  // TODO: really make this a *live* preview, i.e. refresh the preview on each
  // change in the form. This cannot be done easily in Drupal 5, so let's do
  // so in Drupal 6. See cfg.livePreview in common_config_form.js.
  $form['live_preview'] = array(
    '#type' => 'fieldset',
    '#title' => t('Preview'),
    '#description' => t('This is what the Hierarchical Select will look like with your current configuration.'),
    '#collapsible' => FALSE,
    '#attributes' => array(
      'class' => 'live-preview',
    ),
  );
  $form['live_preview']['example'] = array(
    '#type' => 'hierarchical_select',
    '#required' => $preview_is_required,
    '#title' => t('Preview'),
    '#description' => t('The description.'),
    // Skip all validation.
    '#validated' => TRUE,
  );
  hierarchical_select_common_config_apply($form['live_preview']['example'], $config_id, array_merge($defaults_override, array(
    'module' => $module,
    'params' => $params,
  )));
  $form['save_lineage'] = array(
    '#type' => 'radios',
    '#title' => t('Save lineage'),
    '#options' => array(
      1 => t('Save !item lineage', $args),
      0 => t('Save only the deepest !item', $args),
    ),
    '#default_value' => $config['save_lineage'],
    '#description' => t('Saving the !item lineage means saving the <em>the !item itself and all
      its ancestors</em>.', $args),
  );
  $form['enforce_deepest'] = array(
    '#type' => 'radios',
    '#title' => t('Level choice'),
    '#options' => array(
      1 => t('Force the user to choose a !item from a <em>deepest level</em>', $args),
      0 => t('Allow the user to choose a !item from <em>any level</em>', $args),
    ),
    '#default_value' => $config['enforce_deepest'],
    '#description' => t('This setting determines from which level in the !hierarchy tree a
      user can select a !item.', $args),
    '#attributes' => array(
      'class' => 'enforce-deepest',
    ),
  );
  if (module_hook($module, 'hierarchical_select_entity_count')) {
    $form['entity_count'] = array(
      '#type' => 'radios',
      '#title' => t('Display the !entity count', $args),
      '#description' => t('When enabled, the user will see the number of !entities that match
        the current !item listed between brackets.', $args),
      '#options' => array(
        0 => t('Disabled'),
        1 => t('Enabled'),
      ),
      '#default_value' => $config['entity_count'],
      '#attributes' => array(
        'class' => 'entity-count',
      ),
    );
    $form['require_entity'] = array(
      '#type' => 'radios',
      '#title' => t('Require associated !entity', $args),
      '#description' => t('When enabled, !items will only be displayed when they are associated
        with at least one !entity, or if one of their child !items are
        associated with at least one !entity.', $args),
      '#options' => array(
        0 => t('Disabled'),
        1 => t('Enabled'),
      ),
      '#default_value' => $config['require_entity'],
      '#attributes' => array(
        'class' => 'require-entity',
      ),
    );
  }
  $form['resizable'] = array(
    '#type' => 'radios',
    '#title' => t('Resizable'),
    '#description' => t("When enabled, a handle appears below the Hierarchical Select to allow\n      the user to dynamically resize it. Double clicking will toggle between\n      the smallest and a sane 'big size'."),
    '#options' => array(
      0 => t('Disabled'),
      1 => t('Enabled'),
    ),
    '#default_value' => $config['resizable'],
    '#attributes' => array(
      'class' => 'resizable',
    ),
  );
  $form['level_labels'] = array(
    '#tree' => TRUE,
    '#type' => 'fieldset',
    '#title' => t('Level labels'),
    '#description' => t('When the user is allowed to choose a !item from any level in the
      <em>Level choice</em> setting, you can enter a label for <em>each</em>
      level.<br />
      However, when the user is only allowed to choose a !item from the
      deepest level, then you can only enter a label for the <em>root</em>
      level.', $args),
    '#collapsible' => TRUE,
  );
  $form['level_labels']['status'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable level labels'),
    '#default_value' => $config['level_labels']['status'],
    '#attributes' => array(
      'class' => 'level-labels-status',
    ),
  );
  for ($depth = 0; $depth <= $max_hierarchy_depth; $depth++) {
    $form['level_labels']['labels'][$depth] = array(
      '#type' => 'textfield',
      '#size' => 20,
      '#maxlength' => 255,
      '#default_value' => $config['level_labels']['labels'][$depth],
      '#attributes' => array(
        'class' => 'level-label',
      ),
    );
  }
  $form['level_labels']['#theme'] = 'hierarchical_select_common_config_form_level_labels';
  $form['level_labels']['#strings'] = $strings;
  $form['dropbox'] = array(
    '#type' => 'fieldset',
    '#title' => t('Dropbox settings'),
    '#description' => t('The dropbox allows the user to <strong>make multiple selections</strong>.'),
    '#collapsible' => TRUE,
  );
  $form['dropbox']['status'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable the dropbox'),
    '#default_value' => $config['dropbox']['status'],
    '#attributes' => array(
      'class' => 'dropbox-status',
    ),
  );
  $form['dropbox']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#description' => t('The title you enter here appears above the dropbox.'),
    '#size' => 20,
    '#maxlength' => 255,
    '#default_value' => $config['dropbox']['title'],
    '#attributes' => array(
      'class' => 'dropbox-title',
    ),
  );
  $form['dropbox']['limit'] = array(
    '#type' => 'textfield',
    '#title' => t('Limit the number of selections'),
    '#description' => t('Limits the number of selections that can be added to the dropbox.
      0 means no limit.
      <br />
      Note: the "Save !item lineage" option has no effect on this, even if
      a lineage consists of 3 !items, this will count as only one selection
      in the dropbox.', $args),
    '#size' => 5,
    '#maxlength' => 5,
    '#default_value' => $config['dropbox']['limit'],
    '#attributes' => array(
      'class' => 'dropbox-limit',
    ),
  );
  $form['dropbox']['reset_hs'] = array(
    '#type' => 'radios',
    '#title' => t('Reset selection of hierarchical select'),
    '#description' => t('This setting determines what will happen to the hierarchical select
      when the user has added a selection to the dropbox.'),
    '#options' => array(
      0 => t('Disabled'),
      1 => t('Enabled'),
    ),
    '#default_value' => $config['dropbox']['reset_hs'],
    '#attributes' => array(
      'class' => 'dropbox-reset-hs',
    ),
  );
  if (module_hook($module, 'hierarchical_select_create_item')) {
    $form['editability'] = array(
      '#type' => 'fieldset',
      '#title' => t('Editability settings'),
      '#description' => t('You can allow the user to <strong>add new !items to this
        !hierarchy</strong> <em>through</em> Hierarchical Select.', $args),
      '#collapsible' => TRUE,
    );
    $form['editability']['status'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow creation of new !items', $args),
      '#options' => array(
        0 => t('Disabled'),
        1 => t('Enabled'),
      ),
      '#default_value' => $config['editability']['status'],
      '#attributes' => array(
        'class' => 'editability-status',
      ),
    );
    for ($depth = 0; $depth <= $max_hierarchy_depth; $depth++) {
      $form['editability']['item_types'][$depth] = array(
        '#type' => 'textfield',
        '#size' => 20,
        '#maxlength' => 255,
        '#default_value' => $config['editability']['item_types'][$depth],
        '#attributes' => array(
          'class' => 'editability-item-type',
        ),
      );
    }
    for ($depth = 0; $depth <= $max_hierarchy_depth; $depth++) {
      $form['editability']['allowed_levels'][$depth] = array(
        '#type' => 'checkbox',
        '#default_value' => isset($config['editability']['allowed_levels'][$depth]) ? $config['editability']['allowed_levels'][$depth] : 1,
      );
    }
    $form['editability']['allow_new_levels'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow creation of new levels'),
      '#default_value' => $config['editability']['allow_new_levels'],
      '#description' => t('Allow the user to create child !items for !items that do not yet have
        children.', $args),
      '#attributes' => array(
        'class' => 'editability-allow-new-levels',
      ),
    );
    $form['editability']['max_levels'] = array(
      '#type' => 'select',
      '#title' => t('Maximum number of levels allowed'),
      '#options' => array(
        0 => t('0 (no limit)'),
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
      ),
      '#default_value' => $config['editability']['max_levels'],
      '#description' => t('When the user is allowed to create new levels, this option prevents
        the user from creating extremely deep !hierarchies.', $args),
      '#attributes' => array(
        'class' => 'editability-max-levels',
      ),
    );
    $form['editability']['#theme'] = 'hierarchical_select_common_config_form_editability';
    $form['editability']['#strings'] = $strings;
  }
  return $form;
}