silverstripe-framework/src/Forms/CurrencyField_Readonly.php

41 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\Forms;
use SilverStripe\Core\Convert;
/**
* Readonly version of a {@link CurrencyField}.
*/
class CurrencyField_Readonly extends ReadonlyField
{
2016-11-29 00:31:16 +01:00
/**
* Overloaded to display the correctly formated value for this datatype
*
* @param array $properties
* @return string
*/
public function Field($properties = array())
{
if ($this->value) {
$val = Convert::raw2xml($this->value);
$val = _t('SilverStripe\\Forms\\CurrencyField.CURRENCYSYMBOL', '$') . number_format(preg_replace('/[^0-9.-]/', "", $val), 2);
2016-11-29 00:31:16 +01:00
$valforInput = Convert::raw2att($val);
} else {
2017-04-20 03:15:24 +02:00
$val = '<i>' . _t('SilverStripe\\Forms\\CurrencyField.CURRENCYSYMBOL', '$') . '0.00</i>';
2016-11-29 00:31:16 +01:00
$valforInput = '';
}
return "<span class=\"readonly " . $this->extraClass() . "\" id=\"" . $this->ID() . "\">$val</span>"
. "<input type=\"hidden\" name=\"" . $this->name . "\" value=\"" . $valforInput . "\" />";
}
2016-11-29 00:31:16 +01:00
/**
* This already is a readonly field.
*/
public function performReadonlyTransformation()
{
return clone $this;
}
}