You are here

function ctools_context_term_settings_form in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 plugins/contexts/term.inc \ctools_context_term_settings_form()
1 string reference to 'ctools_context_term_settings_form'
term.inc in plugins/contexts/term.inc
Plugin to provide a term context

File

plugins/contexts/term.inc, line 58
Plugin to provide a term context

Code

function ctools_context_term_settings_form($conf) {
  if (empty($conf)) {
    $conf = array(
      'vid' => '',
      'tid' => '',
      'term' => '',
      'description' => '',
    );
  }
  $form['vid'] = array(
    '#title' => t('Vocabulary'),
    '#type' => 'select',
    '#options' => array(),
    '#description' => t('Select the vocabulary for this form.'),
    '#id' => 'ctools-select-vid',
    '#default_value' => $conf['vid'],
  );
  $description = '';
  if (!empty($conf['tid'])) {
    $info = db_fetch_object(db_query("SELECT * FROM {term_data} n WHERE n.tid = %d", $conf['tid']));
    if ($info) {
      $description = ' ' . t('Currently set to @term. Enter another term if you wish to change the term.', array(
        '@term' => $info->name,
      ));
    }
  }
  ctools_include('dependent');
  $options = array();

  // A note: Dependency works strangely on these forms as they have never been
  // updated to a more modern system so they are not individual forms of their
  // own like the content types.
  $form['taxonomy']['#tree'] = TRUE;
  foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
    $options[$vid] = $vocabulary->name;
    $form['taxonomy'][$vocabulary->vid] = array(
      '#type' => 'textfield',
      '#description' => t('Select a term from @vocabulary.', array(
        '@vocabulary' => $vocabulary->name,
      )) . $description,
      '#autocomplete_path' => 'taxonomy/autocomplete/' . $vocabulary->vid,
      '#process' => array(
        'ctools_dependent_process',
      ),
      '#dependency' => array(
        'ctools-select-vid' => array(
          $vocabulary->vid,
        ),
      ),
    );
  }
  $form['vid']['#options'] = $options;
  $form['tid'] = array(
    '#type' => 'value',
    '#value' => $conf['tid'],
  );
  $form['set_identifier'] = array(
    '#type' => 'checkbox',
    '#default_value' => FALSE,
    '#title' => t('Reset identifier to term title'),
    '#description' => t('If checked, the identifier will be reset to the term name of the selected term.'),
  );
  return $form;
}