Elgg  Version 2.3
date.php
Go to the documentation of this file.
1 <?php
19 $vars['class'] = elgg_extract_class($vars, 'elgg-input-date');
20 
21 //@todo popup_calendar deprecated in 1.8. Remove in 2.0
22 $vars['class'][] = 'popup_calendar';
23 
24 $defaults = array(
25  'value' => '',
26  'disabled' => false,
27  'timestamp' => false,
28  'type' => 'text'
29 );
30 
31 $vars = array_merge($defaults, $vars);
32 
33 $timestamp = $vars['timestamp'];
34 unset($vars['timestamp']);
35 
36 if ($timestamp) {
37  if (!isset($vars['id'])) {
38  $vars['id'] = $vars['name'];
39  }
40  echo elgg_view('input/hidden', [
41  'name' => $vars['name'],
42  'value' => $vars['value'],
43  'rel' => $vars['id'],
44  ]);
45  $vars['class'][] = 'elgg-input-timestamp';
46  unset($vars['name']);
47 }
48 
49 // convert timestamps to text for display
50 if (is_numeric($vars['value'])) {
51  $vars['value'] = gmdate('Y-m-d', $vars['value']);
52 }
53 
54 $datepicker_options = elgg_extract('datepicker_options', $vars);
55 $vars['data-datepicker-opts'] = $datepicker_options ? json_encode($datepicker_options) : '';
56 unset($vars['datepicker_options']);
57 
59 
60 if (isset($vars['id'])) {
61  $selector = "#{$vars['id']}";
62 } else {
63  $selector = ".elgg-input-date[name='{$vars['name']}']";
64 }
65 ?>
66 <script>
67  require(['input/date'], function (datepicker) {
68  datepicker.init(<?= json_encode($selector) ?>);
69  });
70 </script>
$timestamp
Definition: date.php:33
elgg_extract_class(array $array, $existing=[])
Extract class names from an array with key "class", optionally merging into a preexisting set...
Definition: elgglib.php:1396
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:208
$vars['class']
Elgg date input Displays a text field with a popup date picker.
Definition: date.php:19
ui datepicker
Definition: admin.css.php:639
elgg echo
Translates a string.
Definition: languages.js:48
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:336
if($timestamp) if(is_numeric($vars['value'])) $datepicker_options
Definition: date.php:54
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:1375
$selector
Definition: filter.php:32
$defaults
Definition: date.php:24