Elgg  Version 3.0
autocomplete.php
Go to the documentation of this file.
1 <?php
27 $vars['class'] = elgg_extract_class($vars, 'elgg-input-autocomplete');
28 
30  'value' => '',
31  'disabled' => false,
32 ];
33 
34 $vars = array_merge($defaults, $vars);
35 
36 $params = elgg_extract('options', $vars, []);
37 
38 if (!empty($params)) {
39  ksort($params);
40 
41  // We sign custom parameters, so that plugins can validate
42  // that the request is unaltered, if needed
44  $params['mac'] = $mac->getToken();
45 }
46 
47 $match_on = elgg_extract('match_on', $vars);
48 if (empty($match_on) || is_array($match_on)) {
49  elgg_log('"input/autocomplete" must specify a single "match_on" parameter');
50  return;
51 }
52 
53 if ($match_on == 'all') {
54  elgg_log('"input/autocomplete" no longer supports matching on "all" entities');
55  return;
56 }
57 
58 if ($match_on == 'friends') {
59  $match_on = 'users';
60  $params['friends_only'] = true;
61 }
62 
63 $params['match_on'] = $match_on;
64 unset($vars['match_on']);
65 
66 if (isset($vars['match_owner'])) {
67  $params['match_owner'] = elgg_extract('match_owner', $vars);
68  unset($vars['match_owner']);
69 }
70 
71 if (isset($vars['match_membership'])) {
72  $params['match_membership'] = elgg_extract('match_membership', $vars);
73  unset($vars['match_membership']);
74 }
75 
76 if (isset($vars['match_target'])) {
77  $target = elgg_extract('match_target', $vars);
78  if ($target instanceof ElggEntity) {
79  $target_guid = $target->guid;
80  } else {
81  $target_guid = (int) $target;
82  }
83  $params['match_membership'] = $target;
84  unset($vars['match_membership']);
85 }
86 
87 $params['view'] = 'json'; // force json viewtype
88 $handler = elgg_extract('handler', $vars, "livesearch/$match_on");
90 
91 $vars['type'] = 'text';
92 $vars['data-source'] = $source;
94 
95 // inline script in case loaded via ajax
96 ?>
97 <script>
98  require(['elgg/autocomplete'], function (autoc) {
99  autoc.init();
100  });
101 </script>
elgg_http_add_url_query_elements($url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:942
$source
elgg_normalize_url($url)
Definition: output.php:186
$defaults
$vars['class']
$target_guid
Definition: groups.php:22
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:1153
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:168
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:786
if(!($comment instanceof\ElggComment)||!$comment->canEdit()) $target
Definition: edit.php:17
elgg echo
Translates a string.
Definition: languages.js:43
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
$handler
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
$params
elgg_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:62
if(!empty($params)) $match_on