Elgg  Version master
autocomplete.php
Go to the documentation of this file.
1 <?php
22 $vars['class'] = elgg_extract_class($vars, 'elgg-input-autocomplete');
23 
24 $params = elgg_extract('options', $vars, []);
25 
26 if (!empty($params)) {
27  ksort($params);
28 
29  // We sign custom parameters, so that plugins can validate
30  // that the request is unaltered, if needed
32  $params['mac'] = $mac->getToken();
33 }
34 
35 $match_on = elgg_extract('match_on', $vars);
36 if (empty($match_on) || !is_string($match_on)) {
37  return;
38 }
39 
40 if ($match_on == 'friends') {
41  $match_on = 'users';
42  $params['friends_only'] = true;
43 }
44 
45 $params['match_on'] = $match_on;
46 unset($vars['match_on']);
47 
48 if (isset($vars['match_owner'])) {
49  $params['match_owner'] = elgg_extract('match_owner', $vars);
50  unset($vars['match_owner']);
51 }
52 
53 if (isset($vars['match_membership'])) {
54  $params['match_membership'] = elgg_extract('match_membership', $vars);
55  unset($vars['match_membership']);
56 }
57 
58 if (isset($vars['match_target'])) {
59  $target = elgg_extract('match_target', $vars);
60  if ($target instanceof ElggEntity) {
61  $target_guid = $target->guid;
62  } else {
63  $target_guid = (int) $target;
64  }
65 
66  $params['match_target'] = $target_guid;
67  unset($vars['match_target']);
68 }
69 
70 $params['view'] = 'json'; // force json viewtype
71 $handler = elgg_extract('handler', $vars, "livesearch/$match_on");
73 
74 $vars['type'] = 'text';
75 $vars['data-source'] = $source;
76 echo elgg_format_element('input', $vars);
77 
78 // inline script in case loaded via ajax
79 ?>
80 <script>
81  import('elgg/autocomplete').then((autoc) => {
82  autoc.default.init();
83  });
84 </script>
$source
$vars['class']
Displays an autocomplete text input.
$target_guid
Definition: groups.php:21
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
$target
Definition: create.php:17
elgg_http_add_url_query_elements(string $url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:181
$handler
$params
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
elgg_extract_class(array $array, array|string $existing=[], string $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:277
elgg_normalize_url(string $url)
Definition: output.php:163
elgg_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:56
if(!empty($params)) $match_on