/**
  * Overrides LinkitSearchPlugin::buildSettingsForm().
  */
 function buildSettingsForm()
 {
     $form = parent::buildSettingsForm();
     // The entity plugin uses the entity name for the #token_types, but terms
     // is a special case, its name is "Taxonomy_term" and the tokens are defined
     // (in the taxonomy module) with just "term".
     // If the token modules is installed.
     if (isset($form[$this->plugin['name']]['token_help']['help']['#token_types'])) {
         $form[$this->plugin['name']]['token_help']['help']['#token_types'] = array('term');
     } else {
         // Get supported tokens for the term entity type.
         $tokens = linkit_extract_tokens('term');
         $form[$this->plugin['name']]['result_description']['#description'] = t('Available tokens: %tokens.', array('%tokens' => implode(', ', $tokens)));
     }
     return $form;
 }
 /**
  * Generate a settings form for this handler.
  * Uses the standard Drupal FAPI.
  * The element will be attached to the "data" key.
  *
  * @return
  *   An array containing any custom form elements to be displayed in the
  *   profile editing form
  */
 function buildSettingsForm()
 {
     $form[$this->plugin['name']] = array('#type' => 'fieldset', '#title' => t('!type plugin settings', array('!type' => $this->ui_title())), '#collapsible' => TRUE, '#collapsed' => TRUE, '#tree' => TRUE, '#states' => array('invisible' => array('input[name="data[plugins][' . $this->plugin['name'] . '][enabled]"]' => array('checked' => FALSE))));
     // Get supported tokens for the entity type.
     $tokens = linkit_extract_tokens($this->plugin['entity_type']);
     // A short description in within the search result for each row.
     $form[$this->plugin['name']]['result_description'] = array('#title' => t('Result format'), '#type' => 'textfield', '#default_value' => isset($this->conf['result_description']) ? $this->conf['result_description'] : '', '#size' => 120, '#maxlength' => 255, '#description' => t('Available tokens: %tokens.', array('%tokens' => implode(', ', $tokens))));
     // If the token module is installed, lets make some fancy stuff with the
     // token chooser.
     if (module_exists('token')) {
         // Unset the regular description if token module is enabled.
         unset($form[$this->plugin['name']]['result_description']['#description']);
         // Display the user documentation of placeholders.
         $form[$this->plugin['name']]['token_help'] = array('#title' => t('Replacement patterns'), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE);
         $form[$this->plugin['name']]['token_help']['help'] = array('#theme' => 'token_tree', '#token_types' => array($this->plugin['entity_type']));
     }
     // If there is bundles, add some default settings features.
     if (count($this->entity_info['bundles']) > 1) {
         $bundles = array();
         // Extract the bundle data.
         foreach ($this->entity_info['bundles'] as $bundle_name => $bundle) {
             $bundles[$bundle_name] = $bundle['label'];
         }
         // Filter the possible bundles to use if the entity has bundles.
         $form[$this->plugin['name']]['bundles'] = array('#title' => t('Type filter'), '#type' => 'checkboxes', '#options' => $bundles, '#default_value' => isset($this->conf['bundles']) ? $this->conf['bundles'] : array(), '#description' => t('If left blank, all types will appear in autocomplete results.'));
         // Group the results with this bundle.
         $form[$this->plugin['name']]['group_by_bundle'] = array('#title' => t('Group by bundle'), '#type' => 'checkbox', '#default_value' => isset($this->conf['group_by_bundle']) ? $this->conf['group_by_bundle'] : 0);
     }
     // Reverse menu trail.
     $form[$this->plugin['name']]['reverse_menu_trail'] = array('#title' => t('Add reverse menu trail to description'), '#type' => 'checkbox', '#default_value' => isset($this->conf['reverse_menu_trail']) ? $this->conf['reverse_menu_trail'] : 0, '#description' => t('If the result has a menu item its menu trail will be added in reverse in the description.'));
     return $form;
 }