public static function SuggestionHelper::alterElement in Autocomplete Search Suggestions 7
Search the form recursivley for the field and add the autocomplete route.
Parameters
array $form: Part or all of a form render array.
string $field_name: The field name to search for.
string $level: The current recursion level.
Return value
array An array of ngrams keys.
1 call to SuggestionHelper::alterElement()
- suggestion_form_alter in ./
suggestion.module - Implements hook_form_alter().
File
- src/
SuggestionHelper.php, line 32 - Helper methods for the suggestion module.
Class
- SuggestionHelper
- Provides helper methods for suggestions.
Code
public static function alterElement(array &$form, $field_name, $level = 1) {
$suxs = FALSE;
$types = array(
'search',
'textfield',
);
if ($level > self::MAX_DEPTH) {
return FALSE;
}
foreach ($form as $key => &$element) {
if ($key == $field_name && !empty($form[$key]['#type']) && in_array($form[$key]['#type'], $types)) {
$form[$key]['#autocomplete_path'] = 'suggestion/autocomplete';
$suxs = TRUE;
}
elseif (is_array($element)) {
$suxs = self::alterElement($element, $field_name, $level + 1);
}
if ($suxs) {
break;
}
}
if ($suxs && $level == 1) {
$form['#submit'][] = 'suggestion_surfer_submit';
}
return $suxs;
}