public function SearchApiHighlight::configurationForm in Search API 7
Display a form for configuring this processor. Since forcing users to specify options for disabled processors makes no sense, none of the form elements should have the '#required' attribute set.
Return value
array A form array for configuring this processor, or FALSE if no configuration is possible.
Overrides SearchApiAbstractProcessor::configurationForm
File
- includes/
processor_highlight.inc, line 47 - Contains the SearchApiHighlight class.
Class
- SearchApiHighlight
- Processor for highlighting search results.
Code
public function configurationForm() {
$this->options += array(
'prefix' => '<strong>',
'suffix' => '</strong>',
'excerpt' => TRUE,
'excerpt_length' => 256,
'highlight' => 'always',
'highlight_partial' => FALSE,
'exclude_fields' => array(),
);
$form['prefix'] = array(
'#type' => 'textfield',
'#title' => t('Highlighting prefix'),
'#description' => t('Text/HTML that will be prepended to all occurrences of search keywords in highlighted text.'),
'#default_value' => $this->options['prefix'],
);
$form['suffix'] = array(
'#type' => 'textfield',
'#title' => t('Highlighting suffix'),
'#description' => t('Text/HTML that will be appended to all occurrences of search keywords in highlighted text.'),
'#default_value' => $this->options['suffix'],
);
$form['excerpt'] = array(
'#type' => 'checkbox',
'#title' => t('Create excerpt'),
'#description' => t('When enabled, an excerpt will be created for searches with keywords, containing all occurrences of keywords in a fulltext field.'),
'#default_value' => $this->options['excerpt'],
);
$form['excerpt_length'] = array(
'#type' => 'textfield',
'#title' => t('Excerpt length'),
'#description' => t('The requested length of the excerpt, in characters.'),
'#default_value' => $this->options['excerpt_length'],
'#element_validate' => array(
'element_validate_integer_positive',
),
'#states' => array(
'visible' => array(
'#edit-processors-search-api-highlighting-settings-excerpt' => array(
'checked' => TRUE,
),
),
),
);
// Exclude certain fulltext fields.
$fields = $this->index
->getFields();
$fulltext_fields = array();
foreach ($this->index
->getFulltextFields() as $field) {
if (isset($fields[$field])) {
$fulltext_fields[$field] = check_plain($fields[$field]['name'] . ' (' . $field . ')');
}
}
$form['exclude_fields'] = array(
'#type' => 'checkboxes',
'#title' => t('Exclude fields from excerpt'),
'#description' => t('Exclude certain fulltext fields from being displayed in the excerpt.'),
'#options' => $fulltext_fields,
'#default_value' => $this->options['exclude_fields'],
'#attributes' => array(
'class' => array(
'search-api-checkboxes-list',
),
),
);
$form['highlight'] = array(
'#type' => 'select',
'#title' => t('Highlight returned field data'),
'#description' => t('Select whether returned fields should be highlighted.'),
'#options' => array(
'always' => t('Always'),
'server' => t('If the server returns fields'),
'never' => t('Never'),
),
'#default_value' => $this->options['highlight'],
);
$form['highlight_partial'] = array(
'#type' => 'checkbox',
'#title' => t('Highlight partial matches'),
'#description' => t('When enabled, matches in parts of words will be highlighted as well.'),
'#default_value' => $this->options['highlight_partial'],
);
return $form;
}