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 
25  'value' => '',
26  'disabled' => false,
27 ];
28 
29 $vars = array_merge($defaults, $vars);
30 
31 $params = elgg_extract('options', $vars, []);
32 
33 if (!empty($params)) {
34  ksort($params);
35 
36  // We sign custom parameters, so that plugins can validate
37  // that the request is unaltered, if needed
39  $params['mac'] = $mac->getToken();
40 }
41 
42 $match_on = elgg_extract('match_on', $vars);
43 if (empty($match_on) || !is_string($match_on)) {
44  return;
45 }
46 
47 if ($match_on == 'friends') {
48  $match_on = 'users';
49  $params['friends_only'] = true;
50 }
51 
52 $params['match_on'] = $match_on;
53 unset($vars['match_on']);
54 
55 if (isset($vars['match_owner'])) {
56  $params['match_owner'] = elgg_extract('match_owner', $vars);
57  unset($vars['match_owner']);
58 }
59 
60 if (isset($vars['match_membership'])) {
61  $params['match_membership'] = elgg_extract('match_membership', $vars);
62  unset($vars['match_membership']);
63 }
64 
65 if (isset($vars['match_target'])) {
66  $target = elgg_extract('match_target', $vars);
67  if ($target instanceof ElggEntity) {
68  $target_guid = $target->guid;
69  } else {
70  $target_guid = (int) $target;
71  }
72 
73  $params['match_target'] = $target_guid;
74  unset($vars['match_target']);
75 }
76 
77 $params['view'] = 'json'; // force json viewtype
78 $handler = elgg_extract('handler', $vars, "livesearch/$match_on");
80 
81 $vars['type'] = 'text';
82 $vars['data-source'] = $source;
83 echo elgg_format_element('input', $vars);
84 
85 // inline script in case loaded via ajax
86 ?>
87 <script>
88  require(['elgg/autocomplete'], function (autoc) {
89  autoc.init();
90  });
91 </script>
if(!$comment instanceof\ElggComment||!$comment->canEdit()) $target
Definition: edit.php:13
$source
$defaults
$vars['class']
Displays an autocomplete text input.
$target_guid
Definition: groups.php:25
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:276
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
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:130
elgg_normalize_url(string $url)
Definition: output.php:148
elgg_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:54
if(!empty($params)) $match_on