Elgg  Version 3.0
date.php
Go to the documentation of this file.
1 <?php
20 $vars['class'] = elgg_extract_class($vars, 'elgg-input-date');
21 
23  'value' => '',
24  'disabled' => false,
25  'timestamp' => false,
26  'autocomplete' => 'off',
27  'type' => 'text',
28  'format' => elgg_get_config('date_format', elgg_echo('input:date_format')),
29 ];
30 
31 $vars = array_merge($defaults, $vars);
32 
33 $timestamp = elgg_extract('timestamp', $vars);
34 unset($vars['timestamp']);
35 
36 $format = elgg_extract('format', $vars, $defaults['format'], false);
37 unset($vars['format']);
38 
41 
44 
45 if ($value) {
46  try {
48 
49  $value_date = $dt->format($format);
50  $value_timestamp = $dt->getTimestamp();
51  } catch (DataFormatException $ex) {
52  // $value is not a valid datetime, using blank value
53  }
54 }
55 
56 if ($timestamp) {
57  if (!isset($vars['id'])) {
58  $vars['id'] = $name;
59  }
60  echo elgg_view('input/hidden', [
61  'name' => $name,
62  'value' => $value_timestamp,
63  'rel' => elgg_extract('id', $vars),
64  ]);
65  $vars['class'][] = 'elgg-input-timestamp';
66  unset($vars['name']);
67 }
68 
69 $vars['value'] = $value_date;
70 
71 $datepicker_options = (array) elgg_extract('datepicker_options', $vars, []);
72 unset($vars['datepicker_options']);
73 
74 if (empty($datepicker_options['dateFormat'])) {
75  $datepicker_options['dateFormat'] = elgg_get_config('date_format_datepicker', elgg_echo('input:date_format:datepicker'));
76 }
77 
78 $vars['data-datepicker-opts'] = $datepicker_options ? json_encode($datepicker_options) : '';
79 
81 
82 if (isset($vars['id'])) {
83  $selector = "#{$vars['id']}";
84 } else {
85  $selector = ".elgg-input-date[name='{$name}']";
86 }
87 ?>
88 <script>
89  require(['input/date'], function (datepicker) {
90  datepicker.init(<?= json_encode($selector) ?>);
91  });
92 </script>
$format
Definition: date.php:36
$timestamp
Definition: date.php:33
$value
Definition: date.php:40
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:1153
$name
Definition: date.php:39
$vars['class']
Elgg date input Displays a text field with a popup date picker.
Definition: date.php:20
$dt
Definition: time.php:69
$datepicker_options
Definition: date.php:71
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:168
elgg echo
Translates a string.
Definition: languages.js:43
elgg require
Throw an error if the required package isn&#39;t present.
Definition: elgglib.js:164
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:1131
static normalizeTime($time)
Returns DateTime object based on time representation.
Definition: Values.php:76
$value_timestamp
Definition: date.php:43
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:246
$value_date
Definition: date.php:42
$defaults
Definition: date.php:22
elgg_get_config($name, $default=null)
Get an Elgg configuration value.