Elgg  Version 4.3
tags.php
Go to the documentation of this file.
1 <?php
13 $vars['class'] = elgg_extract_class($vars, 'elgg-input-tags');
14 
16  'value' => '',
17  'disabled' => false,
18  'autocapitalize' => 'off',
19  'type' => 'text',
20 ];
21 
22 if (isset($vars['entity'])) {
23  $defaults['value'] = elgg_extract('entity', $vars)->tags;
24  unset($vars['entity']);
25 }
26 
27 $vars = array_merge($defaults, $vars);
28 
29 // set tagify options
30 if (!isset($vars['data-tagify-opts']) && isset($vars['tagify_options'])) {
31  $vars['data-tagify-opts'] = json_encode($vars['tagify_options']);
32 }
33 unset($vars['tagify_options']);
34 
35 if (is_array($vars['value'])) {
36  $tags = [];
37 
38  foreach ($vars['value'] as $tag) {
39  if (is_string($tag)) {
40  $tags[] = $tag;
41  } else {
42  $tags[] = $tag->value;
43  }
44  }
45 
46  $vars['value'] = implode(", ", $tags);
47 }
48 
50 
51 if (isset($vars['id'])) {
52  $selector = "#{$vars['id']}";
53 } else {
54  $name = elgg_extract('name', $vars);
55  $selector = ".elgg-input-tags[name='{$name}']";
56 }
57 
58 ?>
59 <script>
60  require(['input/tags'], function (tags) {
61  tags.init(<?= json_encode($selector) ?>);
62  });
63 </script>
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$defaults
Definition: tags.php:15
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:569
$selector
Definition: tags.php:55
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:135
$tag
Definition: title.php:21
$vars['class']
Elgg tag input Displays a tag input field.
Definition: tags.php:13
elgg require
Throw an error if the required package isn&#39;t present.
Definition: deprecated.js:176
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:547
elgg echo
Translates a string.
Definition: deprecated.js:530
$tags
Output object tags.
Definition: tags.php:9