2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableDateField
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
2012-04-14 08:36:50 +02:00
|
|
|
* Allows a user to add a date field.
|
2010-05-31 09:57:00 +02:00
|
|
|
*
|
2009-04-17 04:26:40 +02:00
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2009-12-07 03:04:20 +01:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
class EditableDateField extends EditableFormField
|
|
|
|
{
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
private static $singular_name = 'Date Field';
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
private static $plural_name = 'Date Fields';
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
private static $db = array(
|
|
|
|
'DefaultToToday' => 'Boolean' // From customsettings
|
|
|
|
);
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
|
|
|
$fields->addFieldToTab(
|
|
|
|
'Root.Main',
|
|
|
|
CheckboxField::create(
|
|
|
|
'DefaultToToday',
|
|
|
|
_t('EditableFormField.DEFAULTTOTODAY', 'Default to Today?')
|
|
|
|
),
|
|
|
|
'RightTitle'
|
|
|
|
);
|
|
|
|
});
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
return parent::getCMSFields();
|
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
|
|
|
* Return the form field
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function getFormField()
|
|
|
|
{
|
|
|
|
$defaultValue = $this->DefaultToToday
|
|
|
|
? SS_Datetime::now()->Format('Y-m-d')
|
|
|
|
: $this->Default;
|
2015-08-21 05:21:33 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$field = EditableDateField_FormField::create($this->Name, $this->EscapedTitle, $defaultValue)
|
|
|
|
->setConfig('showcalendar', true)
|
|
|
|
->setFieldHolderTemplate('UserFormsField_holder')
|
|
|
|
->setTemplate('UserFormsField');
|
2015-08-21 05:21:33 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$this->doUpdateFormField($field);
|
2015-08-21 05:21:33 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
return $field;
|
|
|
|
}
|
2012-07-17 06:09:31 +02:00
|
|
|
}
|
2014-08-11 01:09:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package userforms
|
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
class EditableDateField_FormField extends DateField
|
|
|
|
{
|
2014-08-11 01:09:31 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
public function Type()
|
|
|
|
{
|
|
|
|
return "date-alt text";
|
|
|
|
}
|
|
|
|
}
|