Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
date.php
Go to the documentation of this file.
1 <?php
19 $vars['class'] = (array) elgg_extract('class', $vars, []);
20 $vars['class'][] = 'elgg-input-date';
21 
22 //@todo popup_calendar deprecated in 1.8. Remove in 2.0
23 $vars['class'][] = 'popup_calendar';
24 
25 $defaults = array(
26  'value' => '',
27  'disabled' => false,
28  'timestamp' => false,
29  'type' => 'text'
30 );
31 
32 $vars = array_merge($defaults, $vars);
33 
34 $timestamp = $vars['timestamp'];
35 unset($vars['timestamp']);
36 
37 if ($timestamp) {
38  if (!isset($vars['id'])) {
39  $vars['id'] = $vars['name'];
40  }
41  echo elgg_view('input/hidden', [
42  'name' => $vars['name'],
43  'value' => $vars['value'],
44  'rel' => $vars['id'],
45  ]);
46  $vars['class'][] = 'elgg-input-timestamp';
47  unset($vars['name']);
48 }
49 
50 // convert timestamps to text for display
51 if (is_numeric($vars['value'])) {
52  $vars['value'] = gmdate('Y-m-d', $vars['value']);
53 }
54 
55 $datepicker_options = elgg_extract('datepicker_options', $vars);
56 $vars['data-datepicker-opts'] = $datepicker_options ? json_encode($datepicker_options) : '';
57 unset($vars['datepicker_options']);
58 
59 echo elgg_format_element('input', $vars);
60 
61 if (isset($vars['id'])) {
62  $selector = "#{$vars['id']}";
63 } else {
64  $selector = ".elgg-input-date[name='{$vars['name']}']";
65 }
66 ?>
67 <script>
68  require(['input/date'], function (datepicker) {
69  datepicker.init(<?= json_encode($selector) ?>);
70  });
71 </script>
$timestamp
Definition: date.php:34
const datepicker
Definition: elgg.js.php:90
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:218
$vars['class']
Elgg date input Displays a text field with a popup date picker.
Definition: date.php:19
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:342
if($timestamp) if(is_numeric($vars['value'])) $datepicker_options
Definition: date.php:55
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:1310
$selector
Definition: filter.php:32
$defaults
Definition: date.php:25