silverstripe-framework/src/Forms/DateField_Disabled.php

41 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\Forms;
use SilverStripe\Core\Convert;
use SilverStripe\ORM\FieldType\DBDate;
/**
* Disabled version of {@link DateField}.
* Allows dates to be represented in a form, by showing in a user friendly format, eg, dd/mm/yyyy.
*/
class DateField_Disabled extends DateField
{
2016-11-29 00:31:16 +01:00
protected $disabled = true;
2016-11-29 00:31:16 +01:00
public function Field($properties = array())
{
if ($this->valueObj) {
if ($this->valueObj->isToday()) {
$val = Convert::raw2xml($this->valueObj->toString($this->getConfig('dateformat'))
2017-04-20 03:15:24 +02:00
. ' (' . _t('SilverStripe\\Forms\\DateField.TODAY', 'today') . ')');
2016-11-29 00:31:16 +01:00
} else {
$df = new DBDate($this->name);
$df->setValue($this->dataValue());
$val = Convert::raw2xml($this->valueObj->toString($this->getConfig('dateformat'))
. ', ' . $df->Ago());
}
} else {
2017-04-20 03:15:24 +02:00
$val = '<i>(' . _t('SilverStripe\\Forms\\DateField.NOTSET', 'not set') . ')</i>';
2016-11-29 00:31:16 +01:00
}
2016-11-29 00:31:16 +01:00
return "<span class=\"readonly\" id=\"" . $this->ID() . "\">$val</span>";
}
2016-11-29 00:31:16 +01:00
public function Type()
{
return "date_disabled readonly";
}
}