Elgg  Version master
tags.php
Go to the documentation of this file.
1 <?php
12 $vars['class'] = elgg_extract_class($vars, 'elgg-input-tags');
13 
15  'value' => '',
16  'autocapitalize' => 'off',
17  'type' => 'text',
18 ];
19 
20 if (isset($vars['entity'])) {
21  $defaults['value'] = elgg_extract('entity', $vars)->tags;
22  unset($vars['entity']);
23 }
24 
25 $vars = array_merge($defaults, $vars);
26 
27 // set tagify options
28 if (!isset($vars['data-tagify-opts']) && isset($vars['tagify_options'])) {
29  $vars['data-tagify-opts'] = json_encode($vars['tagify_options']);
30 }
31 
32 unset($vars['tagify_options']);
33 
34 if (is_array($vars['value'])) {
35  $tags = [];
36 
37  foreach ($vars['value'] as $tag) {
38  if (is_string($tag)) {
39  $tags[] = $tag;
40  } else {
41  $tags[] = $tag->value;
42  }
43  }
44 
45  $vars['value'] = implode(', ', $tags);
46 }
47 
48 echo elgg_format_element('input', $vars);
49 
50 if (isset($vars['id'])) {
51  $selector = "#{$vars['id']}";
52 } else {
53  $name = elgg_extract('name', $vars);
54  $selector = ".elgg-input-tags[name='{$name}']";
55 }
56 
57 ?>
58 <script>
59  import('input/tags').then((tags) => {
60  tags.default.init(<?= json_encode($selector) ?>);
61  });
62 </script>
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$defaults
Definition: tags.php:14
if(!is_string($title)||$title=== '') $tag
Definition: title.php:15
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
$selector
Definition: tags.php:54
$vars['class']
Elgg tag input Displays a tag input field.
Definition: tags.php:12
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
$tags
Output object tags.
Definition: tags.php:9