function rules_ui_form_data_selection_auto_completion
Autocomplete data selection results.
1 string reference to 'rules_ui_form_data_selection_auto_completion'
- RulesUIController::config_menu in ui/
ui.controller.inc - Generates menu items to manipulate rules configurations.
File
-
ui/
ui.forms.inc, line 651
Code
function rules_ui_form_data_selection_auto_completion($parameter, $form_build_id, $string = '') {
// Get the form and its state from the cache to get the currently edited
// or created element.
$form_state = form_state_defaults();
$form = form_get_cache($form_build_id, $form_state);
if (!isset($form_state['rules_element'])) {
return;
}
$element = $form_state['rules_element'];
$params = $element->pluginParameterInfo();
$matches = array();
if (isset($params[$parameter])) {
$parts = explode(':', $string);
// Remove the last part as it might be unfinished.
$last_part = array_pop($parts);
$selector = implode(':', $parts);
// Start with the partly given selector or from scratch.
$result = array();
if ($selector && ($wrapper = $element->applyDataSelector($selector))) {
$result = RulesData::matchingDataSelector($wrapper, $params[$parameter], $selector . ':', 0);
}
elseif (!$selector) {
$result = RulesData::matchingDataSelector($element->availableVariables(), $params[$parameter], '', 0);
}
foreach ($result as $selector => $info) {
// If we have an incomplete last part, take it into account now.
$attributes = array();
if (!$last_part || strpos($selector, $string) === 0) {
$attributes['class'][] = 'rules-dsac-item';
$attributes['title'] = isset($info['description']) ? strip_tags($info['description']) : '';
if ($selector[strlen($selector) - 1] == ':') {
$attributes['class'][] = 'rules-dsac-group';
$text = check_plain($selector) . '... (' . check_plain($info['label']) . ')';
}
else {
$text = check_plain($selector) . ' (' . check_plain($info['label']) . ')';
}
$matches[$selector] = "<div" . drupal_attributes($attributes) . ">{$text}</div>";
}
}
}
drupal_json_output($matches);
}