You are here

function search_autocomplete_suggestion_configure in Search Autocomplete 7.2

Same name and namespace in other branches
  1. 6.2 search_autocomplete.suggestion.configure.inc \search_autocomplete_suggestion_configure()

MENU CALLBACK: Define the page to configure a suggestion.

Return value

A rendered form

1 call to search_autocomplete_suggestion_configure()
search_autocomplete_suggestion_new in ./search_autocomplete.suggestion.configure.inc
MENU CALLBACK: Define the page to create a new suggestion.
1 string reference to 'search_autocomplete_suggestion_configure'
search_autocomplete_menu in ./search_autocomplete.admin.inc
Implementation of hook_menu(). Create an administration page to access admin form

File

./search_autocomplete.suggestion.configure.inc, line 30
Search Autocomplete Create a new suggestion to Search Autocomplete suggestion list.

Code

function search_autocomplete_suggestion_configure($form, &$form_state, $sid = -1) {

  // if no sid provided: get it
  if ($sid == -1) {
    $sid = arg(5);
  }

  // default values:
  $title = '';
  $dependancies = '';
  $prefix = '';
  $query = '';

  // if we got a sid: retrieve it from database for edition
  if ($sid > 0) {
    $result = db_select('search_autocomplete_suggestions', 's')
      ->fields('s')
      ->condition('sid', $sid)
      ->condition('sug_fid', 0)
      ->execute()
      ->fetchAllAssoc('sid');
    foreach ($result as $match) {
      $title = $match->sug_title;
      $dependancies = $match->sug_dependencies;
      $prefix = $match->sug_prefix;
      $query = $match->sug_query;
    }
  }

  // define the form:
  $form = array();

  /* ------------------------------------------------------------------ */
  $from['sid'] = array(
    '#type' => 'hidden',
    '#value' => $sid,
  );
  $form['title'] = array(
    '#title' => t('Title'),
    '#description' => 'Please enter a title for this suggestion',
    '#type' => 'textfield',
    '#default_value' => $title,
    '#maxlength' => 255,
    '#required' => TRUE,
  );
  $descr = t('Enter the list of machine name modules which your suggestion depend on (items should be separated with comma ",").') . '<br/>' . t('For example, if your suggestion adds taxonomy names, it depends on taxonomy module. Therefore, you should enter: <i>taxonomy</i>.');
  $form['dependancies'] = array(
    '#title' => t('Dependency module'),
    '#description' => $descr,
    '#type' => 'textfield',
    '#default_value' => $dependancies,
    '#maxlength' => 255,
    '#required' => FALSE,
  );
  $descr = t('This prefix will be added to any suggestion of that type during autocompletion.');
  $form['prefix'] = array(
    '#title' => t('Suggestion prefix'),
    '#description' => $descr,
    '#type' => 'textfield',
    '#default_value' => $prefix,
    '#maxlength' => 255,
    '#required' => FALSE,
  );
  $descr = t('The query to perform to retrieve suggestions.') . '<br />' . t('You can use the placeholders :like_word for the input sequence and :curr_lang for the current language.') . '<br />' . t('If you are not sure what to do, please look at examples in <a href="http://projects.axiomcafe.fr/search-autocomplete">the documentation</a> and/or ask for help');
  $form['query'] = array(
    '#title' => t('Query performed to get suggestion'),
    '#description' => $descr,
    '#type' => 'textfield',
    '#default_value' => $query,
    '#size' => 105,
    '#maxlength' => 255,
    '#required' => TRUE,
  );

  // submit buton
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#name' => 'submit',
  );
  if ($sid > 0) {

    // no need to delete a form that has not been created
    // delete buton
    $form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#name' => 'delete',
    );
  }

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