Elgg  Version master
entitypicker.php
Go to the documentation of this file.
1 <?php
20 $name = elgg_extract('name', $vars, 'entities', false);
21 
22 $guids = (array) elgg_extract('values', $vars, elgg_extract('value', $vars, []));
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 $params['view'] = 'json'; // force json viewtype
36 
38  'class' => elgg_extract_class($vars, ['elgg-entity-picker']),
39  'data-limit' => (int) elgg_extract('limit', $vars, 0),
40  'data-name' => $name,
41  'data-match-on' => elgg_extract('match_on', $vars, 'entities', false),
42  'data-handler' => elgg_http_add_url_query_elements(elgg_extract('handler', $vars, 'livesearch'), $params),
43 ];
44 
46  'type' => 'text',
47  'class' => [
48  'elgg-input-entity-picker',
49  ],
50  'size' => 30,
51  'id' => elgg_extract('id', $vars),
52  'placeholder' => elgg_extract('placeholder', $vars),
53 ]);
54 
55 $picker .= elgg_view('input/hidden', ['name' => $name]);
56 $picker .= elgg_extract('picker_extras', $vars, '');
57 
58 $item_view = elgg_extract('item_view', $vars, 'input/autocomplete/item');
59 $items = '';
60 foreach ($guids as $guid) {
61  $entity = get_entity((int) $guid);
62  if (!$entity instanceof \ElggEntity) {
63  continue;
64  }
65 
67  'entity' => $entity,
68  'input_name' => $name,
69  ]);
70 }
71 
72 $picker .= elgg_format_element('ul', ['class' => [
73  'elgg-list',
74  'elgg-entity-picker-list',
75 ]], $items);
76 
78 
79 ?>
80 <script>
81  import('input/entitypicker').then((entitypicker) => {
82  entitypicker.default.setup('.elgg-entity-picker[data-name="' + <?= json_encode($name) ?> + '"]');
83  });
84 </script>
$items
$name
Entity Picker.
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_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
$wrapper_options
$guids
$item_view
$entity
Definition: reset.php:8
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
elgg_http_add_url_query_elements(string $url, array $elements)
Sets elements in a URL&#39;s query string.
Definition: elgglib.php:181
$vars
Definition: theme.php:5
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
$picker
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_build_hmac($data)
Get an HMAC token builder/validator object.
Definition: actions.php:56
$params
$guid
Reset an ElggUpgrade.
Definition: reset.php:6