*
* @return HTML_QuickForm_Element
* Could be an error object
+ *
+ * @throws \CRM_Core_Exception
*/
public function &add(
$type, $name, $label = '',
unset($attributes['multiple']);
$extra = NULL;
}
+
// @see https://docs.civicrm.org/dev/en/latest/framework/ui/#date-picker
- if ($type == 'datepicker') {
+ if ($type === 'datepicker') {
+ $attributes = $attributes ?: [];
+ if (!empty($attributes['format'])) {
+ $dateAttributes = CRM_Core_SelectValues::date($attributes['format'], NULL, NULL, NULL, 'Input');
+ if (empty($extra['minDate']) && !empty($dateAttributes['minYear'])) {
+ $extra['minDate'] = $dateAttributes['minYear'] . '-01-01';
+ }
+ if (empty($extra['maxDate']) && !empty($dateAttributes['minYear'])) {
+ $extra['maxDate'] = $dateAttributes['maxYear'] . '-12-31';
+ }
+ }
// Support minDate/maxDate properties
if (isset($extra['minDate'])) {
$extra['minDate'] = date('Y-m-d', strtotime($extra['minDate']));
$extra['maxDate'] = date('Y-m-d', strtotime($extra['maxDate']));
}
- $attributes = ($attributes ? $attributes : []);
$attributes['data-crm-datepicker'] = json_encode((array) $extra);
if (!empty($attributes['aria-label']) || $label) {
$attributes['aria-label'] = CRM_Utils_Array::value('aria-label', $attributes, $label);
}
$type = "text";
}
- if ($type == 'select' && is_array($extra)) {
+ if ($type === 'select' && is_array($extra)) {
// Normalize this property
if (!empty($extra['multiple'])) {
$extra['multiple'] = 'multiple';