You are here

function search_autocomplete_treelist_form in Search Autocomplete 7.3

Same name and namespace in other branches
  1. 6.4 search_autocomplete.form.treelist.inc \search_autocomplete_treelist_form()
  2. 6.2 search_autocomplete.form.treelist.inc \search_autocomplete_treelist_form()
  3. 7.4 search_autocomplete.form.treelist.inc \search_autocomplete_treelist_form()
  4. 7.2 search_autocomplete.form.treelist.inc \search_autocomplete_treelist_form()

Menu Callback: create the form to list the searchforms

Return value

the form

1 string reference to 'search_autocomplete_treelist_form'
search_autocomplete_menu in ./search_autocomplete.admin.inc
Implements hook_menu(). Create an administration page to access admin form

File

./search_autocomplete.form.treelist.inc, line 20
Search Autocomplete Display the list of form to autocomplete and themis it as a draggable table.

Code

function search_autocomplete_treelist_form($form, &$form_state) {
  $base = "admin/config/search/search_autocomplete";

  // base URL for this module configurations
  $data = _search_autocomplete_get_items();

  // get all forms ordered as a tree;
  $form['my_items'] = array();
  $form['my_items']['#tree'] = TRUE;

  // for each items to render in the form
  foreach ($data as $values) {
    $fid = $values->fid;
    $title = $values->title;
    $weight = $values->weight;
    $enabled = $values->enabled;
    $parent_fid = $values->parent_fid;
    $translite = $values->translite;
    $form['my_items'][$fid] = array(
      // element for this item
      'title' => array(
        // -> human readeable title
        '#type' => 'item',
        '#title' => check_plain($title),
      ),
      'enabled' => array(
        // -> defines if the autocompletion is enabled for this item
        '#type' => 'checkbox',
        '#default_value' => $enabled,
      ),
      'operations' => array(
        'configure' => array(
          '#type' => 'item',
          '#title' => filter_xss(l(t('configure'), "{$base}/{$fid}/configure")),
        ),
        'delete' => array(
          '#type' => 'item',
          '#title' => filter_xss(l(t('delete'), "{$base}/{$parent_fid}/delete/{$fid}")),
        ),
      ),
      'weight' => array(
        // -> weight of the item in hierarchy
        '#type' => 'weight',
        '#delta' => count($data),
        '#default_value' => $weight,
      ),
      'fid' => array(
        // -> the individual id if the item
        '#type' => 'hidden',
        '#value' => $fid,
      ),
      'parent_fid' => array(
        // -> id of the parent item in hierarchy
        '#type' => 'textfield',
        '#default_value' => $parent_fid,
      ),
      '#depth' => $values->depth,
    );
  }

  // translite option
  $title = t('Translite special characters.') . ' (' . t('Requires <a href="https://drupal.org/project/transliteration">Transliteration</a> module.') . ' :  ';
  $title .= module_exists('transliteration') ? '<b>' . t('Installed') . '</b>' : '<b>' . t('Not installed') . '</b>';
  $title .= ')';
  $form['translite'] = array(
    '#type' => 'checkbox',
    '#title' => $title,
    '#description' => t('If enabled, the user will be suggested with all special characters suggestions when using standard characters. In other word, when entering "foo", suggestions may contain also "f&oacute;&ocirc;bar", "fo&otilde;bar", ...'),
    '#disabled' => module_exists('transliteration') ? FALSE : TRUE,
    '#default_value' => $translite,
  );

  // submit buton
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}