You are here

function search_autocomplete_treelist_form in Search Autocomplete 6.4

Same name and namespace in other branches
  1. 6.2 search_autocomplete.form.treelist.inc \search_autocomplete_treelist_form()
  2. 7.4 search_autocomplete.form.treelist.inc \search_autocomplete_treelist_form()
  3. 7.2 search_autocomplete.form.treelist.inc \search_autocomplete_treelist_form()
  4. 7.3 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
Implementation of 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_state) {
  $base = "admin/settings/search_autocomplete";

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

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

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

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