You are here

function ctools_term_ctools_access_settings in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 plugins/access/term.inc \ctools_term_ctools_access_settings()

Settings form for the 'by term' access plugin

1 string reference to 'ctools_term_ctools_access_settings'
term.inc in plugins/access/term.inc
Plugin to provide access control based upon specific terms.

File

plugins/access/term.inc, line 27
Plugin to provide access control based upon specific terms.

Code

function ctools_term_ctools_access_settings(&$form, &$form_state, $conf) {

  // If no configuration was saved before, set some defaults.
  if (empty($conf)) {
    $conf = array(
      'vid' => 0,
    );
  }
  if (!isset($conf['vid'])) {
    $conf['vid'] = 0;
  }
  $form['settings']['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'],
    '#required' => TRUE,
  );
  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['settings']['#tree'] = TRUE;

  // Loop over each of the configured vocabularies.
  foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
    $options[$vid] = $vocabulary->name;
    $form['settings'][$vocabulary->vid] = array(
      '#title' => t('Terms'),
      '#description' => t('Select a term or terms from @vocabulary.', array(
        '@vocabulary' => $vocabulary->name,
      )),
      //. $description,
      '#process' => array(
        'ctools_dependent_process',
      ),
      '#dependency' => array(
        'ctools-select-vid' => array(
          $vocabulary->vid,
        ),
      ),
      '#default_value' => !empty($conf[$vid]) ? $conf[$vid] : '',
      '#multiple' => TRUE,
    );

    // If it's a tag, use an autocomplete.
    if ($vocabulary->tags) {
      $form['settings'][$vocabulary->vid]['#type'] = 'textfield';
      $form['settings'][$vocabulary->vid]['#autocomplete_path'] = 'taxonomy/autocomplete/' . $vocabulary->vid;
    }
    else {
      $terms = array();
      foreach (taxonomy_get_tree($vid) as $x => $term) {
        $terms[$term->tid] = str_repeat('-', $term->depth) . ($term->depth ? ' ' : '') . $term->name;
      }
      $form['settings'][$vocabulary->vid]['#type'] = 'select';
      $form['settings'][$vocabulary->vid]['#options'] = $terms;
      unset($terms);
    }
  }
  $form['settings']['vid']['#options'] = $options;
}